Added wifi UI and change debug print function

* HardwareAbstract debug print function now uses VA_LIST
* Added wifi handling UI
* Notification items currently part of hardware abstract
This commit is contained in:
Thomas Bittner 2023-08-20 23:24:36 +02:00 committed by MatthewColvin
parent 02d973f8b1
commit 53fa7b7c87
17 changed files with 509 additions and 117 deletions

View file

@ -55,7 +55,30 @@
"bit": "cpp", "bit": "cpp",
"compare": "cpp", "compare": "cpp",
"concepts": "cpp", "concepts": "cpp",
"numbers": "cpp" "numbers": "cpp",
"any": "cpp",
"hash_map": "cpp",
"strstream": "cpp",
"bitset": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"forward_list": "cpp",
"list": "cpp",
"ratio": "cpp",
"format": "cpp",
"future": "cpp",
"mutex": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"span": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"typeindex": "cpp",
"valarray": "cpp",
"variant": "cpp"
}, },
"cmake.sourceDirectory": "${workspaceFolder}/.pio/libdeps/esp32/Adafruit BusIO", "cmake.sourceDirectory": "${workspaceFolder}/.pio/libdeps/esp32/Adafruit BusIO",
"editor.formatOnSave": false, "editor.formatOnSave": false,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -1,48 +1,23 @@
#include "HardwareAbstract.hpp" #include "HardwareAbstract.hpp"
HardwareAbstract::HardwareAbstract( HardwareAbstract::HardwareAbstract()
std::shared_ptr<DisplayAbstract> aDisplay,
std::shared_ptr<BatteryInterface> aBattery,
std::shared_ptr<wifiHandlerInterface> aWifiHandler
)
: mBattery(std::move(aBattery)),
mWifiHandler(std::move(aWifiHandler)),
mDisplay(std::move(aDisplay))
{} {}
std::optional<HardwareAbstract::batteryStatus> HardwareAbstract::getBatteryStatus(){ std::optional<HardwareAbstract::batteryStatus> HardwareAbstract::getBatteryStatus(){
#if 0
if(mBattery){ if(mBattery){
HardwareAbstract::batteryStatus currentStatus; HardwareAbstract::batteryStatus currentStatus;
currentStatus.percentage = mBattery->getPercentage(); currentStatus.percentage = mBattery->getPercentage();
currentStatus.isCharging = mBattery->isCharging(); currentStatus.isCharging = mBattery->isCharging();
return currentStatus; return currentStatus;
} }
#endif
return std::nullopt; return std::nullopt;
} }
#if 0
void HardwareAbstract::onBatteryChange(std::function<void(HardwareAbstract::batteryStatus)> onBatteryStatusChangeHandler){ void HardwareAbstract::onBatteryChange(std::function<void(HardwareAbstract::batteryStatus)> onBatteryStatusChangeHandler){
mBatteryNotification.onNotify(std::move(onBatteryStatusChangeHandler)); mBatteryNotification.onNotify(std::move(onBatteryStatusChangeHandler));
} }
#endif
void HardwareAbstract::onStartWifiScan(std::function<void()> cb_func){
this->wifi_scan_start_cb.push_back(cb_func);
}
void HardwareAbstract::onWifiScanDone(std::function<void(std::shared_ptr<std::vector<WifiInfo>>)> cb_func){
this->wifi_scan_done_cb.push_back(cb_func);
}
void HardwareAbstract::notifyStartWifiScan(){
for (std::function<void()> cb_func:this->wifi_scan_start_cb)
{
cb_func();
}
}
void HardwareAbstract::notifyWifiScanDone(std::shared_ptr<std::vector<WifiInfo>> info){
for (std::function<void(std::shared_ptr<std::vector<WifiInfo>>)> cb_func: this->wifi_scan_done_cb)
{
cb_func(info);
}
}

View file

@ -1,16 +1,13 @@
// OMOTE Hardware Abstraction // OMOTE Hardware Abstraction
// 2023 Matthew Colvin // 2023 Matthew Colvin
#ifndef _HARDWAREABSTRACT_H_
#pragma once #define _HARDWAREABSTRACT_H_
#include <functional> #include <functional>
#include <lvgl.h> #include <lvgl.h>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
#include "BatteryInterface.h"
#include "DisplayAbstract.h"
#include "wifiHandlerInterface.h"
#include "Notification.hpp" #include "Notification.hpp"
typedef struct { typedef struct {
@ -18,12 +15,15 @@ typedef struct {
int rssi; int rssi;
} WifiInfo; } WifiInfo;
typedef struct {
bool isConnected;
std::string IP;
std::string ssid;
}wifiStatus;
class HardwareAbstract { class HardwareAbstract {
public: public:
HardwareAbstract( HardwareAbstract(
std::shared_ptr<DisplayAbstract> aDisplay,
std::shared_ptr<BatteryInterface> aBattery = nullptr,
std::shared_ptr<wifiHandlerInterface> aWifiHandler = nullptr
); );
struct batteryStatus { struct batteryStatus {
@ -39,27 +39,24 @@ public:
/// status has changed. /// status has changed.
/// @param onBatteryStatusChangeHandler - Callable to be ran when batter status changes /// @param onBatteryStatusChangeHandler - Callable to be ran when batter status changes
void onBatteryChange(std::function<void(batteryStatus)> onBatteryStatusChangeHandler); void onBatteryChange(std::function<void(batteryStatus)> onBatteryStatusChangeHandler);
void onStartWifiScan(std::function<void()> cb_func);
void onWifiScanDone(std::function<void(std::shared_ptr<std::vector<WifiInfo>>)> cb_func);
void notifyStartWifiScan();
void notifyWifiScanDone(std::shared_ptr<std::vector<WifiInfo>> info);
/// @brief Override in order to do setup of hardware devices /// @brief Override in order to do setup of hardware devices
virtual void init() = 0; virtual void init() = 0;
/// @brief Override to allow printing of a message for debugging /// @brief Override to allow printing of a message for debugging
/// @param message - Debug message /// @param message - Debug message
virtual void debugPrint(std::string message) = 0; virtual void debugPrint(const char* fmt, ...) = 0;
Notification<std::shared_ptr<std::vector<WifiInfo>>> wifi_scan_done;
Notification<> wifi_scan_start;
Notification<std::shared_ptr<std::string>, std::shared_ptr<std::string>> wifi_connect;
Notification<std::shared_ptr<wifiStatus>> wifi_status_update;
protected: protected:
Notification<batteryStatus> mBatteryNotification; Notification<batteryStatus> mBatteryNotification;
private: private:
std::vector<std::function<void()>> wifi_scan_start_cb;
std::vector<std::function<void(std::shared_ptr<std::vector<WifiInfo>>)>> wifi_scan_done_cb;
std::shared_ptr<BatteryInterface> mBattery;
std::shared_ptr<wifiHandlerInterface> mWifiHandler;
std::shared_ptr<DisplayAbstract> mDisplay;
}; };
#endif

View file

@ -1,14 +1,14 @@
#pragma once #pragma once
#include <string> #include <string>
#include "HardwareAbstract.hpp"
class wifiHandlerInterface{ class wifiHandlerInterface{
public: public:
virtual void begin() = 0; virtual void begin() = 0;
virtual void connect(const char* SSID, const char* password) = 0; //virtual void connect(const char* SSID, const char* password) = 0;
virtual void disconnect() = 0; virtual void disconnect() = 0;
virtual bool isConnected() = 0; virtual bool isConnected() = 0;
virtual void turnOff() = 0; virtual void turnOff() = 0;
virtual void scan() = 0; virtual void scan() = 0;
virtual char* getSSID() = 0;
virtual std::string getIP() = 0; virtual std::string getIP() = 0;
}; };

View file

@ -15,6 +15,7 @@ class Notification{
std::vector<HandlerTy> mFunctionHandlers; std::vector<HandlerTy> mFunctionHandlers;
}; };
template <class... handlerData> template <class... handlerData>
void Notification<handlerData...>::onNotify(HandlerTy aHandler){ void Notification<handlerData...>::onNotify(HandlerTy aHandler){
mFunctionHandlers.push_back(std::move(aHandler)); mFunctionHandlers.push_back(std::move(aHandler));
@ -25,4 +26,4 @@ void Notification<outboundData...>::notify(outboundData... notifySendData){
for (auto handler : mFunctionHandlers){ for (auto handler : mFunctionHandlers){
handler(notifySendData...); handler(notifySendData...);
} }
} }

View file

@ -52,13 +52,7 @@ void HardwareRevX::initIO() {
} }
HardwareRevX::HardwareRevX(): HardwareRevX::HardwareRevX():
HardwareAbstract( HardwareAbstract(){
Display::getInstance(),
std::make_shared<Battery>(ADC_BAT,CRG_STAT),
wifiHandler::getInstance()
){
// Reset Sleep Timer on Touch Events
Display::getInstance()->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
} }
HardwareRevX::WakeReason getWakeReason() { HardwareRevX::WakeReason getWakeReason() {
@ -77,6 +71,9 @@ void HardwareRevX::init() {
// Make sure ESP32 is running at full speed // Make sure ESP32 is running at full speed
setCpuFrequencyMhz(240); setCpuFrequencyMhz(240);
mDisplay = Display::getInstance(std::shared_ptr<HardwareAbstract>(this));
mBattery = std::make_shared<Battery>(ADC_BAT,CRG_STAT);
mWifiHandler = wifiHandler::getInstance(std::shared_ptr<HardwareAbstract>(this));
wakeup_reason = getWakeReason(); wakeup_reason = getWakeReason();
initIO(); initIO();
setupBacklight(); setupBacklight();
@ -86,12 +83,26 @@ void HardwareRevX::init() {
setupIMU(); setupIMU();
setupIR(); setupIR();
debugPrint(std::string("Finished Hardware Setup in %d", millis())); debugPrint("Finished Hardware Setup in %d", millis());
} }
#if 0
void HardwareRevX::debugPrint(std::string aDebugMessage) { void HardwareRevX::debugPrint(std::string aDebugMessage) {
Serial.print(aDebugMessage.c_str()); Serial.print(aDebugMessage.c_str());
} }
#else
void HardwareRevX::debugPrint(const char* fmt, ...)
{
char result[100];
va_list arguments;
va_start(arguments, fmt);
vsnprintf(result, 100, fmt, arguments);
va_end (arguments);
Serial.print(result);
}
#endif
std::shared_ptr<HardwareRevX> HardwareRevX::getInstance(){ std::shared_ptr<HardwareRevX> HardwareRevX::getInstance(){
if (!mInstance) { if (!mInstance) {

View file

@ -16,6 +16,9 @@
#include "omoteconfig.h" #include "omoteconfig.h"
#include "BatteryInterface.h"
#include "wifiHandlerInterface.h"
#include "DisplayAbstract.h"
class HardwareRevX : public HardwareAbstract { class HardwareRevX : public HardwareAbstract {
@ -27,7 +30,11 @@ public:
// HardwareAbstract // HardwareAbstract
virtual void init() override; virtual void init() override;
#if 0
virtual void debugPrint(std::string aDebugMessage) override; virtual void debugPrint(std::string aDebugMessage) override;
#else
void debugPrint(const char* fmt, ...);
#endif
void loopHandler(); void loopHandler();
@ -54,6 +61,9 @@ protected:
private: private:
HardwareRevX(); HardwareRevX();
std::shared_ptr<BatteryInterface> mBattery;
std::shared_ptr<wifiHandlerInterface> mWifiHandler;
std::shared_ptr<DisplayAbstract> mDisplay;
// 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;

View file

@ -3,20 +3,21 @@
#include "omoteconfig.h" #include "omoteconfig.h"
#include "Wire.h" #include "Wire.h"
std::shared_ptr<Display> Display::getInstance() std::shared_ptr<Display> Display::getInstance(std::shared_ptr<HardwareAbstract> aHardware)
{ {
if (DisplayAbstract::mInstance == nullptr) if (DisplayAbstract::mInstance == nullptr)
{ {
DisplayAbstract::mInstance = std::shared_ptr<Display>(new Display(LCD_EN, LCD_BL)); DisplayAbstract::mInstance = std::shared_ptr<Display>(new Display(LCD_EN, LCD_BL, aHardware));
} }
return std::static_pointer_cast<Display>(mInstance); return std::static_pointer_cast<Display>(mInstance);
} }
Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(), Display::Display(int backlight_pin, int enable_pin, std::shared_ptr<HardwareAbstract> aHardware): DisplayAbstract(),
mBacklightPin(backlight_pin), mBacklightPin(backlight_pin),
mEnablePin(enable_pin), mEnablePin(enable_pin),
tft(TFT_eSPI()), tft(TFT_eSPI()),
touch(Adafruit_FT6206()) touch(Adafruit_FT6206()),
mHardware(aHardware)
{ {
pinMode(mEnablePin, OUTPUT); pinMode(mEnablePin, OUTPUT);
digitalWrite(mEnablePin, HIGH); digitalWrite(mEnablePin, HIGH);

View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "DisplayAbstract.h" #include "DisplayAbstract.h"
#include "HardwareAbstract.hpp"
#include "Notification.hpp" #include "Notification.hpp"
#include <Adafruit_FT6206.h> #include <Adafruit_FT6206.h>
#include <memory> #include <memory>
@ -19,7 +20,7 @@
class Display: public DisplayAbstract class Display: public DisplayAbstract
{ {
public: public:
static std::shared_ptr<Display> getInstance(); static std::shared_ptr<Display> getInstance(std::shared_ptr<HardwareAbstract> aHardware);
virtual void setBrightness(uint8_t brightness) override; virtual void setBrightness(uint8_t brightness) override;
virtual void turnOff() override; virtual void turnOff() override;
@ -31,7 +32,7 @@ class Display: public DisplayAbstract
virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override; virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override;
private: private:
Display(int backlight_pin, int enable_pin); Display(int backlight_pin, int enable_pin, std::shared_ptr<HardwareAbstract> aHardware);
void setupTFT(); void setupTFT();
void setupTouchScreen(); void setupTouchScreen();
@ -42,6 +43,6 @@ class Display: public DisplayAbstract
Adafruit_FT6206 touch; Adafruit_FT6206 touch;
TS_Point touchPoint; TS_Point touchPoint;
TS_Point oldPoint; TS_Point oldPoint;
std::shared_ptr<HardwareAbstract> mHardware;
Notification<TS_Point> mTouchEvent; Notification<TS_Point> mTouchEvent;
}; };

View file

@ -1,18 +1,29 @@
#include "wifihandler.hpp" #include "wifihandler.hpp"
#include <Arduino.h> #include <Arduino.h>
#include <Preferences.h> #include <Preferences.h>
#include "HardwareAbstract.hpp"
std::shared_ptr<wifiHandler> wifiHandler::mInstance = nullptr; std::shared_ptr<wifiHandler> wifiHandler::mInstance = nullptr;
// WiFi status event // WiFi status event
void wifiHandler::WiFiEvent(WiFiEvent_t event){ void wifiHandler::WiFiEvent(WiFiEvent_t event){
int no_networks = 0; int no_networks = 0;
switch (event) switch (event)
{ {
case ARDUINO_EVENT_WIFI_SCAN_DONE: case ARDUINO_EVENT_WIFI_SCAN_DONE:
{
Serial.println("WIFI scan done\n"); Serial.println("WIFI scan done\n");
no_networks = WiFi.scanComplete(); no_networks = WiFi.scanComplete();
std::vector<WifiInfo> *vec = new std::vector<WifiInfo>();
std::shared_ptr<std::vector<WifiInfo>> info = std::shared_ptr<std::vector<WifiInfo>>(vec);
for (int i = 0; i < no_networks; i++)
{
info->push_back(WifiInfo {
.ssid = std::string(WiFi.SSID(i).c_str()),
.rssi = WiFi.RSSI(i)
});
}
if (no_networks < 0) if (no_networks < 0)
{ {
Serial.println("Scan failed"); Serial.println("Scan failed");
@ -25,40 +36,74 @@ void wifiHandler::WiFiEvent(WiFiEvent_t event){
Serial.print(" found\n"); Serial.print(" found\n");
//this->display.wifi_scan_complete( no_networks); //this->display.wifi_scan_complete( no_networks);
} }
mHardware->wifi_scan_done.notify(info);
break; break;
}
case ARDUINO_EVENT_WIFI_STA_GOT_IP: case ARDUINO_EVENT_WIFI_STA_GOT_IP:
case ARDUINO_EVENT_WIFI_STA_GOT_IP6: case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
// TODO convert to callbacks this->update_credentials();
//display.update_wifi(true);
//update_credentials(temporary_ssid, temporary_password);
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
case ARDUINO_EVENT_WIFI_STA_LOST_IP: case ARDUINO_EVENT_WIFI_STA_LOST_IP:
case ARDUINO_EVENT_WIFI_STA_STOP: case ARDUINO_EVENT_WIFI_STA_STOP:
// TODO Convert to Callbacks this->update_status();
//display.update_wifi(false);
default: default:
break; break;
} }
if (WiFi.status() == WL_CONNECT_FAILED)
{
Serial.println("connection failed.");
WiFi.disconnect();
}
Serial.println(WiFi.status());
} }
std::shared_ptr<wifiHandler> wifiHandler::getInstance() std::shared_ptr<wifiHandler> wifiHandler::getInstance(std::shared_ptr<HardwareAbstract> aHardware)
{ {
if(mInstance) if(mInstance)
{ {
return mInstance; return mInstance;
} }
return std::shared_ptr<wifiHandler>(new wifiHandler()); mInstance = std::shared_ptr<wifiHandler>(new wifiHandler(aHardware));
return mInstance;
}; };
wifiHandler::wifiHandler() wifiHandler::wifiHandler(std::shared_ptr<HardwareAbstract> aHardware)
{ {
this->password[0] = '\0'; this->mHardware = aHardware;
this->SSID[0] = '\0'; this->mHardware->wifi_scan_start.onNotify([this](){this->mHardware->debugPrint("scan called\n"); this->scan();});
this->mHardware->wifi_connect.onNotify([this] (std::shared_ptr<std::string> ssid, std::shared_ptr<std::string> password){this->connect(ssid, password);});
this->password = "";
this->SSID = "";
this->begin();
} }
void wifiHandler::update_credentials(const char* temporary_ssid, const char* temporary_password) void wifiHandler::update_status()
{ {
Serial.println("update_status");
std::shared_ptr<wifiStatus> status = std::make_shared<wifiStatus>(wifiStatus());
//wifiStatus *status = new wifiStatus();
status->isConnected = WiFi.isConnected();
//status->IP = WiFi.localIP();
IPAddress ip = WiFi.localIP();
String ip_str = ip.toString();
status->IP = ip.toString().c_str();
//ip.copy(status->IP, ip.length());
String ssid = WiFi.SSID();
status->ssid = WiFi.SSID().c_str();
//this->wifi_status.isConnected = WiFi.isConnected();
//this->wifi_status.IP = WiFi.localIP();
//this->wifi_status.isConnected = true;
//Serial.println(WiFi.localIP());
this->mHardware->wifi_status_update.notify(status);
}
void wifiHandler::update_credentials()
{
#if 0
if (strcmp(temporary_password, wifiHandler::password) != 0 || strcmp(temporary_ssid, wifiHandler::SSID) != 0) if (strcmp(temporary_password, wifiHandler::password) != 0 || strcmp(temporary_ssid, wifiHandler::SSID) != 0)
{ {
strcpy(wifiHandler::password, temporary_password); strcpy(wifiHandler::password, temporary_password);
@ -72,18 +117,36 @@ void wifiHandler::update_credentials(const char* temporary_ssid, const char* tem
preferences.putString("SSID", tempString); preferences.putString("SSID", tempString);
preferences.end(); preferences.end();
} }
#else
if (this->temporary_password->compare(this->password) != 0 || this->temporary_ssid->compare(this->SSID))
{
this->password = *(this->temporary_password);
this->SSID = *(this->temporary_ssid);
Preferences preferences;
preferences.begin("wifiSettings", false);
String tempString = this->temporary_password->c_str();
preferences.putString("password", tempString);
tempString = this->temporary_ssid->c_str();
preferences.putString("SSID", tempString);
preferences.end();
}
#endif
} }
void wifiHandler::scan() void wifiHandler::scan()
{ {
Serial.println("scan called");
WiFi.scanNetworks(true); WiFi.scanNetworks(true);
} }
void wifiHandler::begin() void wifiHandler::begin()
{ {
//this->display = display; //this->display = display;
WiFi.setHostname("OMOTE"); WiFi.setHostname("OMOTE");
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
//WiFi.onEvent([this] (WiFiEvent_t event) {mInstance->WiFiEvent(event);});
WiFi.onEvent([] (WiFiEvent_t event) {mInstance->WiFiEvent(event);}); WiFi.onEvent([] (WiFiEvent_t event) {mInstance->WiFiEvent(event);});
Preferences preferences; Preferences preferences;
@ -97,9 +160,11 @@ void wifiHandler::begin()
{ {
Serial.print("Connecting to wifi "); Serial.print("Connecting to wifi ");
Serial.println(ssid); Serial.println(ssid);
strcpy(this->SSID, ssid.c_str()); //strcpy(this->SSID, ssid.c_str());
strcpy(this->password, password.c_str()); //strcpy(this->password, password.c_str());
this->connect(this->SSID, this->password); this->SSID = ssid.c_str();
this->password = password.c_str();
//this->connect(this->SSID, this->password);
} }
else else
{ {
@ -113,11 +178,11 @@ void wifiHandler::begin()
WiFi.setSleep(true); WiFi.setSleep(true);
} }
void wifiHandler::connect(const char* SSID, const char* password) void wifiHandler::connect(std::shared_ptr<std::string> ssid, std::shared_ptr<std::string> password)
{ {
strncpy(this->temporary_password, password, STRING_SIZE); this->temporary_password = password;
strncpy(this->temporary_ssid, SSID, STRING_SIZE); this->temporary_ssid = ssid;
WiFi.begin(SSID, password); WiFi.begin(ssid->c_str(), password->c_str());
} }
void wifiHandler::turnOff() void wifiHandler::turnOff()
@ -135,11 +200,6 @@ bool wifiHandler::isConnected()
return WiFi.isConnected(); return WiFi.isConnected();
} }
char* wifiHandler::getSSID()
{
return this->SSID;
}
std::string wifiHandler::getIP() std::string wifiHandler::getIP()
{ {
return std::string(WiFi.localIP().toString().c_str()); return std::string(WiFi.localIP().toString().c_str());

View file

@ -1,12 +1,14 @@
#pragma once #pragma once
#include "wifiHandlerInterface.h" #include "wifiHandlerInterface.h"
#include "HardwareAbstract.hpp"
#include <WiFi.h> #include <WiFi.h>
#define STRING_SIZE 50 #define STRING_SIZE 50
class wifiHandler: public wifiHandlerInterface { class wifiHandler: public wifiHandlerInterface {
public: public:
static std::shared_ptr<wifiHandler> getInstance(); wifiHandler(std::shared_ptr<HardwareAbstract> aHardware);
static std::shared_ptr<wifiHandler> getInstance(std::shared_ptr<HardwareAbstract> aHardware);
/** /**
* @brief Function to initialize the wifi handler * @brief Function to initialize the wifi handler
* *
@ -19,7 +21,7 @@ class wifiHandler: public wifiHandlerInterface {
* @param SSID * @param SSID
* @param password * @param password
*/ */
void connect(const char* SSID, const char* password); //void connect(const char* SSID, const char* password);
/** /**
* @brief Function to disconnect from the network * @brief Function to disconnect from the network
@ -47,13 +49,6 @@ class wifiHandler: public wifiHandlerInterface {
*/ */
void scan(); void scan();
/**
* @brief Function to get SSID of the currently connected wifi network
*
* @return char* SSID of the currently connected network
*/
char* getSSID();
/** /**
* @brief Function to update the wifi credentials. This function is called in the wifi event callback function * @brief Function to update the wifi credentials. This function is called in the wifi event callback function
* after a connection is established. Only then is the new credentials stored and the old stored credentials * after a connection is established. Only then is the new credentials stored and the old stored credentials
@ -62,7 +57,7 @@ class wifiHandler: public wifiHandlerInterface {
* @param temporary_ssid * @param temporary_ssid
* @param temporary_password * @param temporary_password
*/ */
void update_credentials(const char* temporary_ssid, const char* temporary_password); void update_credentials();
void WiFiEvent(WiFiEvent_t event); void WiFiEvent(WiFiEvent_t event);
@ -72,24 +67,27 @@ class wifiHandler: public wifiHandlerInterface {
* @return String IP Address of the device * @return String IP Address of the device
*/ */
std::string getIP(); std::string getIP();
Notification<std::shared_ptr<std::vector<WifiInfo>>> scan_done;
private: private:
wifiHandler(); wifiStatus wifi_status;
static std::shared_ptr<wifiHandler> mInstance; static std::shared_ptr<wifiHandler> mInstance;
char temporary_password[STRING_SIZE]; std::shared_ptr<HardwareAbstract> mHardware;
char temporary_ssid[STRING_SIZE]; std::shared_ptr<std::string> temporary_password;
std::shared_ptr<std::string> temporary_ssid;
void connect(std::shared_ptr<std::string> ssid, std::shared_ptr<std::string> password);
void update_status();
/** /**
* @brief Internal variable to store the wifi password * @brief Internal variable to store the wifi password
* *
*/ */
char password[STRING_SIZE]; std::string password;
/** /**
* @brief Internal variable to store the wifi SSID * @brief Internal variable to store the wifi SSID
* *
*/ */
char SSID[STRING_SIZE]; std::string SSID;
}; };

View file

@ -6,10 +6,18 @@
class HardwareSimulator : public HardwareAbstract { class HardwareSimulator : public HardwareAbstract {
public: public:
HardwareSimulator(); HardwareSimulator();
#if 0
virtual void debugPrint(std::string message) override { virtual void debugPrint(std::string message) override {
std::cout << message; std::cout << message;
} }
#else
virtual void debugPrint(const char* fmt, ...) override {
va_list arguments;
va_start(arguments, fmt);
vprintf(fmt, arguments);
va_end(arguments);
}
#endif
virtual void init() override {}; virtual void init() override {};

View file

@ -1,5 +1,10 @@
#include "Images.hpp" #include "Images.hpp"
static void update_default_image_color(lv_obj_t* image)
{
lv_obj_set_style_img_recolor(image, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(image, LV_OPA_COVER, LV_PART_MAIN);
}
Images::Images(){ Images::Images(){
setupImageDescriptions(); setupImageDescriptions();
@ -36,6 +41,27 @@ lv_obj_t* Images::addLightBulbIcon(lv_obj_t* parent){
return bulbIcon; return bulbIcon;
} }
lv_obj_t* Images::addWifiNoSignal(lv_obj_t* parent){
lv_obj_t* noSignal = this->addImg(parent, &this->wifiNoSignal);
update_default_image_color(noSignal);
return noSignal;
}
lv_obj_t* Images::addWifiLowSignal(lv_obj_t* parent){
lv_obj_t* lowSignal = this->addImg(parent, &this->wifiLowSignal);
update_default_image_color(lowSignal);
return lowSignal;
}
lv_obj_t* Images::addWifiMidSignal(lv_obj_t* parent){
lv_obj_t* lowSignal = this->addImg(parent, &this->wifiMidSignal);
update_default_image_color(lowSignal);
return lowSignal;
}
lv_obj_t* Images::addWifiHighSignal(lv_obj_t* parent){
lv_obj_t* lowSignal = this->addImg(parent, &this->wifiHighSignal);
update_default_image_color(lowSignal);
return lowSignal;
}
lv_obj_t* Images::addLeftGradiant(lv_obj_t* parent){ lv_obj_t* Images::addLeftGradiant(lv_obj_t* parent){
return this->addImg(parent, &this->gradientLeft); return this->addImg(parent, &this->gradientLeft);
} }
@ -934,6 +960,103 @@ inline static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t
0xff, 0xff, 0xff, 0xff, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x21, 0x22, 0x22, 0x21, 0x01, 0x00, 0x00, 0x00, 0x01, 0x21, 0x22, 0x22, 0x21, 0x01, 0x00, 0x00, 0x00,
}; };
inline static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t WiFi_No_Signal_map[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
inline static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t WiFi_Mid_Signal_map[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
inline static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t WiFi_Low_Signal_map[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
inline static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t WiFi_High_Signal_map[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void Images::setupImageDescriptions(){ void Images::setupImageDescriptions(){
this->low_brightness.header.cf = LV_IMG_CF_ALPHA_8BIT; this->low_brightness.header.cf = LV_IMG_CF_ALPHA_8BIT;
this->low_brightness.header.always_zero = 0; this->low_brightness.header.always_zero = 0;
@ -995,4 +1118,37 @@ void Images::setupImageDescriptions(){
this->gradientRight.header.h = 1; this->gradientRight.header.h = 1;
this->gradientRight.data_size = 30; this->gradientRight.data_size = 30;
this->gradientRight.data = gradientRight_map; this->gradientRight.data = gradientRight_map;
this->wifiNoSignal.header.cf = LV_IMG_CF_ALPHA_8BIT;
this->wifiNoSignal.header.always_zero = 0;
this->wifiNoSignal.header.reserved = 0;
this->wifiNoSignal.header.w = 25;
this->wifiNoSignal.header.h = 21;
this->wifiNoSignal.data_size = 525;
this->wifiNoSignal.data = WiFi_No_Signal_map;
this->wifiLowSignal.header.cf = LV_IMG_CF_ALPHA_8BIT;
this->wifiLowSignal.header.always_zero = 0;
this->wifiLowSignal.header.reserved = 0;
this->wifiLowSignal.header.w = 25;
this->wifiLowSignal.header.h = 21;
this->wifiLowSignal.data_size = 525;
this->wifiLowSignal.data = WiFi_Low_Signal_map;
this->wifiMidSignal.header.cf = LV_IMG_CF_ALPHA_8BIT;
this->wifiMidSignal.header.always_zero = 0;
this->wifiMidSignal.header.reserved = 0;
this->wifiMidSignal.header.w = 25;
this->wifiMidSignal.header.h = 21;
this->wifiMidSignal.data_size = 525;
this->wifiMidSignal.data = WiFi_Mid_Signal_map;
this->wifiHighSignal.header.cf = LV_IMG_CF_ALPHA_8BIT;
this->wifiHighSignal.header.always_zero = 0;
this->wifiHighSignal.header.reserved = 0;
this->wifiHighSignal.header.w = 25;
this->wifiHighSignal.header.h = 21;
this->wifiHighSignal.data_size = 525;
this->wifiHighSignal.data = WiFi_High_Signal_map;
} }

View file

@ -19,6 +19,12 @@ public:
lv_obj_t* addLeftGradiant(lv_obj_t* parent); lv_obj_t* addLeftGradiant(lv_obj_t* parent);
lv_obj_t* addRightGradiant(lv_obj_t* parent); lv_obj_t* addRightGradiant(lv_obj_t* parent);
lv_obj_t* addWifiNoSignal(lv_obj_t* parent);
lv_obj_t* addWifiLowSignal(lv_obj_t* parent);
lv_obj_t* addWifiMidSignal(lv_obj_t* parent);
lv_obj_t* addWifiHighSignal(lv_obj_t* parent);
private: private:
// Make Image based on anImageDesc then // Make Image based on anImageDesc then
// add that image to parent. // add that image to parent.
@ -36,6 +42,9 @@ private:
lv_img_dsc_t gradientLeft; lv_img_dsc_t gradientLeft;
lv_img_dsc_t gradientRight; lv_img_dsc_t gradientRight;
lv_img_dsc_t wifiNoSignal;
lv_img_dsc_t wifiLowSignal;
lv_img_dsc_t wifiMidSignal;
lv_img_dsc_t wifiHighSignal;
}; };

View file

@ -78,7 +78,7 @@ private:
std::shared_ptr<HardwareAbstract> mHardware; std::shared_ptr<HardwareAbstract> mHardware;
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;
/** /**
* @brief Keyboard object used whenever a keyboard is needed. * @brief Keyboard object used whenever a keyboard is needed.
* *
@ -180,6 +180,7 @@ void create_keyboard();
unsigned int no_wifi_networks; 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
* *

View file

@ -1,5 +1,8 @@
#include "OmoteUI.hpp" #include "OmoteUI.hpp"
#define WIFI_SUBPAGE_SIZE 3
static char* ssid;
lv_obj_t* OmoteUI::create_wifi_selection_page(lv_obj_t* menu) lv_obj_t* OmoteUI::create_wifi_selection_page(lv_obj_t* menu)
{ {
/* Create sub page for wifi*/ /* Create sub page for wifi*/
@ -49,7 +52,7 @@ void OmoteUI::password_field_event_cb(lv_event_t* e)
const char* password = lv_textarea_get_text(ta); const char* password = lv_textarea_get_text(ta);
switch(code){ switch(code){
case LV_EVENT_READY: case LV_EVENT_READY:
//wifihandler.connect(ssid, password); this->mHardware->wifi_connect.notify(std::make_shared<std::string>(std::string(ssid)), std::make_shared<std::string>(std::string(password)));
lv_obj_clear_state(ta, LV_STATE_FOCUSED); lv_obj_clear_state(ta, LV_STATE_FOCUSED);
this->hide_keyboard(); this->hide_keyboard();
this->reset_settings_menu(); this->reset_settings_menu();
@ -70,11 +73,13 @@ void OmoteUI::connect_btn_cb(lv_event_t* event)
lv_obj_t* ta = (lv_obj_t*) event->user_data; lv_obj_t* ta = (lv_obj_t*) event->user_data;
const char* password = lv_textarea_get_text(ta); const char* password = lv_textarea_get_text(ta);
this->mHardware->wifi_connect.notify(std::make_shared<std::string>(std::string(ssid)), std::make_shared<std::string>(std::string(password)));
//Trigger wifi connection here //Trigger wifi connection here
//wifihandler.connect(ssid, password); //wifihandler.connect(ssid, password);
lv_obj_clear_state(ta, LV_STATE_FOCUSED); lv_obj_clear_state(ta, LV_STATE_FOCUSED);
this->hide_keyboard(); this->hide_keyboard();
this->reset_settings_menu(); this->reset_settings_menu();
} }
void OmoteUI::create_wifi_main_page(lv_obj_t* parent) void OmoteUI::create_wifi_main_page(lv_obj_t* parent)
@ -107,10 +112,120 @@ void OmoteUI::create_wifi_main_page(lv_obj_t* parent)
void OmoteUI::wifi_scan_done(std::shared_ptr<std::vector<WifiInfo>> info) void OmoteUI::wifi_scan_done(std::shared_ptr<std::vector<WifiInfo>> info)
{ {
for (WifiInfo i:*info) unsigned int size = info->size();
this->no_subpages = (size + WIFI_SUBPAGE_SIZE - 1)/WIFI_SUBPAGE_SIZE;
this->no_wifi_networks = size;
this->found_wifi_networks = info;
if (size == 0)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "no networks found");
}
else
{
this->update_wifi_selection_subpage(0);
}
}
void OmoteUI::next_wifi_selection_subpage(lv_event_t* e)
{
int subpage = (int) lv_event_get_user_data(e);
this->update_wifi_selection_subpage(subpage);
}
/**
* @brief Callback function in case a wifi is selected. This callback function will change the label of the wifi password
* sub page to the selected wifi network.
*
* @param e Pointer to event object for the event where this callback is called
*/
static void wifi_selected_cb(lv_event_t* e)
{
lv_obj_t* label = lv_obj_get_child(e->target, 0);
lv_label_set_text((lv_obj_t*) e->user_data, lv_label_get_text(label));
ssid = lv_label_get_text(label);
}
void OmoteUI::update_wifi_selection_subpage(int page)
{
if (page < this->no_subpages)
{
lv_obj_clean(this->wifi_setting_cont);
lv_obj_t* pageLabel = lv_label_create(this->wifi_setting_cont);
lv_label_set_text_fmt(pageLabel, "Page %d/%d", page + 1, this->no_subpages);
if (page > 0)
{ {
mHardware->debugPrint(i.ssid); lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Previous");
lv_obj_align(menuLabel, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_add_event_cb(menuBox, [](lv_event_t* e) {mInstance->next_wifi_selection_subpage(e);},LV_EVENT_CLICKED, (void*)(page - 1));
lv_obj_t* arrow = lv_label_create(menuBox);
lv_label_set_text(arrow, LV_SYMBOL_LEFT);
lv_obj_align(arrow, LV_ALIGN_TOP_LEFT, 0, 0);
} }
for (int i = 0; i < WIFI_SUBPAGE_SIZE && (page*WIFI_SUBPAGE_SIZE + i) < this->no_wifi_networks; i++)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_add_flag(menuBox, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, this->found_wifi_networks->at(page*WIFI_SUBPAGE_SIZE + i).ssid.c_str());
lv_obj_t* wifi_image;
int RSSI = this->found_wifi_networks->at(page*WIFI_SUBPAGE_SIZE + i).rssi;
if (RSSI > -50)
{
wifi_image = imgs.addWifiHighSignal(menuBox);
}
else if (RSSI > -60)
{
wifi_image = imgs.addWifiMidSignal(menuBox);
}
else if (RSSI > -70)
{
wifi_image = imgs.addWifiLowSignal(menuBox);
}
else
{
wifi_image = imgs.addWifiLowSignal(menuBox);
}
lv_obj_align(wifi_image, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_menu_set_load_page_event(this->settingsMenu, menuBox, this->wifi_password_page);
lv_obj_add_event_cb(menuBox, wifi_selected_cb, LV_EVENT_CLICKED, this->wifi_password_label);
}
if ((page + 1) < this->no_subpages)
{
lv_obj_t* menuBox = lv_obj_create(this->wifi_setting_cont);
lv_obj_set_size(menuBox, lv_pct(100), 45);
lv_obj_set_scrollbar_mode(menuBox, LV_SCROLLBAR_MODE_OFF);
lv_obj_t* menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Next");
lv_obj_add_event_cb(menuBox, [](lv_event_t* e) {mInstance->next_wifi_selection_subpage(e);}, LV_EVENT_CLICKED, (void*)(page + 1));
lv_obj_t* arrow = lv_label_create(menuBox);
lv_label_set_text(arrow, LV_SYMBOL_RIGHT);
lv_obj_align(arrow, LV_ALIGN_TOP_RIGHT, 0, 0);
}
lv_obj_scroll_to_y(this->wifi_setting_cont, 0, LV_ANIM_OFF);
}
} }
void OmoteUI::create_wifi_settings(lv_obj_t* menu, lv_obj_t* parent) void OmoteUI::create_wifi_settings(lv_obj_t* menu, lv_obj_t* parent)
@ -118,7 +233,31 @@ void OmoteUI::create_wifi_settings(lv_obj_t* menu, lv_obj_t* parent)
this->wifi_selection_page = this->create_wifi_selection_page(menu); this->wifi_selection_page = this->create_wifi_selection_page(menu);
this->wifi_password_page = this->create_wifi_password_page(this->settingsMenu); this->wifi_password_page = this->create_wifi_password_page(this->settingsMenu);
this->create_wifi_main_page(parent); this->create_wifi_main_page(parent);
this->mHardware->onWifiScanDone([this] (std::shared_ptr<std::vector<WifiInfo>> info) {this->wifi_scan_done(info);}); this->mHardware->wifi_scan_done.onNotify([this] (std::shared_ptr<std::vector<WifiInfo>> info) {this->wifi_scan_done(info);});
this->mHardware->wifi_status_update.onNotify([this] (std::shared_ptr<wifiStatus> status) {this->wifi_status(status);});
}
void OmoteUI::wifi_status(std::shared_ptr<wifiStatus> status)
{
this->mHardware->debugPrint("connected %d\n", status->isConnected);
this->mHardware->debugPrint("IP %s\n", status->IP);
this->mHardware->debugPrint("SSID %s\n", status->ssid);
lv_obj_t* ip_label = lv_obj_get_child(this->wifiOverview, 3);
lv_obj_t* ssid_label = lv_obj_get_child(this->wifiOverview, 0);
if (status->isConnected)
{
lv_label_set_text(this->WifiLabel, LV_SYMBOL_WIFI);
lv_label_set_text(ssid_label, status->ssid.c_str());
lv_label_set_text(ip_label, status->IP.c_str());
}
else
{
lv_label_set_text(this->WifiLabel, "");
lv_label_set_text(ssid_label, "Disconnected");
lv_label_set_text(ip_label, "-");
}
} }
lv_obj_t* OmoteUI::create_wifi_password_page(lv_obj_t* menu) lv_obj_t* OmoteUI::create_wifi_password_page(lv_obj_t* menu)
@ -165,6 +304,8 @@ void OmoteUI::wifi_settings_cb(lv_event_t* event)
lv_obj_clean(cont); lv_obj_clean(cont);
lv_obj_t* label = lv_label_create(cont); lv_obj_t* label = lv_label_create(cont);
lv_label_set_text(label, "Searching for wifi networks"); lv_label_set_text(label, "Searching for wifi networks");
mHardware->debugPrint("Wifi settings cb called\n");
mHardware->wifi_scan_start.notify();
//This will trigger an asynchronouse network scan //This will trigger an asynchronouse network scan
// We need to trigger wifi search via HAL // We need to trigger wifi search via HAL
//wifihandler.scan(); //wifihandler.scan();