-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine and implement hardware interface (#37)
- Loading branch information
1 parent
7a9ee13
commit 6a78c4c
Showing
47 changed files
with
3,533 additions
and
1,628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@startuml | ||
' KEY | ||
' --> : is a | ||
' *-- : must have | ||
' o-- : should have | ||
|
||
namespace HAL{ | ||
interface BatteryInterface | ||
interface WifiInterface | ||
interface OtherHWInterface | ||
|
||
abstract HardwareAbstract | ||
|
||
HardwareAbstract o-- BatteryInterface | ||
HardwareAbstract o-- WifiInterface | ||
HardwareAbstract o-- OtherHWInterface | ||
} | ||
|
||
namespace Simulator{ | ||
class BatterySimulator | ||
class WifiSimulator | ||
BatterySimulator --> HAL.BatteryInterface | ||
WifiSimulator --> HAL.WifiInterface | ||
} | ||
|
||
namespace ESP32{ | ||
class Battery | ||
class WifiHandler | ||
Battery --> HAL.BatteryInterface | ||
WifiHandler --> HAL.WifiInterface | ||
} | ||
|
||
|
||
namespace UI { | ||
class OmoteUI | ||
OmoteUI *-- HAL.HardwareAbstract | ||
} | ||
|
||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "HardwareAbstract.hpp" | ||
|
||
HardwareAbstract::HardwareAbstract(){ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// OMOTE Hardware Abstraction | ||
// 2023 Matthew Colvin | ||
#pragma once | ||
#include "BatteryInterface.h" | ||
#include "DisplayAbstract.h" | ||
#include "wifiHandlerInterface.h" | ||
|
||
#include "Notification.hpp" | ||
|
||
#include <memory> | ||
|
||
class HardwareAbstract { | ||
public: | ||
HardwareAbstract(); | ||
|
||
/// @brief Override in order to do setup of hardware devices post construction | ||
virtual void init() = 0; | ||
|
||
|
||
/// @brief Override to allow printing of a message for debugging | ||
/// @param message - Debug message | ||
virtual void debugPrint(const char* fmt, ...) = 0; | ||
|
||
virtual std::shared_ptr<BatteryInterface> battery() = 0; | ||
virtual std::shared_ptr<DisplayAbstract> display() = 0; | ||
virtual std::shared_ptr<wifiHandlerInterface> wifi() = 0; | ||
|
||
protected: | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#include "Notification.hpp" | ||
|
||
class BatteryInterface { | ||
public: | ||
BatteryInterface() = default; | ||
virtual int getPercentage() = 0; | ||
virtual bool isCharging() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "DisplayAbstract.h" | ||
|
||
std::shared_ptr<DisplayAbstract> DisplayAbstract::mInstance = nullptr; | ||
|
||
DisplayAbstract::DisplayAbstract(){ | ||
lv_init(); | ||
|
||
lv_disp_draw_buf_init(&mdraw_buf, mbufA, mbufB, | ||
SCREEN_WIDTH * SCREEN_HEIGHT / 10); | ||
|
||
// Initialize the display driver | ||
static lv_disp_drv_t disp_drv; | ||
lv_disp_drv_init(&disp_drv); | ||
disp_drv.hor_res = SCREEN_WIDTH; | ||
disp_drv.ver_res = SCREEN_HEIGHT; | ||
disp_drv.flush_cb = &DisplayAbstract::flushDisplayImpl; | ||
disp_drv.draw_buf = &mdraw_buf; | ||
lv_disp_drv_register(&disp_drv); | ||
|
||
// Initialize the touchscreen driver | ||
static lv_indev_drv_t indev_drv; | ||
lv_indev_drv_init(&indev_drv); | ||
indev_drv.type = LV_INDEV_TYPE_POINTER; | ||
indev_drv.read_cb = &DisplayAbstract::screenInputImpl; | ||
lv_indev_drv_register(&indev_drv); | ||
|
||
} | ||
|
||
void DisplayAbstract::flushDisplayImpl(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) { | ||
mInstance->flushDisplay(disp, area, color_p); | ||
} | ||
|
||
void DisplayAbstract::screenInputImpl(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) { | ||
mInstance->screenInput(indev_driver, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
#include <memory> | ||
#include "lvgl.h" | ||
class DisplayAbstract | ||
{ | ||
public: | ||
DisplayAbstract(); | ||
virtual void setBrightness(uint8_t brightness) = 0; | ||
virtual uint8_t getBrightness() = 0; | ||
virtual void turnOff() = 0; | ||
|
||
protected: | ||
// Set this with a getInstance method in the Child Class | ||
static std::shared_ptr<DisplayAbstract> mInstance; | ||
|
||
virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) = 0; | ||
virtual void screenInput(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) = 0; | ||
private: | ||
|
||
// Used to satisfy LVGL APIs | ||
static void flushDisplayImpl(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p); | ||
static void screenInputImpl(lv_indev_drv_t *indev_driver, lv_indev_data_t *data); | ||
|
||
// LVGL Screen Buffers | ||
lv_disp_draw_buf_t mdraw_buf; | ||
lv_color_t mbufA[SCREEN_WIDTH * SCREEN_HEIGHT / 10]; | ||
lv_color_t mbufB[SCREEN_WIDTH * SCREEN_HEIGHT / 10]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
class UIInterface | ||
{ | ||
public: | ||
virtual void setup() = 0; | ||
virtual void setup_ui() = 0; | ||
virtual void wifi_scan_complete(unsigned int size) = 0; | ||
virtual void clear_wifi_networks() = 0; | ||
virtual void update_wifi(bool connected) = 0; | ||
virtual void hide_keyboard() = 0; | ||
virtual void show_keyboard() = 0; | ||
virtual void update() = 0; | ||
virtual void reset_settings_menu() = 0; | ||
virtual void update_battery(int percentage, bool isCharging, bool isConnected) = 0; | ||
virtual void turnOff() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
#include <string> | ||
#include <memory> | ||
#include <functional> | ||
|
||
typedef struct { | ||
std::string ssid; | ||
int rssi; | ||
} WifiInfo; | ||
|
||
typedef struct { | ||
bool isConnected; | ||
std::string IP; | ||
std::string ssid; | ||
}wifiStatus; | ||
|
||
class wifiHandlerInterface{ | ||
public: | ||
virtual bool isAvailable() = 0; | ||
virtual void scan() = 0; | ||
virtual void connect(std::shared_ptr<std::string> ssid, std::shared_ptr<std::string> password) = 0; | ||
virtual void onScanDone(std::function<void (std::shared_ptr<std::vector<WifiInfo>>)> function) = 0; | ||
virtual void onStatusUpdate(std::function<void (std::shared_ptr<wifiStatus>)> function) = 0; | ||
virtual void begin() = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
#include "SPSCQueueInterface.hpp" | ||
|
||
template <typename T> | ||
class MPMCQueueInterface: public SPSCQueueInterface<T> | ||
{ | ||
public: | ||
bool push(T obj, bool overwrite = false); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
#include <vector> | ||
#include <functional> | ||
|
||
template <class... notifyData> | ||
class Notification{ | ||
public: | ||
typedef std::function<void(notifyData...)> HandlerTy; | ||
|
||
Notification() = default; | ||
void onNotify(HandlerTy aHandler); | ||
void notify(notifyData... notifySendData); | ||
|
||
private: | ||
std::vector<HandlerTy> mFunctionHandlers; | ||
}; | ||
|
||
|
||
template <class... handlerData> | ||
void Notification<handlerData...>::onNotify(HandlerTy aHandler){ | ||
mFunctionHandlers.push_back(std::move(aHandler)); | ||
} | ||
|
||
template <class... outboundData> | ||
void Notification<outboundData...>::notify(outboundData... notifySendData){ | ||
for (auto handler : mFunctionHandlers){ | ||
handler(notifySendData...); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
#include <optional> | ||
|
||
template <typename T> | ||
class SPSCQueueInterface { | ||
public: | ||
virtual bool push(T obj) = 0; | ||
virtual std::optional<T> pop() = 0; | ||
virtual std::optional<T> peek() = 0; | ||
virtual bool isFull() = 0; | ||
virtual bool isEmpty() = 0; | ||
}; |
Oops, something went wrong.