diff --git a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp index 9488a35..e6c8b34 100644 --- a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp +++ b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.cpp @@ -60,19 +60,18 @@ void wifiHandler::WiFiEvent(WiFiEvent_t event){ bool wifiHandler::isAvailable(){ return true; } -std::shared_ptr wifiHandler::getInstance(std::shared_ptr aHardware) +std::shared_ptr wifiHandler::getInstance() { if(mInstance) { return mInstance; } - mInstance = std::shared_ptr(new wifiHandler(aHardware)); + mInstance = std::shared_ptr(new wifiHandler()); return mInstance; }; -wifiHandler::wifiHandler(std::shared_ptr aHardware) +wifiHandler::wifiHandler() { - this->mHardware = aHardware; this->password = ""; this->SSID = ""; this->begin(); diff --git a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp index bd4bf7c..d44735b 100644 --- a/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp +++ b/Platformio/HAL/Targets/ESP32/wifiHandler/wifihandler.hpp @@ -1,6 +1,5 @@ #pragma once #include "wifiHandlerInterface.h" -#include "HardwareAbstract.hpp" #include "Notification.hpp" #include "memory.h" #include @@ -9,8 +8,8 @@ class wifiHandler: public wifiHandlerInterface { public: - wifiHandler(std::shared_ptr aHardware); - static std::shared_ptr getInstance(std::shared_ptr aHardware); + wifiHandler(); + static std::shared_ptr getInstance(); /** * @brief Function to initialize the wifi handler * @@ -67,7 +66,6 @@ class wifiHandler: public wifiHandlerInterface { std::string getIP(); wifiStatus wifi_status; static std::shared_ptr mInstance; - std::shared_ptr mHardware; std::shared_ptr temporary_password; std::shared_ptr temporary_ssid; diff --git a/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp b/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp index 38c3996..ada3f47 100644 --- a/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp +++ b/Platformio/HAL/Targets/Simulator/HardwareSimulator.cpp @@ -27,10 +27,16 @@ static int tick_thread(void * data) return 0; } -HardwareSimulator::HardwareSimulator(): HardwareAbstract(SDLDisplay::getInstance()){ +HardwareSimulator::HardwareSimulator(): HardwareAbstract(){ /* Tick init. * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed * Create an SDL thread to do this*/ + this->mDisplay = SDLDisplay::getInstance(); + this->mWifiHandler = std::make_shared(wifiHandlerSim()); SDL_CreateThread(tick_thread, "tick", NULL); +} +std::shared_ptr HardwareSimulator::wifi() +{ + return this->mWifiHandler; } \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp b/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp index 5d40d5f..8d8c970 100644 --- a/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp +++ b/Platformio/HAL/Targets/Simulator/HardwareSimulator.hpp @@ -1,23 +1,21 @@ #pragma once #include "HardwareAbstract.hpp" +#include "wifiHandlerSim.hpp" #include #include +#include "SDLDisplay.hpp" class HardwareSimulator : public HardwareAbstract { public: HardwareSimulator(); -#if 0 - virtual void debugPrint(std::string message) override { - 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 + + std::shared_ptr wifi(); virtual void init() override {}; @@ -27,4 +25,7 @@ public: fakeStatus.percentage = 100; return fakeStatus; } +private: + std::shared_ptr mWifiHandler; + std::shared_ptr mDisplay; }; diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp new file mode 100644 index 0000000..3ee7e4f --- /dev/null +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp @@ -0,0 +1,30 @@ +#include "SDLDisplay.hpp" +#include "SDL2/SDL.h" +#include "sdl/sdl.h" + +std::shared_ptr SDLDisplay::getInstance(){ + if (!DisplayAbstract::mInstance){ + DisplayAbstract::mInstance = std::shared_ptr(new SDLDisplay()); + } + return std::static_pointer_cast(mInstance); +} + +void SDLDisplay::setBrightness(uint8_t brightness){ + +} + +void SDLDisplay::turnOff(){ + +} + +void SDLDisplay::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p){ + sdl_display_flush(disp,area,color_p); +} + +void SDLDisplay::screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data){ + sdl_mouse_read(indev_driver,data); +} + +SDLDisplay::SDLDisplay(): DisplayAbstract() { + sdl_init(); +} \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp index 977ca94..53fd84c 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp @@ -1,27 +1,19 @@ +#pragma once #include "DisplayAbstract.h" class SDLDisplay : public DisplayAbstract{ public: - static std::shared_ptr getInstance(){ - if (!DisplayAbstract::mInstance){ - DisplayAbstract::mInstance = std::shared_ptr(new SDLDisplay()); - } - return std::static_pointer_cast(mInstance); - } + static std::shared_ptr getInstance(); - virtual void setBrightness(uint8_t brightness) override {}; - virtual void turnOff() override {}; + void setBrightness(uint8_t brightness); + void turnOff(); protected: - virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override - { sdl_display_flush(disp,area,color_p); }; - virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override - { sdl_mouse_read(indev_driver,data);} + virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override; + virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override; private: - SDLDisplay(): DisplayAbstract(){ - sdl_init(); - } + SDLDisplay(); }; \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp new file mode 100644 index 0000000..01708ea --- /dev/null +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp @@ -0,0 +1,64 @@ +#include "wifiHandlerSim.hpp" + +std::shared_ptr mInstance; + +std::shared_ptr wifiHandlerSim::getInstance() +{ + if(mInstance) + { + return mInstance; + } + mInstance = std::make_shared(wifiHandlerSim()); + return mInstance; +}; + +wifiHandlerSim::wifiHandlerSim(){ + +} + +static wifiStatus status = { + .isConnected = true + , .IP = "172.0.0.1" +}; + +void wifiHandlerSim::connect(std::shared_ptr ssid, std::shared_ptr password){ + status.ssid = *ssid; + std::shared_ptr new_status = std::make_shared (wifiStatus(std::move(status))); + this->status_update.notify(new_status); +} + +static const WifiInfo wifis[] = { + { + .ssid = "High Signal Wifi" + , .rssi = -49 + } + , { + .ssid = "Mid Signal Wifi" + , .rssi = -55 + } + , { + .ssid = "Low Signal Wifi" + , .rssi = -65 + } + , { + .ssid = "No Signal Wifi" + , .rssi = -90 + } +}; + +void wifiHandlerSim::scan(){ + std::shared_ptr> info = std::make_shared>(std::vector(std::begin(wifis), std::end(wifis))); + this->scan_notification.notify(info); +} + +bool wifiHandlerSim::isAvailable(){ + return false; +} + +void wifiHandlerSim::onScanDone(std::function>)> function){ + this->scan_notification.onNotify(std::move(function)); +} + +void wifiHandlerSim::onStatusUpdate(std::function)> function){ + this->status_update.onNotify(std::move(function)); +} \ No newline at end of file diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp new file mode 100644 index 0000000..a318637 --- /dev/null +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp @@ -0,0 +1,34 @@ +#pragma once +#include "wifiHandlerInterface.h" +#include "Notification.hpp" +#include + +class wifiHandlerSim: public wifiHandlerInterface { + public: + wifiHandlerSim(); + static std::shared_ptr getInstance(); + + + /** + * @brief Connect to the wifi using the provided credetials + * + * @param SSID + * @param password + */ + void connect(std::shared_ptr ssid, std::shared_ptr password); + //void connect(const char* SSID, const char* password); + + + + /** + * @brief function to trigger asynchronous scan for wifi networks + * + */ + void scan(); + bool isAvailable(); + void onScanDone(std::function>)> function); + void onStatusUpdate(std::function)> function); + private: + Notification>> scan_notification; + Notification> status_update; +}; \ No newline at end of file diff --git a/Platformio/OmoteUI/wifiSettings.cpp b/Platformio/OmoteUI/wifiSettings.cpp index 355adae..d5f67eb 100644 --- a/Platformio/OmoteUI/wifiSettings.cpp +++ b/Platformio/OmoteUI/wifiSettings.cpp @@ -132,7 +132,7 @@ void OmoteUI::wifi_scan_done(std::shared_ptr> info) } void OmoteUI::next_wifi_selection_subpage(lv_event_t* e) { - int subpage = (int) lv_event_get_user_data(e); + int subpage = (uintptr_t) lv_event_get_user_data(e); this->update_wifi_selection_subpage(subpage); } diff --git a/Platformio/platformio.ini b/Platformio/platformio.ini index 841d482..430b7f1 100644 --- a/Platformio/platformio.ini +++ b/Platformio/platformio.ini @@ -128,6 +128,7 @@ build_flags = ; -------------- Sim Includes --------------------------- -I HAL/Targets/Simulator + -I HAL/Targets/Simulator/wifiHandlerSim debug_build_flags = -g ;Allow debugging in vscode