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(){
|
bool wifiHandler::isAvailable(){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::shared_ptr<wifiHandler> wifiHandler::getInstance(std::shared_ptr<HardwareAbstract> aHardware)
|
std::shared_ptr<wifiHandler> wifiHandler::getInstance()
|
||||||
{
|
{
|
||||||
if(mInstance)
|
if(mInstance)
|
||||||
{
|
{
|
||||||
return mInstance;
|
return mInstance;
|
||||||
}
|
}
|
||||||
mInstance = std::shared_ptr<wifiHandler>(new wifiHandler(aHardware));
|
mInstance = std::shared_ptr<wifiHandler>(new wifiHandler());
|
||||||
return mInstance;
|
return mInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
wifiHandler::wifiHandler(std::shared_ptr<HardwareAbstract> aHardware)
|
wifiHandler::wifiHandler()
|
||||||
{
|
{
|
||||||
this->mHardware = aHardware;
|
|
||||||
this->password = "";
|
this->password = "";
|
||||||
this->SSID = "";
|
this->SSID = "";
|
||||||
this->begin();
|
this->begin();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "wifiHandlerInterface.h"
|
#include "wifiHandlerInterface.h"
|
||||||
#include "HardwareAbstract.hpp"
|
|
||||||
#include "Notification.hpp"
|
#include "Notification.hpp"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
@ -9,8 +8,8 @@
|
||||||
|
|
||||||
class wifiHandler: public wifiHandlerInterface {
|
class wifiHandler: public wifiHandlerInterface {
|
||||||
public:
|
public:
|
||||||
wifiHandler(std::shared_ptr<HardwareAbstract> aHardware);
|
wifiHandler();
|
||||||
static std::shared_ptr<wifiHandler> getInstance(std::shared_ptr<HardwareAbstract> aHardware);
|
static std::shared_ptr<wifiHandler> getInstance();
|
||||||
/**
|
/**
|
||||||
* @brief Function to initialize the wifi handler
|
* @brief Function to initialize the wifi handler
|
||||||
*
|
*
|
||||||
|
@ -67,7 +66,6 @@ class wifiHandler: public wifiHandlerInterface {
|
||||||
std::string getIP();
|
std::string getIP();
|
||||||
wifiStatus wifi_status;
|
wifiStatus wifi_status;
|
||||||
static std::shared_ptr<wifiHandler> mInstance;
|
static std::shared_ptr<wifiHandler> mInstance;
|
||||||
std::shared_ptr<HardwareAbstract> mHardware;
|
|
||||||
std::shared_ptr<std::string> temporary_password;
|
std::shared_ptr<std::string> temporary_password;
|
||||||
std::shared_ptr<std::string> temporary_ssid;
|
std::shared_ptr<std::string> temporary_ssid;
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,16 @@ static int tick_thread(void * data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HardwareSimulator::HardwareSimulator(): HardwareAbstract(SDLDisplay::getInstance()){
|
HardwareSimulator::HardwareSimulator(): HardwareAbstract(){
|
||||||
/* Tick init.
|
/* Tick init.
|
||||||
* You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed
|
* 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*/
|
* Create an SDL thread to do this*/
|
||||||
|
this->mDisplay = SDLDisplay::getInstance();
|
||||||
|
this->mWifiHandler = std::make_shared<wifiHandlerSim>(wifiHandlerSim());
|
||||||
SDL_CreateThread(tick_thread, "tick", NULL);
|
SDL_CreateThread(tick_thread, "tick", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi()
|
||||||
|
{
|
||||||
|
return this->mWifiHandler;
|
||||||
}
|
}
|
|
@ -1,23 +1,21 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "HardwareAbstract.hpp"
|
#include "HardwareAbstract.hpp"
|
||||||
|
#include "wifiHandlerSim.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "SDLDisplay.hpp"
|
||||||
|
|
||||||
class HardwareSimulator : public HardwareAbstract {
|
class HardwareSimulator : public HardwareAbstract {
|
||||||
public:
|
public:
|
||||||
HardwareSimulator();
|
HardwareSimulator();
|
||||||
#if 0
|
|
||||||
virtual void debugPrint(std::string message) override {
|
|
||||||
std::cout << message;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
virtual void debugPrint(const char* fmt, ...) override {
|
virtual void debugPrint(const char* fmt, ...) override {
|
||||||
va_list arguments;
|
va_list arguments;
|
||||||
va_start(arguments, fmt);
|
va_start(arguments, fmt);
|
||||||
vprintf(fmt, arguments);
|
vprintf(fmt, arguments);
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
std::shared_ptr<wifiHandlerInterface> wifi();
|
||||||
|
|
||||||
virtual void init() override {};
|
virtual void init() override {};
|
||||||
|
|
||||||
|
@ -27,4 +25,7 @@ public:
|
||||||
fakeStatus.percentage = 100;
|
fakeStatus.percentage = 100;
|
||||||
return fakeStatus;
|
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"
|
#include "DisplayAbstract.h"
|
||||||
|
|
||||||
class SDLDisplay : public DisplayAbstract{
|
class SDLDisplay : public DisplayAbstract{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<SDLDisplay> getInstance(){
|
static std::shared_ptr<SDLDisplay> getInstance();
|
||||||
if (!DisplayAbstract::mInstance){
|
|
||||||
DisplayAbstract::mInstance = std::shared_ptr<SDLDisplay>(new SDLDisplay());
|
|
||||||
}
|
|
||||||
return std::static_pointer_cast<SDLDisplay>(mInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setBrightness(uint8_t brightness) override {};
|
void setBrightness(uint8_t brightness);
|
||||||
virtual void turnOff() override {};
|
void turnOff();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override
|
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;
|
||||||
virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) override
|
|
||||||
{ sdl_mouse_read(indev_driver,data);}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDLDisplay(): DisplayAbstract(){
|
SDLDisplay();
|
||||||
sdl_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -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)
|
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);
|
this->update_wifi_selection_subpage(subpage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,7 @@ build_flags =
|
||||||
|
|
||||||
; -------------- Sim Includes ---------------------------
|
; -------------- Sim Includes ---------------------------
|
||||||
-I HAL/Targets/Simulator
|
-I HAL/Targets/Simulator
|
||||||
|
-I HAL/Targets/Simulator/wifiHandlerSim
|
||||||
|
|
||||||
debug_build_flags =
|
debug_build_flags =
|
||||||
-g ;Allow debugging in vscode
|
-g ;Allow debugging in vscode
|
||||||
|
|
Loading…
Add table
Reference in a new issue