OMOTE/Platformio/src/main.cpp

165 lines
5.5 KiB
C++
Raw Normal View History

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"
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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();
// get wakeup reason
init_sleep();
2023-06-28 14:26:56 -04:00
// Restore settings from internal flash memory
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
init_preferences();
2024-03-10 14:27:46 -04:00
// blinking led
init_userled();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
// Power Pin definition
init_battery();
2024-03-10 14:27:46 -04:00
// button Pin definition for hardware keys
init_keys();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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)
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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)
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
register_device_keyboard_ble();
#endif
2024-03-10 14:27:46 -04:00
register_keyboardCommands();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
// register the GUIs. They will be displayed in the order they have been registered.
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
init_gui();
gui_loop(); // Run the LVGL UI once before the loop takes over
// setup the Inertial Measurement Unit (IMU) for motion detection. Has to be after init_gui(), otherwise I2C will not work
init_IMU();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
// register the scenes and their key_commands_*
2024-03-10 14:27:46 -04:00
register_scene_defaultKeys();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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)
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
init_mqtt();
2023-06-28 14:26:56 -04:00
#endif
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;
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
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
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
keypad_loop();
2024-03-10 14:27:46 -04:00
// process IR receiver, if activated
if (get_irReceiverEnabled()) {
infraredReceiver_loop();
}
2024-03-10 14:27:46 -04:00
// update LVGL UI
gui_loop();
2024-03-18 15:20:59 -04:00
// call mqtt loop to receive mqtt messages, if you are subscribed to some topics
#if (ENABLE_WIFI_AND_MQTT == 1)
mqtt_loop();
#endif
2024-03-10 14:27:46 -04:00
// --- 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
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
check_activity();
2024-03-18 15:20:59 -04:00
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();
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
}
2023-06-28 14:26:56 -04:00
Modular approach - first version for main branch (#60) * first version of "modular-approach" * changed keyboard commands for HOME and BACK * Update README.md * only some typos in comments * readability * comment for what the mqtt keyboard is used * removed numbering of tab variables. not needed anymore * changed the default keyboard from "´mqtt keyboard" to "BLE keyboard" * updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked * added comment for key repeatModes * added comment for MQTT keyboard * setting timout via GUI now works, not only dropdown without functionality * BLE indicator added; separation of BLE/WiFi activation from activation of devices using it * report battery level to BLE device * Dynamic keyboard commands, so you can safely deactivate BLE and/or WiFi and not break the example code * reorganized files into folders * moved lv_conf.h into the gui folder * added devices for appleTV and smarthome * assets.c broken up and placed them where they are used * added support for IR RC5 * reorganization of files and folder * added comment * renamed assets files * introduction of gui_registry * removed unnecessary functions from sleep.h * use gui_registry.h only once * some files renamed for better understandability * minor renaming * some more renaming * check if WiFi label was instantiated before using it * introduction of a scene registry * save prefs directly after timeout is changed * renaming of preferencesStorage * comment added * only readability * detailled definition of key layout for the diferrent scenes * made code compile for "device_smarthome" when WiFi is deactivated * fixed access violation when no scene was active * added support for IR DENON commands * increased lvgl heap from 32K to 48K
2024-02-12 13:57:51 -05:00
}