2023-06-28 14:26:56 -04:00
|
|
|
// OMOTE firmware for ESP32
|
2024-03-10 14:27:46 -04:00
|
|
|
// 2023-2024 Maximilian Kern / Klaus Musch
|
|
|
|
|
|
|
|
// init hardware and hardware loop
|
|
|
|
#include "applicationInternal/hardware/hardwarePresenter.h"
|
|
|
|
// register devices and their commands
|
|
|
|
#include "devices/misc/device_specialCommands.h"
|
|
|
|
#include "devices/TV/device_samsungTV/device_samsungTV.h"
|
|
|
|
#include "devices/AVreceiver/device_yamahaAmp/device_yamahaAmp.h"
|
|
|
|
#include "devices/AVreceiver/device_denonAvr/device_denonAvr.h"
|
|
|
|
#include "devices/mediaPlayer/device_appleTV/device_appleTV.h"
|
|
|
|
#include "devices/keyboard/device_keyboard_mqtt/device_keyboard_mqtt.h"
|
|
|
|
#include "devices/keyboard/device_keyboard_ble/device_keyboard_ble.h"
|
|
|
|
#include "devices/misc/device_smarthome/device_smarthome.h"
|
|
|
|
#include "applicationInternal/commandHandler.h"
|
|
|
|
// register gui and keys
|
|
|
|
#include "applicationInternal/gui/guiBase.h"
|
|
|
|
#include "applicationInternal/gui/guiRegistry.h"
|
|
|
|
#include "guis/gui_irReceiver.h"
|
|
|
|
#include "guis/gui_settings.h"
|
|
|
|
#include "guis/gui_numpad.h"
|
|
|
|
#include "devices/mediaPlayer/device_appleTV/gui_appleTV.h"
|
|
|
|
#include "devices/misc/device_smarthome/gui_smarthome.h"
|
|
|
|
#include "applicationInternal/keys.h"
|
|
|
|
#include "applicationInternal/gui/guiStatusUpdate.h"
|
|
|
|
// register scenes
|
|
|
|
#include "scenes/scene__defaultKeys.h"
|
2024-02-12 13:57:51 -05:00
|
|
|
#include "scenes/scene_allOff.h"
|
|
|
|
#include "scenes/scene_TV.h"
|
|
|
|
#include "scenes/scene_fireTV.h"
|
|
|
|
#include "scenes/scene_chromecast.h"
|
2024-03-10 14:27:46 -04:00
|
|
|
#include "applicationInternal/scenes/sceneHandler.h"
|
|
|
|
|
|
|
|
#if defined(ARDUINO)
|
|
|
|
// in case of Arduino we have a setup() and a loop()
|
|
|
|
void setup() {
|
2023-06-28 14:26:56 -04:00
|
|
|
|
2024-03-10 14:27:46 -04:00
|
|
|
#elif defined(WIN32) || defined(__linux__)
|
|
|
|
// in case of Windows/Linux, we have only a main() function, no setup() and loop(), so we have to simulate them
|
|
|
|
// forward declaration of loop()
|
|
|
|
void loop(unsigned long *pIMUTaskTimer, unsigned long *pUpdateStatusTimer);
|
|
|
|
// main function as usual in C
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
#endif
|
2023-06-28 14:26:56 -04:00
|
|
|
|
|
|
|
// --- Startup ---
|
|
|
|
Serial.begin(115200);
|
2024-03-10 14:27:46 -04:00
|
|
|
// do some general hardware setup, like powering the TFT, I2C, ...
|
|
|
|
init_hardware_general();
|
2023-06-28 14:26:56 -04:00
|
|
|
// Restore settings from internal flash memory
|
2024-02-12 13:57:51 -05:00
|
|
|
init_preferences();
|
2024-03-10 14:27:46 -04:00
|
|
|
// blinking led
|
|
|
|
init_userled();
|
2024-02-12 13:57:51 -05:00
|
|
|
// Power Pin definition
|
|
|
|
init_battery();
|
|
|
|
// get wakeup reason
|
|
|
|
init_sleep();
|
|
|
|
// setup the Inertial Measurement Unit (IMU) for motion detection
|
2024-03-10 14:27:46 -04:00
|
|
|
init_IMU();
|
|
|
|
|
|
|
|
// button Pin definition for hardware keys
|
|
|
|
init_keys();
|
2024-02-12 13:57:51 -05:00
|
|
|
// setup IR sender
|
|
|
|
init_infraredSender();
|
2024-03-10 14:27:46 -04:00
|
|
|
#if (ENABLE_KEYBOARD_BLE == 1)
|
|
|
|
init_keyboardBLE();
|
|
|
|
#endif
|
2024-02-12 13:57:51 -05:00
|
|
|
|
|
|
|
// register commands for the devices
|
2024-03-10 14:27:46 -04:00
|
|
|
register_specialCommands();
|
|
|
|
register_device_samsungTV();
|
|
|
|
register_device_yamahaAmp();
|
|
|
|
register_device_denonAvr();
|
2024-02-12 13:57:51 -05:00
|
|
|
register_device_smarthome();
|
|
|
|
register_device_appleTV();
|
2024-03-10 14:27:46 -04:00
|
|
|
#if (ENABLE_KEYBOARD_MQTT == 1)
|
2024-02-12 13:57:51 -05:00
|
|
|
register_device_keyboard_mqtt();
|
|
|
|
#endif
|
2024-03-10 14:27:46 -04:00
|
|
|
#if (ENABLE_KEYBOARD_BLE == 1)
|
2024-02-12 13:57:51 -05:00
|
|
|
register_device_keyboard_ble();
|
|
|
|
#endif
|
2024-03-10 14:27:46 -04:00
|
|
|
register_keyboardCommands();
|
2024-02-12 13:57:51 -05:00
|
|
|
|
2024-03-10 09:41:50 -04:00
|
|
|
// register the GUIs. They will be displayed in the order they have been registered.
|
2024-02-12 13:57:51 -05:00
|
|
|
register_gui_irReceiver();
|
|
|
|
register_gui_settings();
|
|
|
|
register_gui_appleTV();
|
2024-03-10 14:27:46 -04:00
|
|
|
register_gui_numpad();
|
2024-02-12 13:57:51 -05:00
|
|
|
register_gui_smarthome();
|
2024-03-10 14:27:46 -04:00
|
|
|
// init GUI - will initialize tft, touch and lvgl
|
2024-02-12 13:57:51 -05:00
|
|
|
init_gui();
|
|
|
|
gui_loop(); // Run the LVGL UI once before the loop takes over
|
|
|
|
|
2024-03-12 14:12:43 -04:00
|
|
|
// register the scenes and their key_commands_*
|
2024-03-10 14:27:46 -04:00
|
|
|
register_scene_defaultKeys();
|
2024-02-12 13:57:51 -05:00
|
|
|
register_scene_allOff();
|
|
|
|
register_scene_TV();
|
|
|
|
register_scene_fireTV();
|
|
|
|
register_scene_chromecast();
|
|
|
|
setLabelCurrentScene();
|
|
|
|
|
2024-03-10 14:27:46 -04:00
|
|
|
// init WiFi - needs to be after init_gui() because WifiLabel must be available
|
|
|
|
#if (ENABLE_WIFI_AND_MQTT == 1)
|
2024-02-12 13:57:51 -05:00
|
|
|
init_mqtt();
|
2023-06-28 14:26:56 -04:00
|
|
|
#endif
|
|
|
|
|
2024-03-10 09:41:50 -04:00
|
|
|
Serial.printf("Setup finished in %lu ms.\r\n", millis());
|
2024-03-10 14:27:46 -04:00
|
|
|
|
|
|
|
#if defined(WIN32) || defined(__linux__)
|
|
|
|
// In Windows/Linux there is no loop function that is automatically being called. So we have to do this on our own infinitely here in main()
|
|
|
|
unsigned long IMUTaskTimer = 0;
|
|
|
|
unsigned long updateStatusTimer = 0;
|
|
|
|
while (1)
|
|
|
|
loop(&IMUTaskTimer, &updateStatusTimer);
|
|
|
|
#endif
|
|
|
|
|
2023-06-28 14:26:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Loop ------------------------------------------------------------------------------------------------------------------------------------
|
2024-03-10 14:27:46 -04:00
|
|
|
#if defined(ARDUINO)
|
|
|
|
unsigned long IMUTaskTimer = 0;
|
|
|
|
unsigned long updateStatusTimer = 0;
|
|
|
|
unsigned long *pIMUTaskTimer = &IMUTaskTimer;
|
|
|
|
unsigned long *pUpdateStatusTimer = &updateStatusTimer;
|
2024-03-10 09:41:50 -04:00
|
|
|
void loop() {
|
2024-03-10 14:27:46 -04:00
|
|
|
#elif defined(WIN32) || defined(__linux__)
|
|
|
|
void loop(unsigned long *pIMUTaskTimer, unsigned long *pUpdateStatusTimer) {
|
|
|
|
#endif
|
2023-06-28 14:26:56 -04:00
|
|
|
|
2024-03-10 14:27:46 -04:00
|
|
|
// --- do as often as possible --------------------------------------------------------
|
|
|
|
// update backlight brightness. Fade in on startup, dim before going to sleep
|
2024-02-12 13:57:51 -05:00
|
|
|
update_backligthBrighness();
|
2024-03-10 14:27:46 -04:00
|
|
|
// keypad handling: get key states from hardware and process them
|
2024-03-10 09:41:50 -04:00
|
|
|
keypad_loop();
|
2024-03-10 14:27:46 -04:00
|
|
|
// process IR receiver, if activated
|
|
|
|
if (get_irReceiverEnabled()) {
|
2024-03-10 09:41:50 -04:00
|
|
|
infraredReceiver_loop();
|
|
|
|
}
|
2024-03-10 14:27:46 -04:00
|
|
|
// update LVGL UI
|
|
|
|
gui_loop();
|
|
|
|
|
|
|
|
// --- every 100 ms -------------------------------------------------------------------
|
|
|
|
// Refresh IMU data (motion detection) every 100 ms
|
|
|
|
// If no action (key, TFT or motion), then go to sleep
|
|
|
|
if(millis() - *pIMUTaskTimer >= 100){
|
|
|
|
*pIMUTaskTimer = millis();
|
2023-06-28 14:26:56 -04:00
|
|
|
|
2024-02-12 13:57:51 -05:00
|
|
|
check_activity();
|
2023-06-28 14:26:56 -04:00
|
|
|
}
|
|
|
|
|
2024-03-10 14:27:46 -04:00
|
|
|
// --- every 1000 ms ------------------------------------------------------------------
|
|
|
|
if(millis() - *pUpdateStatusTimer >= 1000) {
|
|
|
|
*pUpdateStatusTimer = millis();
|
2023-06-28 14:26:56 -04:00
|
|
|
|
2024-03-10 14:27:46 -04:00
|
|
|
// update user_led, battery, BLE, memoryUsage on GUI
|
|
|
|
updateHardwareStatusAndShowOnGUI();
|
2024-02-12 13:57:51 -05:00
|
|
|
}
|
2023-06-28 14:26:56 -04:00
|
|
|
|
2024-02-12 13:57:51 -05:00
|
|
|
}
|