Skip to content

Commit

Permalink
Refine and implement hardware interface (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewColvin authored Sep 14, 2023
1 parent 7a9ee13 commit 6a78c4c
Show file tree
Hide file tree
Showing 47 changed files with 3,533 additions and 1,628 deletions.
4 changes: 2 additions & 2 deletions PCB/Remote.kicad_pcb
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@
(property "ki_keywords" "cap capacitor")
(path "/5d818a81-71ff-4f40-8854-04efda688b48")
(attr smd)
(fp_text reference "C13" (at -3.25 -1.68) (layer "F.SilkS")
(fp_text reference "C13" (at -3.238895 0.068182) (layer "F.SilkS")
(effects (font (size 1 1) (thickness 0.15)))
(tstamp 15439bba-04d4-4528-ad0e-855324eb39a5)
)
Expand Down Expand Up @@ -6445,7 +6445,7 @@
(property "ki_keywords" "cap capacitor")
(path "/a888a00f-5496-4d09-af9f-455dba2d8767")
(attr smd)
(fp_text reference "C14" (at 3.5 -1.85) (layer "F.SilkS")
(fp_text reference "C14" (at 3.488895 -0.14998) (layer "F.SilkS")
(effects (font (size 1 1) (thickness 0.15)))
(tstamp 5ecdc16d-4df0-4830-8429-f936a2864918)
)
Expand Down
Binary file modified PCB/production/gerber.zip
Binary file not shown.
30 changes: 29 additions & 1 deletion Platformio/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cmake.configureOnOpen": false,
"files.associations": {
"*.json": "jsonc",
"random": "cpp",
"array": "cpp",
"atomic": "cpp",
Expand Down Expand Up @@ -50,7 +51,34 @@
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"bit": "cpp",
"compare": "cpp",
"concepts": "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",
"editor.formatOnSave": false,
Expand Down
Binary file added Platformio/HAL/Architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions Platformio/HAL/Architecture.puml
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
5 changes: 5 additions & 0 deletions Platformio/HAL/HardwareAbstract.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "HardwareAbstract.hpp"

HardwareAbstract::HardwareAbstract(){

}
30 changes: 30 additions & 0 deletions Platformio/HAL/HardwareAbstract.hpp
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:

};
9 changes: 9 additions & 0 deletions Platformio/HAL/HardwareModules/BatteryInterface.h
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;
};
35 changes: 35 additions & 0 deletions Platformio/HAL/HardwareModules/DisplayAbstract.cpp
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);
}
28 changes: 28 additions & 0 deletions Platformio/HAL/HardwareModules/DisplayAbstract.h
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];
};
17 changes: 17 additions & 0 deletions Platformio/HAL/HardwareModules/UIInterface.h
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;
};
25 changes: 25 additions & 0 deletions Platformio/HAL/HardwareModules/wifiHandlerInterface.h
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;
};
9 changes: 9 additions & 0 deletions Platformio/HAL/MPMCQueueInterface.hpp
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);
};
29 changes: 29 additions & 0 deletions Platformio/HAL/Notification.hpp
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...);
}
}
12 changes: 12 additions & 0 deletions Platformio/HAL/SPSCQueueInterface.hpp
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;
};
Loading

0 comments on commit 6a78c4c

Please sign in to comment.