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<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:
};

View file

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

View file

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

View file

@ -3,27 +3,27 @@
#include "SDLDisplay.hpp"
#include <sstream>
HardwareSimulator::HardwareSimulator(): HardwareAbstract(),
mTickThread([](){
HardwareSimulator::HardwareSimulator()
: HardwareAbstract(), mTickThread([]() {
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(2));
lv_tick_inc(2); /*Tell lvgl that 2 milliseconds were elapsed*/
}}),
}
}),
mBattery(std::make_shared<BatterySimulator>()),
mDisplay(SDLDisplay::getInstance()),
mWifiHandler(std::make_shared<wifiHandlerSim>())
{
mWifiHandler(std::make_shared<wifiHandlerSim>()) {
mHardwareStatusTitleUpdate = std::thread([this] {
int dataToShow = 0;
while (true)
{
while (true) {
std::stringstream title;
switch (dataToShow) {
case 0:
title << "Batt:" << mBattery->getPercentage() << "%" << std::endl;
break;
case 1:
title << "BKLght: " << static_cast<int>(mDisplay->getBrightness()) << std::endl;
title << "BKLght: " << static_cast<int>(mDisplay->getBrightness())
<< std::endl;
dataToShow = -1;
break;
default:
@ -46,3 +46,15 @@ std::shared_ptr<DisplayAbstract> HardwareSimulator::display(){
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi() {
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
#include "HardwareAbstract.hpp"
#include "batterySimulator.hpp"
#include "SDLDisplay.hpp"
#include "batterySimulator.hpp"
#include "wifiHandlerSim.hpp"
#include <thread>
@ -24,6 +24,15 @@ public:
virtual std::shared_ptr<DisplayAbstract> display() 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:
std::thread mTickThread;
std::thread mHardwareStatusTitleUpdate;

View file

@ -11,7 +11,8 @@ std::shared_ptr<OmoteUI> OmoteUI::mInstance = nullptr;
// #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true)
// #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
// 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
void OmoteUI::tabview_device_event_cb(lv_event_t *e) {
currentDevice = lv_tabview_get_tab_act(lv_event_get_target(e));
this->mHardware->setCurrentDevice(currentDevice);
}
// Slider Event handler
@ -43,8 +45,16 @@ void OmoteUI::appleKey_event_cb(lv_event_t *e) {
// Wakeup by IMU Switch Event handler
void OmoteUI::WakeEnableSetting_event_cb(lv_event_t *e) {
wakeupByIMUEnabled =
lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
this->mHardware->setWakeupByIMUEnabled(
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
@ -108,32 +118,41 @@ void OmoteUI::create_status_bar(){
this->WifiLabel = lv_label_create(statusbar);
lv_label_set_text(this->WifiLabel, "");
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);
lv_label_set_text(this->objBattPercentage, "");
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);
lv_label_set_text(this->objBattIcon, LV_SYMBOL_BATTERY_EMPTY);
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();
if(percent > 95) lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_FULL);
else if(percent > 75) lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_3);
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);
if (percent > 95)
lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_FULL);
else if (percent > 75)
lv_label_set_text(batteryIcon, LV_SYMBOL_BATTERY_3);
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
// 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_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
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);
}
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_obj_t *ta = lv_event_get_target(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());
lv_obj_add_flag(this->kb, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_y(this->kb, 0);
}
void OmoteUI::hide_keyboard()
{
lv_obj_add_flag(this->kb, LV_OBJ_FLAG_HIDDEN);
}
void OmoteUI::hide_keyboard() { 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);
}
void OmoteUI::attach_keyboard(lv_obj_t* textarea)
{
if (this->kb == NULL)
{
void OmoteUI::attach_keyboard(lv_obj_t *textarea) {
if (this->kb == NULL) {
this->create_keyboard();
}
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(textarea, [] (lv_event_t* e) {mInstance->ta_kb_event_cb(e);}, LV_EVENT_DEFOCUSED, this->kb);
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(
textarea, [](lv_event_t *e) { mInstance->ta_kb_event_cb(e); },
LV_EVENT_DEFOCUSED, this->kb);
}
void OmoteUI::layout_UI() {
@ -218,9 +233,12 @@ void OmoteUI::layout_UI() {
this->create_keyboard();
// Setup a scrollable tabview for devices and settings
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_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);
// 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");
// 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 row_dsc[] = { 52, 52, 52, 52, LV_GRID_TEMPLATE_LAST }; // manual y distribution to compress the grid a bit
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 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
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 row = i / 3;
// 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);
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_radius(obj, 14, 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
buttonLabel = lv_label_create(obj);
if (i < 9) {
lv_label_set_text_fmt(buttonLabel, std::to_string(i+1).c_str(), col, row);
lv_obj_set_user_data(obj, (void*)i); // Add user data so we can identify which button caused the container event
}
else{
lv_label_set_text_fmt(buttonLabel, std::to_string(i + 1).c_str(), col,
row);
lv_obj_set_user_data(obj,
(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_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);
}
// 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 a nice apple tv logo
@ -287,7 +315,9 @@ void OmoteUI::layout_UI() {
lv_obj_set_size(button, 60, 60);
lv_obj_set_style_radius(button, 30, 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);
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_style_radius(button, 30, 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);
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_set_size(lightToggleA, 40, 22);
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_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_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_grad_color(slider, lv_color_lighten(lv_palette_main(LV_PALETTE_AMBER), 180), LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider, lv_color_lighten(lv_color_black(), 30),
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_color(slider, lv_color_white(), LV_PART_KNOB);
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_obj_set_size(slider, lv_pct(90), 10);
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
menuBox = lv_obj_create(tab4);
@ -365,23 +407,32 @@ void OmoteUI::layout_UI() {
lv_obj_t *lightToggleB = lv_switch_create(menuBox);
lv_obj_set_size(lightToggleB, 40, 22);
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_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);
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_grad_color(slider, lv_color_lighten(lv_palette_main(LV_PALETTE_AMBER), 180), LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider, lv_color_lighten(lv_color_black(), 30),
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_color(slider, lv_color_white(), LV_PART_KNOB);
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_obj_set_size(slider, lv_pct(90), 10);
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)
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_border_width(menuBox, 0, LV_PART_MAIN);
// 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
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_flex_flow(panel, LV_FLEX_FLOW_ROW);
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);
// 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(tabview, [] (lv_event_t* e) {mInstance->tabview_device_event_cb(e);}, LV_EVENT_VALUE_CHANGED, NULL);
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(
tabview, [](lv_event_t *e) { mInstance->tabview_device_event_cb(e); },
LV_EVENT_VALUE_CHANGED, NULL);
// Initialize scroll position for the indicator
lv_event_send(lv_tabview_get_content(tabview), LV_EVENT_SCROLL, NULL);

View file

@ -2,14 +2,14 @@
// 2023 Matthew Colvin
#pragma once
#include "UIBase.hpp"
#include "Images.hpp"
#include "UIBase.hpp"
#include "lvgl.h"
#include "poller.hpp"
#include <algorithm>
#include <memory>
#include <stdio.h>
#include <string>
#include "poller.hpp"
namespace UI::Basic {
/// @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);
// Update current device when the tabview page is changes
void tabview_device_event_cb(lv_event_t *e);
// Update wake timeout handler
void wakeTimeoutSetting_event_cb(lv_event_t *e);
// Slider Event handler
void bl_slider_event_cb(lv_event_t *e);
// Apple Key Event handler
@ -59,15 +61,17 @@ public:
void wifi_scan_done(std::shared_ptr<std::vector<WifiInfo>> info);
void loopHandler();
/**
* @brief Function to hide the keyboard. If the keyboard is attached to a text 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.
* @brief Function to hide the keyboard. If the keyboard is attached to a text
* 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();
/**
* @brief Function to show the keyboard. If a text area needs the keybaord, it 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
* @brief Function to show the keyboard. If a text area needs the keybaord, it
* 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.
*
*/
@ -78,6 +82,8 @@ private:
std::unique_ptr<poller> batteryPoller;
int sleepTimeoutMap[5] = {10000,30000,60000,180000,600000};
void reset_settings_menu();
void attach_keyboard(lv_obj_t *textarea);
std::shared_ptr<std::vector<WifiInfo>> found_wifi_networks;
@ -88,7 +94,8 @@ private:
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();
@ -130,12 +137,12 @@ void create_keyboard();
Images imgs = Images();
uint_fast8_t currentDevice = 4;
lv_color_t color_primary = lv_color_hex(0x303030); // gray
bool wakeupByIMUEnabled = true;
inline static const uint_fast8_t virtualKeyMapTechnisat[10] = {
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0};
/************************************** WIFI Settings Menu *******************************************************/
/************************************** WIFI Settings Menu
* *******************************************************/
/**
* @brief Container within the wifi selection page
*/
@ -148,8 +155,8 @@ void create_keyboard();
lv_obj_t *wifiOverview;
/**
* @brief Label in the wifi password page. This label is updated with the selected SSID when the credentials for
* a wifi network is entered.
* @brief Label in the wifi password page. This label is updated with the
* selected SSID when the credentials for a wifi network is entered.
*
*/
lv_obj_t *wifi_password_label;
@ -181,10 +188,10 @@ void create_keyboard();
*/
unsigned int no_wifi_networks;
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
*/
@ -209,16 +216,19 @@ void create_keyboard();
/**
* @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);
/**
* @brief Method to create wifi settings. This method will call the create_wifi_selection_page,
* the create_wifi_password_page, and the create_wifi_main_page
* @brief Method to create wifi settings. This method will call the
* 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 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);
@ -237,4 +247,4 @@ void create_keyboard();
void display_settings(lv_obj_t *parent);
};
}
} // namespace UI::Basic

View file

@ -2,9 +2,7 @@
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_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_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_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN);
lv_slider_set_value(slider, mHardware->display()->getBrightness() , LV_ANIM_OFF);
lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50),
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_align(slider, LV_ALIGN_TOP_MID, 0, 3);
brightnessIcon = imgs.addHighBrightnessIcon(menuBox);
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);
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_align(wakeToggle, LV_ALIGN_TOP_RIGHT, 0, 29);
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);
if(wakeupByIMUEnabled) lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); // set default state
lv_obj_add_event_cb(
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);
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_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(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_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_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);
}