Updated simulator to support new wifi selection UI
This commit is contained in:
parent
5cd4c6f379
commit
43a930d7a8
10 changed files with 156 additions and 31 deletions
|
@ -60,19 +60,18 @@ void wifiHandler::WiFiEvent(WiFiEvent_t event){
|
|||
bool wifiHandler::isAvailable(){
|
||||
return true;
|
||||
}
|
||||
std::shared_ptr<wifiHandler> wifiHandler::getInstance(std::shared_ptr<HardwareAbstract> aHardware)
|
||||
std::shared_ptr<wifiHandler> wifiHandler::getInstance()
|
||||
{
|
||||
if(mInstance)
|
||||
{
|
||||
return mInstance;
|
||||
}
|
||||
mInstance = std::shared_ptr<wifiHandler>(new wifiHandler(aHardware));
|
||||
mInstance = std::shared_ptr<wifiHandler>(new wifiHandler());
|
||||
return mInstance;
|
||||
};
|
||||
|
||||
wifiHandler::wifiHandler(std::shared_ptr<HardwareAbstract> aHardware)
|
||||
wifiHandler::wifiHandler()
|
||||
{
|
||||
this->mHardware = aHardware;
|
||||
this->password = "";
|
||||
this->SSID = "";
|
||||
this->begin();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
#include "wifiHandlerInterface.h"
|
||||
#include "HardwareAbstract.hpp"
|
||||
#include "Notification.hpp"
|
||||
#include "memory.h"
|
||||
#include <WiFi.h>
|
||||
|
@ -9,8 +8,8 @@
|
|||
|
||||
class wifiHandler: public wifiHandlerInterface {
|
||||
public:
|
||||
wifiHandler(std::shared_ptr<HardwareAbstract> aHardware);
|
||||
static std::shared_ptr<wifiHandler> getInstance(std::shared_ptr<HardwareAbstract> aHardware);
|
||||
wifiHandler();
|
||||
static std::shared_ptr<wifiHandler> 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<wifiHandler> mInstance;
|
||||
std::shared_ptr<HardwareAbstract> mHardware;
|
||||
std::shared_ptr<std::string> temporary_password;
|
||||
std::shared_ptr<std::string> temporary_ssid;
|
||||
|
||||
|
|
|
@ -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>(wifiHandlerSim());
|
||||
SDL_CreateThread(tick_thread, "tick", NULL);
|
||||
}
|
||||
|
||||
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi()
|
||||
{
|
||||
return this->mWifiHandler;
|
||||
}
|
|
@ -1,23 +1,21 @@
|
|||
#pragma once
|
||||
#include "HardwareAbstract.hpp"
|
||||
#include "wifiHandlerSim.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#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<wifiHandlerInterface> wifi();
|
||||
|
||||
virtual void init() override {};
|
||||
|
||||
|
@ -27,4 +25,7 @@ public:
|
|||
fakeStatus.percentage = 100;
|
||||
return fakeStatus;
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<wifiHandlerSim> mWifiHandler;
|
||||
std::shared_ptr<SDLDisplay> mDisplay;
|
||||
};
|
||||
|
|
30
Platformio/HAL/Targets/Simulator/SDLDisplay.cpp
Normal file
30
Platformio/HAL/Targets/Simulator/SDLDisplay.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "SDLDisplay.hpp"
|
||||
#include "SDL2/SDL.h"
|
||||
#include "sdl/sdl.h"
|
||||
|
||||
std::shared_ptr<SDLDisplay> SDLDisplay::getInstance(){
|
||||
if (!DisplayAbstract::mInstance){
|
||||
DisplayAbstract::mInstance = std::shared_ptr<SDLDisplay>(new SDLDisplay());
|
||||
}
|
||||
return std::static_pointer_cast<SDLDisplay>(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();
|
||||
}
|
|
@ -1,27 +1,19 @@
|
|||
#pragma once
|
||||
#include "DisplayAbstract.h"
|
||||
|
||||
class SDLDisplay : public DisplayAbstract{
|
||||
|
||||
public:
|
||||
static std::shared_ptr<SDLDisplay> getInstance(){
|
||||
if (!DisplayAbstract::mInstance){
|
||||
DisplayAbstract::mInstance = std::shared_ptr<SDLDisplay>(new SDLDisplay());
|
||||
}
|
||||
return std::static_pointer_cast<SDLDisplay>(mInstance);
|
||||
}
|
||||
static std::shared_ptr<SDLDisplay> 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();
|
||||
|
||||
};
|
|
@ -0,0 +1,64 @@
|
|||
#include "wifiHandlerSim.hpp"
|
||||
|
||||
std::shared_ptr<wifiHandlerSim> mInstance;
|
||||
|
||||
std::shared_ptr<wifiHandlerSim> wifiHandlerSim::getInstance()
|
||||
{
|
||||
if(mInstance)
|
||||
{
|
||||
return mInstance;
|
||||
}
|
||||
mInstance = std::make_shared<wifiHandlerSim>(wifiHandlerSim());
|
||||
return mInstance;
|
||||
};
|
||||
|
||||
wifiHandlerSim::wifiHandlerSim(){
|
||||
|
||||
}
|
||||
|
||||
static wifiStatus status = {
|
||||
.isConnected = true
|
||||
, .IP = "172.0.0.1"
|
||||
};
|
||||
|
||||
void wifiHandlerSim::connect(std::shared_ptr<std::string> ssid, std::shared_ptr<std::string> password){
|
||||
status.ssid = *ssid;
|
||||
std::shared_ptr<wifiStatus> new_status = std::make_shared<wifiStatus> (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<std::vector<WifiInfo>> info = std::make_shared<std::vector<WifiInfo>>(std::vector(std::begin(wifis), std::end(wifis)));
|
||||
this->scan_notification.notify(info);
|
||||
}
|
||||
|
||||
bool wifiHandlerSim::isAvailable(){
|
||||
return false;
|
||||
}
|
||||
|
||||
void wifiHandlerSim::onScanDone(std::function<void (std::shared_ptr<std::vector<WifiInfo>>)> function){
|
||||
this->scan_notification.onNotify(std::move(function));
|
||||
}
|
||||
|
||||
void wifiHandlerSim::onStatusUpdate(std::function<void (std::shared_ptr<wifiStatus>)> function){
|
||||
this->status_update.onNotify(std::move(function));
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
#include "wifiHandlerInterface.h"
|
||||
#include "Notification.hpp"
|
||||
#include <memory>
|
||||
|
||||
class wifiHandlerSim: public wifiHandlerInterface {
|
||||
public:
|
||||
wifiHandlerSim();
|
||||
static std::shared_ptr<wifiHandlerSim> getInstance();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to the wifi using the provided credetials
|
||||
*
|
||||
* @param SSID
|
||||
* @param password
|
||||
*/
|
||||
void connect(std::shared_ptr<std::string> ssid, std::shared_ptr<std::string> 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<void (std::shared_ptr<std::vector<WifiInfo>>)> function);
|
||||
void onStatusUpdate(std::function<void (std::shared_ptr<wifiStatus>)> function);
|
||||
private:
|
||||
Notification<std::shared_ptr<std::vector<WifiInfo>>> scan_notification;
|
||||
Notification<std::shared_ptr<wifiStatus>> status_update;
|
||||
};
|
|
@ -132,7 +132,7 @@ void OmoteUI::wifi_scan_done(std::shared_ptr<std::vector<WifiInfo>> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue