Merge remote-tracking branch 'upstream/abstraction' into UIRefactor

This commit is contained in:
MatthewColvin 2023-09-17 19:45:03 -05:00
commit f5b7b7bc5f
8 changed files with 435 additions and 293 deletions

View file

@ -25,6 +25,15 @@ public:
virtual std::shared_ptr<DisplayAbstract> display() = 0; virtual std::shared_ptr<DisplayAbstract> display() = 0;
virtual std::shared_ptr<wifiHandlerInterface> wifi() = 0; virtual std::shared_ptr<wifiHandlerInterface> wifi() = 0;
virtual char getCurrentDevice() = 0;
virtual void setCurrentDevice(char currentDevice) = 0;
virtual bool getWakeupByIMUEnabled() = 0;
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) = 0;
virtual uint16_t getSleepTimeout() = 0;
virtual void setSleepTimeout(uint16_t sleepTimeout) = 0;
protected: protected:
}; };

View file

@ -50,9 +50,7 @@ void HardwareRevX::initIO() {
gpio_deep_sleep_hold_dis(); gpio_deep_sleep_hold_dis();
} }
HardwareRevX::HardwareRevX(): HardwareRevX::HardwareRevX() : HardwareAbstract() {}
HardwareAbstract(){
}
HardwareRevX::WakeReason getWakeReason() { HardwareRevX::WakeReason getWakeReason() {
// Find out wakeup cause // Find out wakeup cause
@ -78,7 +76,9 @@ void HardwareRevX::init() {
mWifiHandler = wifiHandler::getInstance(); mWifiHandler = wifiHandler::getInstance();
restorePreferences(); restorePreferences();
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;}); mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint) {
standbyTimer = this->getSleepTimeout();
});
setupIMU(); setupIMU();
setupIR(); setupIR();
@ -86,8 +86,7 @@ void HardwareRevX::init() {
debugPrint("Finished Hardware Setup in %d", millis()); debugPrint("Finished Hardware Setup in %d", millis());
} }
void HardwareRevX::debugPrint(const char* fmt, ...) void HardwareRevX::debugPrint(const char *fmt, ...) {
{
char result[100]; char result[100];
va_list arguments; va_list arguments;
@ -105,18 +104,13 @@ std::shared_ptr<HardwareRevX> HardwareRevX::getInstance(){
return mInstance; return mInstance;
} }
std::shared_ptr<wifiHandlerInterface> HardwareRevX::wifi() std::shared_ptr<wifiHandlerInterface> HardwareRevX::wifi() {
{
return mWifiHandler; return mWifiHandler;
} }
std::shared_ptr<BatteryInterface> HardwareRevX::battery(){ std::shared_ptr<BatteryInterface> HardwareRevX::battery() { return mBattery; }
return mBattery;
}
std::shared_ptr<DisplayAbstract> HardwareRevX::display(){ std::shared_ptr<DisplayAbstract> HardwareRevX::display() { return mDisplay; }
return mDisplay;
}
void HardwareRevX::activityDetection() { void HardwareRevX::activityDetection() {
static int accXold; static int accXold;
@ -134,7 +128,7 @@ void HardwareRevX::activityDetection() {
standbyTimer = 0; standbyTimer = 0;
// If the motion exceeds the threshold, the standbyTimer is reset // If the motion exceeds the threshold, the standbyTimer is reset
if (motion > MOTION_THRESHOLD) if (motion > MOTION_THRESHOLD)
standbyTimer = SLEEP_TIMEOUT; standbyTimer = sleepTimeout;
// Store the current acceleration and time // Store the current acceleration and time
accXold = accX; accXold = accX;
@ -142,11 +136,31 @@ void HardwareRevX::activityDetection() {
accZold = accZ; accZold = accZ;
} }
char HardwareRevX::getCurrentDevice() { return currentDevice; }
void HardwareRevX::setCurrentDevice(char currentDevice) {
this->currentDevice = currentDevice;
}
bool HardwareRevX::getWakeupByIMUEnabled() { return wakeupByIMUEnabled; }
void HardwareRevX::setWakeupByIMUEnabled(bool wakeupByIMUEnabled) {
this->wakeupByIMUEnabled = wakeupByIMUEnabled;
}
uint16_t HardwareRevX::getSleepTimeout() { return sleepTimeout; }
void HardwareRevX::setSleepTimeout(uint16_t sleepTimeout) {
this->sleepTimeout = sleepTimeout;
standbyTimer = sleepTimeout;
}
void HardwareRevX::enterSleep() { void HardwareRevX::enterSleep() {
// Save settings to internal flash memory // Save settings to internal flash memory
preferences.putBool("wkpByIMU", wakeupByIMUEnabled); preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
preferences.putUChar("blBrightness", mDisplay->getBrightness()); preferences.putUChar("blBrightness", mDisplay->getBrightness());
preferences.putUChar("currentDevice", currentDevice); preferences.putUChar("currentDevice", currentDevice);
preferences.putUInt("sleepTimeout", sleepTimeout);
if (!preferences.getBool("alreadySetUp")) if (!preferences.getBool("alreadySetUp"))
preferences.putBool("alreadySetUp", true); preferences.putBool("alreadySetUp", true);
preferences.end(); preferences.end();
@ -259,6 +273,11 @@ void HardwareRevX::restorePreferences() {
wakeupByIMUEnabled = preferences.getBool("wkpByIMU"); wakeupByIMUEnabled = preferences.getBool("wkpByIMU");
backlight_brightness = preferences.getUChar("blBrightness"); backlight_brightness = preferences.getUChar("blBrightness");
currentDevice = preferences.getUChar("currentDevice"); currentDevice = preferences.getUChar("currentDevice");
sleepTimeout = preferences.getUInt("sleepTimeout");
// setting the default to prevent a 0ms sleep timeout
if (sleepTimeout == 0) {
sleepTimeout = SLEEP_TIMEOUT;
}
} }
mDisplay->setBrightness(backlight_brightness); mDisplay->setBrightness(backlight_brightness);
} }
@ -312,7 +331,7 @@ void HardwareRevX::loopHandler() {
if (customKeypad.key[i].kstate == PRESSED || if (customKeypad.key[i].kstate == PRESSED ||
customKeypad.key[i].kstate == HOLD) { customKeypad.key[i].kstate == HOLD) {
standbyTimer = standbyTimer =
SLEEP_TIMEOUT; // Reset the sleep timer when a button is pressed sleepTimeout; // Reset the sleep timer when a button is pressed
int keyCode = customKeypad.key[i].kcode; int keyCode = customKeypad.key[i].kcode;
Serial.println(customKeypad.key[i].kchar); Serial.println(customKeypad.key[i].kchar);
// Send IR codes depending on the current device (tabview page) // Send IR codes depending on the current device (tabview page)

View file

@ -2,8 +2,9 @@
#include "SparkFunLIS3DH.h" #include "SparkFunLIS3DH.h"
#include "HardwareAbstract.hpp" #include "HardwareAbstract.hpp"
#include "lvgl.h"
#include "battery.hpp" #include "battery.hpp"
#include "lvgl.h"
#include "wifihandler.hpp"
#include <IRrecv.h> #include <IRrecv.h>
#include <IRremoteESP8266.h> #include <IRremoteESP8266.h>
#include <IRsend.h> #include <IRsend.h>
@ -13,14 +14,11 @@
#include <PubSubClient.h> #include <PubSubClient.h>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include "wifihandler.hpp"
#include "omoteconfig.h"
#include "BatteryInterface.h" #include "BatteryInterface.h"
#include "wifiHandlerInterface.h"
#include "display.hpp" #include "display.hpp"
#include "omoteconfig.h"
#include "wifiHandlerInterface.h"
class HardwareRevX : public HardwareAbstract { class HardwareRevX : public HardwareAbstract {
public: public:
@ -37,9 +35,19 @@ public:
virtual std::shared_ptr<DisplayAbstract> display() override; virtual std::shared_ptr<DisplayAbstract> display() override;
virtual std::shared_ptr<wifiHandlerInterface> wifi() override; virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
virtual char getCurrentDevice() override;
virtual void setCurrentDevice(char currentDevice) override;
virtual bool getWakeupByIMUEnabled() override;
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) override;
virtual uint16_t getSleepTimeout() override;
virtual void setSleepTimeout(uint16_t sleepTimeout) override;
/// @brief To be ran in loop out in main /// @brief To be ran in loop out in main
// TODO move to a freertos task // TODO move to a freertos task
void loopHandler(); void loopHandler();
protected: protected:
// Init Functions to setup hardware // Init Functions to setup hardware
void initIO(); void initIO();
@ -64,6 +72,7 @@ private:
// IMU Motion Detection // IMU Motion Detection
LIS3DH IMU = LIS3DH(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19. LIS3DH IMU = LIS3DH(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
int standbyTimer = SLEEP_TIMEOUT; int standbyTimer = SLEEP_TIMEOUT;
int sleepTimeout = SLEEP_TIMEOUT;
int motion = 0; int motion = 0;
WakeReason wakeup_reason; WakeReason wakeup_reason;
@ -76,7 +85,6 @@ private:
IRsend IrSender = IRsend(IR_LED, true); IRsend IrSender = IRsend(IR_LED, true);
IRrecv IrReceiver = IRrecv(IR_RX); IRrecv IrReceiver = IRrecv(IR_RX);
// Keypad declarations // Keypad declarations
static const byte ROWS = 5; // four rows static const byte ROWS = 5; // four rows
static const byte COLS = 5; // four columns static const byte COLS = 5; // four columns

View file

@ -3,27 +3,27 @@
#include "SDLDisplay.hpp" #include "SDLDisplay.hpp"
#include <sstream> #include <sstream>
HardwareSimulator::HardwareSimulator(): HardwareAbstract(), HardwareSimulator::HardwareSimulator()
mTickThread([](){ : HardwareAbstract(), mTickThread([]() {
while (true) { while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(2)); std::this_thread::sleep_for(std::chrono::milliseconds(2));
lv_tick_inc(2); /*Tell lvgl that 2 milliseconds were elapsed*/ lv_tick_inc(2); /*Tell lvgl that 2 milliseconds were elapsed*/
}}), }
}),
mBattery(std::make_shared<BatterySimulator>()), mBattery(std::make_shared<BatterySimulator>()),
mDisplay(SDLDisplay::getInstance()), mDisplay(SDLDisplay::getInstance()),
mWifiHandler(std::make_shared<wifiHandlerSim>()) mWifiHandler(std::make_shared<wifiHandlerSim>()) {
{
mHardwareStatusTitleUpdate = std::thread([this] { mHardwareStatusTitleUpdate = std::thread([this] {
int dataToShow = 0; int dataToShow = 0;
while (true) while (true) {
{
std::stringstream title; std::stringstream title;
switch (dataToShow) { switch (dataToShow) {
case 0: case 0:
title << "Batt:" << mBattery->getPercentage() << "%" << std::endl; title << "Batt:" << mBattery->getPercentage() << "%" << std::endl;
break; break;
case 1: case 1:
title << "BKLght: " << static_cast<int>(mDisplay->getBrightness()) << std::endl; title << "BKLght: " << static_cast<int>(mDisplay->getBrightness())
<< std::endl;
dataToShow = -1; dataToShow = -1;
break; break;
default: default:
@ -46,3 +46,15 @@ std::shared_ptr<DisplayAbstract> HardwareSimulator::display(){
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi() { std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi() {
return mWifiHandler; return mWifiHandler;
} }
char HardwareSimulator::getCurrentDevice() { return 0; }
void HardwareSimulator::setCurrentDevice(char currentDevice) {}
bool HardwareSimulator::getWakeupByIMUEnabled() { return true; }
void HardwareSimulator::setWakeupByIMUEnabled(bool wakeupByIMUEnabled) {}
uint16_t HardwareSimulator::getSleepTimeout() { return 20000; }
void HardwareSimulator::setSleepTimeout(uint16_t sleepTimeout) {}

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "HardwareAbstract.hpp" #include "HardwareAbstract.hpp"
#include "batterySimulator.hpp"
#include "SDLDisplay.hpp" #include "SDLDisplay.hpp"
#include "batterySimulator.hpp"
#include "wifiHandlerSim.hpp" #include "wifiHandlerSim.hpp"
#include <thread> #include <thread>
@ -24,6 +24,15 @@ public:
virtual std::shared_ptr<DisplayAbstract> display() override; virtual std::shared_ptr<DisplayAbstract> display() override;
virtual std::shared_ptr<wifiHandlerInterface> wifi() override; virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
virtual char getCurrentDevice() override;
virtual void setCurrentDevice(char currentDevice) override;
virtual bool getWakeupByIMUEnabled() override;
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) override;
virtual uint16_t getSleepTimeout() override;
virtual void setSleepTimeout(uint16_t sleepTimeout) override;
private: private:
std::thread mTickThread; std::thread mTickThread;
std::thread mHardwareStatusTitleUpdate; std::thread mHardwareStatusTitleUpdate;

View file

@ -11,7 +11,8 @@ std::shared_ptr<OmoteUI> OmoteUI::mInstance = nullptr;
// #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true) // #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true)
// #endif // #endif
OmoteUI::OmoteUI(std::shared_ptr<HardwareAbstract> aHardware) : UIBase(aHardware){} OmoteUI::OmoteUI(std::shared_ptr<HardwareAbstract> aHardware)
: UIBase(aHardware) {}
// Set the page indicator scroll position relative to the tabview scroll // Set the page indicator scroll position relative to the tabview scroll
// position // position
@ -26,6 +27,7 @@ void OmoteUI::store_scroll_value_event_cb(lv_event_t *e) {
// Update current device when the tabview page is changes // Update current device when the tabview page is changes
void OmoteUI::tabview_device_event_cb(lv_event_t *e) { void OmoteUI::tabview_device_event_cb(lv_event_t *e) {
currentDevice = lv_tabview_get_tab_act(lv_event_get_target(e)); currentDevice = lv_tabview_get_tab_act(lv_event_get_target(e));
this->mHardware->setCurrentDevice(currentDevice);
} }
// Slider Event handler // Slider Event handler
@ -43,8 +45,16 @@ void OmoteUI::appleKey_event_cb(lv_event_t *e) {
// Wakeup by IMU Switch Event handler // Wakeup by IMU Switch Event handler
void OmoteUI::WakeEnableSetting_event_cb(lv_event_t *e) { void OmoteUI::WakeEnableSetting_event_cb(lv_event_t *e) {
wakeupByIMUEnabled = this->mHardware->setWakeupByIMUEnabled(
lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED); lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED));
}
// Wakeup timeout dropdown Event handler
void OmoteUI::wakeTimeoutSetting_event_cb(lv_event_t *e) {
lv_obj_t *drop = lv_event_get_target(e);
int sleepTimeout = sleepTimeoutMap[lv_dropdown_get_selected(drop)];
mHardware->setSleepTimeout(sleepTimeout);
} }
// Smart Home Toggle Event handler // Smart Home Toggle Event handler
@ -108,32 +118,41 @@ void OmoteUI::create_status_bar(){
this->WifiLabel = lv_label_create(statusbar); this->WifiLabel = lv_label_create(statusbar);
lv_label_set_text(this->WifiLabel, ""); lv_label_set_text(this->WifiLabel, "");
lv_obj_align(this->WifiLabel, LV_ALIGN_LEFT_MID, -8, 0); lv_obj_align(this->WifiLabel, LV_ALIGN_LEFT_MID, -8, 0);
lv_obj_set_style_text_font(this->WifiLabel, &lv_font_montserrat_12, LV_PART_MAIN); lv_obj_set_style_text_font(this->WifiLabel, &lv_font_montserrat_12,
LV_PART_MAIN);
this->objBattPercentage = lv_label_create(statusbar); this->objBattPercentage = lv_label_create(statusbar);
lv_label_set_text(this->objBattPercentage, ""); lv_label_set_text(this->objBattPercentage, "");
lv_obj_align(this->objBattPercentage, LV_ALIGN_RIGHT_MID, -16, 0); lv_obj_align(this->objBattPercentage, LV_ALIGN_RIGHT_MID, -16, 0);
lv_obj_set_style_text_font(this->objBattPercentage, &lv_font_montserrat_12, LV_PART_MAIN); lv_obj_set_style_text_font(this->objBattPercentage, &lv_font_montserrat_12,
LV_PART_MAIN);
this->objBattIcon = lv_label_create(statusbar); this->objBattIcon = lv_label_create(statusbar);
lv_label_set_text(this->objBattIcon, LV_SYMBOL_BATTERY_EMPTY); lv_label_set_text(this->objBattIcon, LV_SYMBOL_BATTERY_EMPTY);
lv_obj_align(this->objBattIcon, LV_ALIGN_RIGHT_MID, 8, 0); lv_obj_align(this->objBattIcon, LV_ALIGN_RIGHT_MID, 8, 0);
lv_obj_set_style_text_font(this->objBattIcon, &lv_font_montserrat_16, LV_PART_MAIN); lv_obj_set_style_text_font(this->objBattIcon, &lv_font_montserrat_16,
LV_PART_MAIN);
batteryPoller = std::make_unique<poller>([&batteryIcon = objBattIcon, battery = mHardware->battery()](){ batteryPoller = std::make_unique<poller>(
[&batteryIcon = objBattIcon, battery = mHardware->battery()]() {
auto percent = battery->getPercentage(); auto percent = battery->getPercentage();
if(percent > 95) lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_FULL); if (percent > 95)
else if(percent > 75) lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_3); lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_FULL);
else if(percent > 50) lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_2); else if (percent > 75)
else if(percent > 25) lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_1); lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_3);
else lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_EMPTY); else if (percent > 50)
lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_2);
else if (percent > 25)
lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_1);
else
lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_EMPTY);
}); });
} }
void OmoteUI::setup_settings(lv_obj_t* parent) void OmoteUI::setup_settings(lv_obj_t *parent) {
{
// Add content to the settings tab // Add content to the settings tab
// With a flex layout, setting groups/boxes will position themselves automatically // With a flex layout, setting groups/boxes will position themselves
// automatically
lv_obj_set_layout(parent, LV_LAYOUT_FLEX); lv_obj_set_layout(parent, LV_LAYOUT_FLEX);
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lv_obj_set_scrollbar_mode(parent, LV_SCROLLBAR_MODE_ACTIVE); lv_obj_set_scrollbar_mode(parent, LV_SCROLLBAR_MODE_ACTIVE);
@ -163,8 +182,7 @@ void OmoteUI::setup_settings(lv_obj_t* parent)
lv_menu_set_page(this->settingsMenu, this->settingsMainPage); lv_menu_set_page(this->settingsMenu, this->settingsMainPage);
} }
void OmoteUI::ta_kb_event_cb(lv_event_t* e) void OmoteUI::ta_kb_event_cb(lv_event_t *e) {
{
lv_event_code_t code = lv_event_get_code(e); lv_event_code_t code = lv_event_get_code(e);
lv_obj_t *ta = lv_event_get_target(e); lv_obj_t *ta = lv_event_get_target(e);
lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e); lv_obj_t *kb = (lv_obj_t *)lv_event_get_user_data(e);
@ -183,32 +201,29 @@ void OmoteUI::ta_kb_event_cb(lv_event_t* e)
} }
} }
void OmoteUI::create_keyboard() void OmoteUI::create_keyboard() {
{
this->kb = lv_keyboard_create(lv_scr_act()); this->kb = lv_keyboard_create(lv_scr_act());
lv_obj_add_flag(this->kb, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(this->kb, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_y(this->kb, 0); lv_obj_set_y(this->kb, 0);
} }
void OmoteUI::hide_keyboard() void OmoteUI::hide_keyboard() { lv_obj_add_flag(this->kb, LV_OBJ_FLAG_HIDDEN); }
{
lv_obj_add_flag(this->kb, LV_OBJ_FLAG_HIDDEN);
}
void OmoteUI::reset_settings_menu() void OmoteUI::reset_settings_menu() {
{
lv_menu_set_page(this->settingsMenu, this->settingsMainPage); lv_menu_set_page(this->settingsMenu, this->settingsMainPage);
} }
void OmoteUI::attach_keyboard(lv_obj_t* textarea) void OmoteUI::attach_keyboard(lv_obj_t *textarea) {
{ if (this->kb == NULL) {
if (this->kb == NULL)
{
this->create_keyboard(); this->create_keyboard();
} }
lv_keyboard_set_textarea(this->kb, textarea); lv_keyboard_set_textarea(this->kb, textarea);
lv_obj_add_event_cb(textarea, [] (lv_event_t* e) {mInstance->ta_kb_event_cb(e);}, LV_EVENT_FOCUSED, this->kb); lv_obj_add_event_cb(
lv_obj_add_event_cb(textarea, [] (lv_event_t* e) {mInstance->ta_kb_event_cb(e);}, LV_EVENT_DEFOCUSED, this->kb); textarea, [](lv_event_t *e) { mInstance->ta_kb_event_cb(e); },
LV_EVENT_FOCUSED, this->kb);
lv_obj_add_event_cb(
textarea, [](lv_event_t *e) { mInstance->ta_kb_event_cb(e); },
LV_EVENT_DEFOCUSED, this->kb);
} }
void OmoteUI::layout_UI() { void OmoteUI::layout_UI() {
@ -218,9 +233,12 @@ void OmoteUI::layout_UI() {
this->create_keyboard(); this->create_keyboard();
// Setup a scrollable tabview for devices and settings // Setup a scrollable tabview for devices and settings
lv_obj_t *tabview; lv_obj_t *tabview;
tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 0); // Hide tab labels by setting their height to 0 tabview =
lv_tabview_create(lv_scr_act(), LV_DIR_TOP,
0); // Hide tab labels by setting their height to 0
lv_obj_set_style_bg_color(tabview, lv_color_black(), LV_PART_MAIN); lv_obj_set_style_bg_color(tabview, lv_color_black(), LV_PART_MAIN);
lv_obj_set_size(tabview, SCREEN_WIDTH, 270); // 270 = screenHeight(320) - panel(30) - statusbar(20) lv_obj_set_size(tabview, SCREEN_WIDTH,
270); // 270 = screenHeight(320) - panel(30) - statusbar(20)
lv_obj_align(tabview, LV_ALIGN_TOP_MID, 0, 20); lv_obj_align(tabview, LV_ALIGN_TOP_MID, 0, 20);
// Add 4 tabs (names are irrelevant since the labels are hidden) // Add 4 tabs (names are irrelevant since the labels are hidden)
@ -230,8 +248,11 @@ void OmoteUI::layout_UI() {
lv_obj_t *tab4 = lv_tabview_add_tab(tabview, "Smart Home"); lv_obj_t *tab4 = lv_tabview_add_tab(tabview, "Smart Home");
// Configure number button grid // Configure number button grid
static lv_coord_t col_dsc[] = { LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST }; // equal x distribution static lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1),
static lv_coord_t row_dsc[] = { 52, 52, 52, 52, LV_GRID_TEMPLATE_LAST }; // manual y distribution to compress the grid a bit LV_GRID_TEMPLATE_LAST}; // equal x distribution
static lv_coord_t row_dsc[] = {
52, 52, 52, 52, LV_GRID_TEMPLATE_LAST}; // manual y distribution to
// compress the grid a bit
// Create a container with grid for tab2 // Create a container with grid for tab2
lv_obj_set_style_pad_all(tab2, 0, LV_PART_MAIN); lv_obj_set_style_pad_all(tab2, 0, LV_PART_MAIN);
@ -254,29 +275,36 @@ void OmoteUI::layout_UI() {
uint8_t col = i % 3; uint8_t col = i % 3;
uint8_t row = i / 3; uint8_t row = i / 3;
// Create the button object // Create the button object
if ((row == 3) && ((col == 0) || (col == 2))) continue; // Do not create a complete fourth row, only a 0 button if ((row == 3) && ((col == 0) || (col == 2)))
continue; // Do not create a complete fourth row, only a 0 button
obj = lv_btn_create(cont); obj = lv_btn_create(cont);
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, col, 1, LV_GRID_ALIGN_STRETCH, row, 1); lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, col, 1,
LV_GRID_ALIGN_STRETCH, row, 1);
lv_obj_set_style_bg_color(obj, this->color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(obj, this->color_primary, LV_PART_MAIN);
lv_obj_set_style_radius(obj, 14, LV_PART_MAIN); lv_obj_set_style_radius(obj, 14, LV_PART_MAIN);
lv_obj_set_style_shadow_color(obj, lv_color_hex(0x404040), LV_PART_MAIN); lv_obj_set_style_shadow_color(obj, lv_color_hex(0x404040), LV_PART_MAIN);
lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE); // Clicking a button causes a event in its container lv_obj_add_flag(obj, LV_OBJ_FLAG_EVENT_BUBBLE); // Clicking a button causes
// a event in its container
// Create Labels for each button // Create Labels for each button
buttonLabel = lv_label_create(obj); buttonLabel = lv_label_create(obj);
if (i < 9) { if (i < 9) {
lv_label_set_text_fmt(buttonLabel, std::to_string(i+1).c_str(), col, row); lv_label_set_text_fmt(buttonLabel, std::to_string(i + 1).c_str(), col,
lv_obj_set_user_data(obj, (void*)i); // Add user data so we can identify which button caused the container event row);
} lv_obj_set_user_data(obj,
else{ (void *)i); // Add user data so we can identify which
// button caused the container event
} else {
lv_label_set_text_fmt(buttonLabel, "0", col, row); lv_label_set_text_fmt(buttonLabel, "0", col, row);
lv_obj_set_user_data(obj, (void *)9); lv_obj_set_user_data(obj, (void *)9);
} }
lv_obj_set_style_text_font(buttonLabel, &lv_font_montserrat_24, LV_PART_MAIN); lv_obj_set_style_text_font(buttonLabel, &lv_font_montserrat_24,
LV_PART_MAIN);
lv_obj_center(buttonLabel); lv_obj_center(buttonLabel);
} }
// Create a shared event for all button inside container // Create a shared event for all button inside container
lv_obj_add_event_cb(cont, [] (lv_event_t* e) {mInstance->virtualKeypad_event_cb(e);}, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb(
cont, [](lv_event_t *e) { mInstance->virtualKeypad_event_cb(e); },
LV_EVENT_CLICKED, NULL);
// Add content to the Apple TV tab (3) // Add content to the Apple TV tab (3)
// Add a nice apple tv logo // Add a nice apple tv logo
@ -287,7 +315,9 @@ void OmoteUI::layout_UI() {
lv_obj_set_size(button, 60, 60); lv_obj_set_size(button, 60, 60);
lv_obj_set_style_radius(button, 30, LV_PART_MAIN); lv_obj_set_style_radius(button, 30, LV_PART_MAIN);
lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN);
lv_obj_add_event_cb(button, [] (lv_event_t* e) {mInstance->appleKey_event_cb(e);}, LV_EVENT_CLICKED, (void*)1); lv_obj_add_event_cb(
button, [](lv_event_t *e) { mInstance->appleKey_event_cb(e); },
LV_EVENT_CLICKED, (void *)1);
appleImg = imgs.addAppleDisplayImage(button); appleImg = imgs.addAppleDisplayImage(button);
lv_obj_align(appleImg, LV_ALIGN_CENTER, -3, 0); lv_obj_align(appleImg, LV_ALIGN_CENTER, -3, 0);
@ -300,7 +330,9 @@ void OmoteUI::layout_UI() {
lv_obj_set_size(button, 60, 60); lv_obj_set_size(button, 60, 60);
lv_obj_set_style_radius(button, 30, LV_PART_MAIN); lv_obj_set_style_radius(button, 30, LV_PART_MAIN);
lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN);
lv_obj_add_event_cb(button, [] (lv_event_t* e) {mInstance->appleKey_event_cb(e);}, LV_EVENT_CLICKED, (void*)2); lv_obj_add_event_cb(
button, [](lv_event_t *e) { mInstance->appleKey_event_cb(e); },
LV_EVENT_CLICKED, (void *)2);
appleImg = imgs.addAppleDisplayImage(button); appleImg = imgs.addAppleDisplayImage(button);
lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, 0); lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, 0);
@ -333,22 +365,32 @@ void OmoteUI::layout_UI() {
lv_obj_t *lightToggleA = lv_switch_create(menuBox); lv_obj_t *lightToggleA = lv_switch_create(menuBox);
lv_obj_set_size(lightToggleA, 40, 22); lv_obj_set_size(lightToggleA, 40, 22);
lv_obj_align(lightToggleA, LV_ALIGN_TOP_RIGHT, 0, 0); lv_obj_align(lightToggleA, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_set_style_bg_color(lightToggleA, lv_color_lighten(color_primary, 50), LV_PART_MAIN); lv_obj_set_style_bg_color(lightToggleA, lv_color_lighten(color_primary, 50),
LV_PART_MAIN);
lv_obj_set_style_bg_color(lightToggleA, color_primary, LV_PART_INDICATOR); lv_obj_set_style_bg_color(lightToggleA, color_primary, LV_PART_INDICATOR);
lv_obj_add_event_cb(lightToggleA, [] (lv_event_t* e) {mInstance->smartHomeToggle_event_cb(e);}, LV_EVENT_VALUE_CHANGED, (void*)1); lv_obj_add_event_cb(
lightToggleA,
[](lv_event_t *e) { mInstance->smartHomeToggle_event_cb(e); },
LV_EVENT_VALUE_CHANGED, (void *)1);
lv_obj_t *slider = lv_slider_create(menuBox); lv_obj_t *slider = lv_slider_create(menuBox);
lv_slider_set_range(slider, 0, 100); lv_slider_set_range(slider, 0, 100);
lv_obj_set_style_bg_color(slider, lv_color_lighten(lv_color_black(), 30), LV_PART_INDICATOR); lv_obj_set_style_bg_color(slider, lv_color_lighten(lv_color_black(), 30),
lv_obj_set_style_bg_grad_color(slider, lv_color_lighten(lv_palette_main(LV_PALETTE_AMBER), 180), LV_PART_INDICATOR); LV_PART_INDICATOR);
lv_obj_set_style_bg_grad_color(
slider, lv_color_lighten(lv_palette_main(LV_PALETTE_AMBER), 180),
LV_PART_INDICATOR);
lv_obj_set_style_bg_grad_dir(slider, LV_GRAD_DIR_HOR, LV_PART_INDICATOR); lv_obj_set_style_bg_grad_dir(slider, LV_GRAD_DIR_HOR, LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB); lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB);
lv_obj_set_style_bg_opa(slider, 255, LV_PART_MAIN); lv_obj_set_style_bg_opa(slider, 255, LV_PART_MAIN);
lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN); lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50),
LV_PART_MAIN);
lv_slider_set_value(slider, 255, LV_ANIM_OFF); lv_slider_set_value(slider, 255, LV_ANIM_OFF);
lv_obj_set_size(slider, lv_pct(90), 10); lv_obj_set_size(slider, lv_pct(90), 10);
lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 37); lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 37);
lv_obj_add_event_cb(slider, [] (lv_event_t* e) {mInstance->smartHomeSlider_event_cb(e);}, LV_EVENT_VALUE_CHANGED, (void*)1); lv_obj_add_event_cb(
slider, [](lv_event_t *e) { mInstance->smartHomeSlider_event_cb(e); },
LV_EVENT_VALUE_CHANGED, (void *)1);
// Add another this->settingsMenu box for a second appliance // Add another this->settingsMenu box for a second appliance
menuBox = lv_obj_create(tab4); menuBox = lv_obj_create(tab4);
@ -365,23 +407,32 @@ void OmoteUI::layout_UI() {
lv_obj_t *lightToggleB = lv_switch_create(menuBox); lv_obj_t *lightToggleB = lv_switch_create(menuBox);
lv_obj_set_size(lightToggleB, 40, 22); lv_obj_set_size(lightToggleB, 40, 22);
lv_obj_align(lightToggleB, LV_ALIGN_TOP_RIGHT, 0, 0); lv_obj_align(lightToggleB, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_set_style_bg_color(lightToggleB, lv_color_lighten(color_primary, 50), LV_PART_MAIN); lv_obj_set_style_bg_color(lightToggleB, lv_color_lighten(color_primary, 50),
LV_PART_MAIN);
lv_obj_set_style_bg_color(lightToggleB, color_primary, LV_PART_INDICATOR); lv_obj_set_style_bg_color(lightToggleB, color_primary, LV_PART_INDICATOR);
lv_obj_add_event_cb(lightToggleB, [] (lv_event_t* e) {mInstance->smartHomeToggle_event_cb(e);}, LV_EVENT_VALUE_CHANGED, (void*)2); lv_obj_add_event_cb(
lightToggleB,
[](lv_event_t *e) { mInstance->smartHomeToggle_event_cb(e); },
LV_EVENT_VALUE_CHANGED, (void *)2);
slider = lv_slider_create(menuBox); slider = lv_slider_create(menuBox);
lv_slider_set_range(slider, 0, 100); lv_slider_set_range(slider, 0, 100);
lv_obj_set_style_bg_color(slider, lv_color_lighten(lv_color_black(), 30), LV_PART_INDICATOR); lv_obj_set_style_bg_color(slider, lv_color_lighten(lv_color_black(), 30),
lv_obj_set_style_bg_grad_color(slider, lv_color_lighten(lv_palette_main(LV_PALETTE_AMBER), 180), LV_PART_INDICATOR); LV_PART_INDICATOR);
lv_obj_set_style_bg_grad_color(
slider, lv_color_lighten(lv_palette_main(LV_PALETTE_AMBER), 180),
LV_PART_INDICATOR);
lv_obj_set_style_bg_grad_dir(slider, LV_GRAD_DIR_HOR, LV_PART_INDICATOR); lv_obj_set_style_bg_grad_dir(slider, LV_GRAD_DIR_HOR, LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB); lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB);
lv_obj_set_style_bg_opa(slider, 255, LV_PART_MAIN); lv_obj_set_style_bg_opa(slider, 255, LV_PART_MAIN);
lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN); lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50),
LV_PART_MAIN);
lv_slider_set_value(slider, 255, LV_ANIM_OFF); lv_slider_set_value(slider, 255, LV_ANIM_OFF);
lv_obj_set_size(slider, lv_pct(90), 10); lv_obj_set_size(slider, lv_pct(90), 10);
lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 37); lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 37);
lv_obj_add_event_cb(slider, [] (lv_event_t* e) {mInstance->smartHomeSlider_event_cb(e);}, LV_EVENT_VALUE_CHANGED, (void*)2); lv_obj_add_event_cb(
slider, [](lv_event_t *e) { mInstance->smartHomeSlider_event_cb(e); },
LV_EVENT_VALUE_CHANGED, (void *)2);
// Add another room (empty for now) // Add another room (empty for now)
menuLabel = lv_label_create(tab4); menuLabel = lv_label_create(tab4);
@ -392,14 +443,14 @@ void OmoteUI::layout_UI() {
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN); lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
// Set current page according to the current Device // Set current page according to the current Device
lv_tabview_set_act(tabview, 0, LV_ANIM_OFF); currentDevice = this->mHardware->getCurrentDevice();
lv_tabview_set_act(tabview, currentDevice, LV_ANIM_OFF);
// Create a page indicator // Create a page indicator
panel = lv_obj_create(lv_scr_act()); panel = lv_obj_create(lv_scr_act());
lv_obj_clear_flag(panel, LV_OBJ_FLAG_CLICKABLE); // This indicator will not be clickable lv_obj_clear_flag(
panel, LV_OBJ_FLAG_CLICKABLE); // This indicator will not be clickable
lv_obj_set_size(panel, SCREEN_WIDTH, 30); lv_obj_set_size(panel, SCREEN_WIDTH, 30);
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
lv_obj_align(panel, LV_ALIGN_BOTTOM_MID, 0, 0); lv_obj_align(panel, LV_ALIGN_BOTTOM_MID, 0, 0);
@ -452,8 +503,13 @@ void OmoteUI::layout_UI() {
lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN); lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN);
// Make the indicator scroll together with the tabs by creating a scroll event // Make the indicator scroll together with the tabs by creating a scroll event
lv_obj_add_event_cb(lv_tabview_get_content(tabview), [] (lv_event_t* e) {mInstance->store_scroll_value_event_cb(e);}, LV_EVENT_SCROLL, NULL); lv_obj_add_event_cb(
lv_obj_add_event_cb(tabview, [] (lv_event_t* e) {mInstance->tabview_device_event_cb(e);}, LV_EVENT_VALUE_CHANGED, NULL); lv_tabview_get_content(tabview),
[](lv_event_t *e) { mInstance->store_scroll_value_event_cb(e); },
LV_EVENT_SCROLL, NULL);
lv_obj_add_event_cb(
tabview, [](lv_event_t *e) { mInstance->tabview_device_event_cb(e); },
LV_EVENT_VALUE_CHANGED, NULL);
// Initialize scroll position for the indicator // Initialize scroll position for the indicator
lv_event_send(lv_tabview_get_content(tabview), LV_EVENT_SCROLL, NULL); lv_event_send(lv_tabview_get_content(tabview), LV_EVENT_SCROLL, NULL);

View file

@ -2,14 +2,14 @@
// 2023 Matthew Colvin // 2023 Matthew Colvin
#pragma once #pragma once
#include "UIBase.hpp"
#include "Images.hpp" #include "Images.hpp"
#include "UIBase.hpp"
#include "lvgl.h" #include "lvgl.h"
#include "poller.hpp"
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#include "poller.hpp"
namespace UI::Basic { namespace UI::Basic {
/// @brief Singleton to allow UI code to live separately from the Initialization /// @brief Singleton to allow UI code to live separately from the Initialization
@ -34,6 +34,8 @@ public:
void store_scroll_value_event_cb(lv_event_t *e); void store_scroll_value_event_cb(lv_event_t *e);
// Update current device when the tabview page is changes // Update current device when the tabview page is changes
void tabview_device_event_cb(lv_event_t *e); void tabview_device_event_cb(lv_event_t *e);
// Update wake timeout handler
void wakeTimeoutSetting_event_cb(lv_event_t *e);
// Slider Event handler // Slider Event handler
void bl_slider_event_cb(lv_event_t *e); void bl_slider_event_cb(lv_event_t *e);
// Apple Key Event handler // Apple Key Event handler
@ -59,15 +61,17 @@ public:
void wifi_scan_done(std::shared_ptr<std::vector<WifiInfo>> info); void wifi_scan_done(std::shared_ptr<std::vector<WifiInfo>> info);
void loopHandler(); void loopHandler();
/** /**
* @brief Function to hide the keyboard. If the keyboard is attached to a text area, it will be hidden when the * @brief Function to hide the keyboard. If the keyboard is attached to a text
* text area is defocused. This function can be used if the keyboard need to be hidden due to some script event. * area, it will be hidden when the text area is defocused. This function can
* be used if the keyboard need to be hidden due to some script event.
* *
*/ */
void hide_keyboard(); void hide_keyboard();
/** /**
* @brief Function to show the keyboard. If a text area needs the keybaord, it should be attached to the text area * @brief Function to show the keyboard. If a text area needs the keybaord, it
* using the approbiate function. The keyboard will then show up when the text area is focused. This function is * should be attached to the text area using the approbiate function. The
* keyboard will then show up when the text area is focused. This function is
* needed if the keyboard should be shown due to some script or other trigger. * needed if the keyboard should be shown due to some script or other trigger.
* *
*/ */
@ -78,6 +82,8 @@ private:
std::unique_ptr<poller> batteryPoller; std::unique_ptr<poller> batteryPoller;
int sleepTimeoutMap[5] = {10000,30000,60000,180000,600000};
void reset_settings_menu(); void reset_settings_menu();
void attach_keyboard(lv_obj_t *textarea); void attach_keyboard(lv_obj_t *textarea);
std::shared_ptr<std::vector<WifiInfo>> found_wifi_networks; std::shared_ptr<std::vector<WifiInfo>> found_wifi_networks;
@ -88,7 +94,8 @@ private:
lv_obj_t *kb; lv_obj_t *kb;
/** /**
* @brief Function to create the keyboard object which can then be attached to different text areas. * @brief Function to create the keyboard object which can then be attached to
* different text areas.
* *
*/ */
void create_keyboard(); void create_keyboard();
@ -130,12 +137,12 @@ void create_keyboard();
Images imgs = Images(); Images imgs = Images();
uint_fast8_t currentDevice = 4; uint_fast8_t currentDevice = 4;
lv_color_t color_primary = lv_color_hex(0x303030); // gray lv_color_t color_primary = lv_color_hex(0x303030); // gray
bool wakeupByIMUEnabled = true;
inline static const uint_fast8_t virtualKeyMapTechnisat[10] = { inline static const uint_fast8_t virtualKeyMapTechnisat[10] = {
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0}; 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0};
/************************************** WIFI Settings Menu *******************************************************/ /************************************** WIFI Settings Menu
* *******************************************************/
/** /**
* @brief Container within the wifi selection page * @brief Container within the wifi selection page
*/ */
@ -148,8 +155,8 @@ void create_keyboard();
lv_obj_t *wifiOverview; lv_obj_t *wifiOverview;
/** /**
* @brief Label in the wifi password page. This label is updated with the selected SSID when the credentials for * @brief Label in the wifi password page. This label is updated with the
* a wifi network is entered. * selected SSID when the credentials for a wifi network is entered.
* *
*/ */
lv_obj_t *wifi_password_label; lv_obj_t *wifi_password_label;
@ -181,10 +188,10 @@ void create_keyboard();
*/ */
unsigned int no_wifi_networks; unsigned int no_wifi_networks;
void wifi_status(std::shared_ptr<wifiStatus> status); void wifi_status(std::shared_ptr<wifiStatus> status);
/** /**
* @brief callback function to get next wifi subpage. This callback can be used to get the next or previous page * @brief callback function to get next wifi subpage. This callback can be
* used to get the next or previous page
* *
* @param e lvgl event object * @param e lvgl event object
*/ */
@ -209,16 +216,19 @@ void create_keyboard();
/** /**
* @brief Method to create the wifi settings on the main page * @brief Method to create the wifi settings on the main page
* *
* @param parent lv object parent where the main settings page should be added to * @param parent lv object parent where the main settings page should be
* added to
*/ */
void create_wifi_main_page(lv_obj_t *parent); void create_wifi_main_page(lv_obj_t *parent);
/** /**
* @brief Method to create wifi settings. This method will call the create_wifi_selection_page, * @brief Method to create wifi settings. This method will call the
* the create_wifi_password_page, and the create_wifi_main_page * create_wifi_selection_page, the create_wifi_password_page, and the
* create_wifi_main_page
* *
* @param menu Settings menu where the sub pages should be added to * @param menu Settings menu where the sub pages should be added to
* @param parent lv object parent where the main settings page should be added to * @param parent lv object parent where the main settings page should be
* added to
*/ */
void create_wifi_settings(lv_obj_t *menu, lv_obj_t *parent); void create_wifi_settings(lv_obj_t *menu, lv_obj_t *parent);
@ -237,4 +247,4 @@ void create_keyboard();
void display_settings(lv_obj_t *parent); void display_settings(lv_obj_t *parent);
}; };
} } // namespace UI::Basic

View file

@ -2,9 +2,7 @@
using namespace UI::Basic; using namespace UI::Basic;
void OmoteUI::display_settings(lv_obj_t *parent) {
void OmoteUI::display_settings(lv_obj_t* parent)
{
lv_obj_t *menuLabel = lv_label_create(parent); lv_obj_t *menuLabel = lv_label_create(parent);
lv_label_set_text(menuLabel, "Display"); lv_label_set_text(menuLabel, "Display");
@ -20,13 +18,17 @@ void OmoteUI::display_settings(lv_obj_t* parent)
lv_slider_set_range(slider, 0, 255); lv_slider_set_range(slider, 0, 255);
lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB); lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB);
lv_obj_set_style_bg_opa(slider, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_bg_opa(slider, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN); lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50),
lv_slider_set_value(slider, mHardware->display()->getBrightness() , LV_ANIM_OFF); LV_PART_MAIN);
lv_slider_set_value(slider, mHardware->display()->getBrightness(),
LV_ANIM_OFF);
lv_obj_set_size(slider, lv_pct(66), 10); lv_obj_set_size(slider, lv_pct(66), 10);
lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 3); lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 3);
brightnessIcon = imgs.addHighBrightnessIcon(menuBox); brightnessIcon = imgs.addHighBrightnessIcon(menuBox);
lv_obj_align(brightnessIcon, LV_ALIGN_TOP_RIGHT, 0, -1); lv_obj_align(brightnessIcon, LV_ALIGN_TOP_RIGHT, 0, -1);
lv_obj_add_event_cb(slider, [] (lv_event_t* e) {mInstance->bl_slider_event_cb(e);}, LV_EVENT_VALUE_CHANGED, nullptr); lv_obj_add_event_cb(
slider, [](lv_event_t *e) { mInstance->bl_slider_event_cb(e); },
LV_EVENT_VALUE_CHANGED, nullptr);
menuLabel = lv_label_create(menuBox); menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Lift to Wake"); lv_label_set_text(menuLabel, "Lift to Wake");
@ -35,8 +37,12 @@ void OmoteUI::display_settings(lv_obj_t* parent)
lv_obj_set_size(wakeToggle, 40, 22); lv_obj_set_size(wakeToggle, 40, 22);
lv_obj_align(wakeToggle, LV_ALIGN_TOP_RIGHT, 0, 29); lv_obj_align(wakeToggle, LV_ALIGN_TOP_RIGHT, 0, 29);
lv_obj_set_style_bg_color(wakeToggle, lv_color_hex(0x505050), LV_PART_MAIN); lv_obj_set_style_bg_color(wakeToggle, lv_color_hex(0x505050), LV_PART_MAIN);
lv_obj_add_event_cb(wakeToggle, [] (lv_event_t* e) {mInstance->WakeEnableSetting_event_cb(e);}, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_add_event_cb(
if(wakeupByIMUEnabled) lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); // set default state wakeToggle,
[](lv_event_t *e) { mInstance->WakeEnableSetting_event_cb(e); },
LV_EVENT_VALUE_CHANGED, NULL);
if (mHardware->getWakeupByIMUEnabled())
lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); // set default state
menuLabel = lv_label_create(menuBox); menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Timeout"); lv_label_set_text(menuLabel, "Timeout");
@ -49,11 +55,24 @@ void OmoteUI::display_settings(lv_obj_t* parent)
lv_obj_align(drop, LV_ALIGN_TOP_RIGHT, 0, 61); lv_obj_align(drop, LV_ALIGN_TOP_RIGHT, 0, 61);
lv_obj_set_size(drop, 70, 22); lv_obj_set_size(drop, 70, 22);
// lv_obj_set_style_text_font(drop, &lv_font_montserrat_12, LV_PART_MAIN); // lv_obj_set_style_text_font(drop, &lv_font_montserrat_12, LV_PART_MAIN);
//lv_obj_set_style_text_font(lv_dropdown_get_list(drop), &lv_font_montserrat_12, LV_PART_MAIN); // lv_obj_set_style_text_font(lv_dropdown_get_list(drop),
// &lv_font_montserrat_12, LV_PART_MAIN);
lv_obj_set_style_pad_top(drop, 1, LV_PART_MAIN); lv_obj_set_style_pad_top(drop, 1, LV_PART_MAIN);
lv_obj_set_style_bg_color(drop, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(drop, color_primary, LV_PART_MAIN);
lv_obj_set_style_bg_color(lv_dropdown_get_list(drop), color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(lv_dropdown_get_list(drop), color_primary,
LV_PART_MAIN);
lv_obj_set_style_border_width(lv_dropdown_get_list(drop), 1, LV_PART_MAIN); lv_obj_set_style_border_width(lv_dropdown_get_list(drop), 1, LV_PART_MAIN);
lv_obj_set_style_border_color(lv_dropdown_get_list(drop), lv_color_hex(0x505050), LV_PART_MAIN); lv_obj_set_style_border_color(lv_dropdown_get_list(drop),
lv_color_hex(0x505050), LV_PART_MAIN);
int sleepTimeoutMapSize =
sizeof(sleepTimeoutMap) / sizeof(sleepTimeoutMap[0]);
int currentTimeout = mHardware->getSleepTimeout();
for (int i = 0; i < sleepTimeoutMapSize; i++) {
if (currentTimeout == sleepTimeoutMap[i])
lv_dropdown_set_selected(drop, i);
}
lv_obj_add_event_cb(
drop, [](lv_event_t *e) { mInstance->wakeTimeoutSetting_event_cb(e); },
LV_EVENT_VALUE_CHANGED, NULL);
} }