-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5989736
commit 7c9a062
Showing
95 changed files
with
4,739 additions
and
2,320 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
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
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,20 @@ | ||
#include "HardwareFactory.hpp" | ||
|
||
#if OMOTE_SIM | ||
#include "HardwareSimulator.hpp" | ||
#endif | ||
|
||
#if OMOTE_ESP32 | ||
#include "HardwareRevX.hpp" | ||
#endif | ||
|
||
#if OMOTE_SIM | ||
std::unique_ptr<HardwareAbstract> HardwareFactory::mHardware = | ||
std::make_unique<HardwareSimulator>(); | ||
#endif | ||
#if OMOTE_ESP32 | ||
std::unique_ptr<HardwareAbstract> HardwareFactory::mHardware = | ||
std::make_unique<HardwareRevX>(); | ||
#endif | ||
|
||
HardwareAbstract &HardwareFactory::getAbstract() { return *mHardware; } |
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,11 @@ | ||
#include "HardwareAbstract.hpp" | ||
#include <memory> | ||
/** | ||
* @brief The HardwareFactory is responsible for making the | ||
*/ | ||
class HardwareFactory { | ||
public: | ||
static HardwareAbstract &getAbstract(); | ||
|
||
static std::unique_ptr<HardwareAbstract> mHardware; | ||
}; |
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,8 @@ | ||
#include "KeyPressAbstract.hpp" | ||
|
||
KeyPressAbstract::KeyPressAbstract() {} | ||
|
||
void KeyPressAbstract::RegisterKeyPressHandler( | ||
std::function<bool(KeyPressAbstract::KeyEvent)> aKeyEventHandler) { | ||
mKeyEventHandler = std::move(aKeyEventHandler); | ||
} |
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,73 @@ | ||
#pragma once | ||
#include "Notification.hpp" | ||
|
||
#include <memory> | ||
class KeyPressAbstract { | ||
public: | ||
// Keys from Top Down left to right. | ||
enum class KeyId { | ||
Power, | ||
// Top 4 Buttons left to right | ||
Stop, | ||
Rewind, | ||
Play, | ||
FastForward, | ||
// Buttons around D Pad | ||
Menu, | ||
Info, | ||
Back, | ||
Source, | ||
// D Pad | ||
Up, | ||
Down, | ||
Left, | ||
Right, | ||
Center, | ||
// Volume Channel and 2 between | ||
VolUp, | ||
VolDown, | ||
Mute, | ||
Record, | ||
ChannelUp, | ||
ChannelDown, | ||
// Bottom 4 buttons left to right | ||
Aux1, | ||
Aux2, | ||
Aux3, | ||
Aux4, | ||
INVALID | ||
}; | ||
|
||
class KeyEvent { | ||
public: | ||
enum class Type { Press, Release, INVALID }; | ||
|
||
KeyEvent() = default; | ||
KeyEvent(const KeyId aId, const Type aType) : mId(aId), mType(aType) {} | ||
|
||
KeyId mId = KeyId::INVALID; | ||
Type mType = Type::INVALID; | ||
}; | ||
|
||
KeyPressAbstract(); | ||
|
||
/// @brief Register a SINGLE handler to be used for proccessing keys | ||
/// @param aKeyEventHandler - Callable the Handles KeyEvent | ||
void RegisterKeyPressHandler(std::function<bool(KeyEvent)> aKeyEventHandler); | ||
|
||
protected: | ||
/// @brief Function ment to be called regularly to allow | ||
/// proccesssing of key presses by calling mKeyEventHandler | ||
/// best case this is done on a seprate thread/task | ||
/// since it could take a while to handle a KeyPress | ||
virtual void HandleKeyPresses() = 0; | ||
|
||
/// @brief Function to queue up Key events to be handled later on by | ||
/// HandleKeyPresses() hopefully on a seprate thread or task | ||
/// This function should be implemented in a way that makes it ISR | ||
/// safe | ||
/// @param aJustOccuredKeyEvent - A Key even that just occured | ||
virtual void QueueKeyEvent(KeyEvent aJustOccuredKeyEvent) = 0; | ||
|
||
std::function<bool(KeyEvent)> mKeyEventHandler; | ||
}; |
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 |
---|---|---|
@@ -1,25 +1,54 @@ | ||
#pragma once | ||
#include <string> | ||
#include <memory> | ||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
|
||
class wifiHandlerInterface { | ||
public: | ||
wifiHandlerInterface() = default; | ||
struct WifiInfo { | ||
WifiInfo() = default; | ||
WifiInfo(std::string aSsid, int aRssi) : ssid(aSsid), rssi(aRssi) {} | ||
|
||
std::string ssid = ""; | ||
int rssi = 0; | ||
}; | ||
|
||
struct wifiStatus { | ||
wifiStatus() = default; | ||
wifiStatus(bool aConnected, std::string aIp, std::string aSsid) | ||
: isConnected(aConnected), IP(aIp), ssid(aSsid){}; | ||
|
||
bool isConnected = false; | ||
std::string IP = ""; | ||
std::string ssid = ""; | ||
}; | ||
|
||
typedef std::vector<WifiInfo> ScanDoneDataTy; | ||
typedef Notification<ScanDoneDataTy> ScanNotificationTy; | ||
|
||
/// @brief Initialize the wifi handler | ||
virtual void begin() = 0; | ||
/// @brief Trigger a scan scan for wifi networks | ||
virtual void scan() = 0; | ||
/// @brief Attempt a connection to the wifi using the provided credentials | ||
virtual void connect(std::string ssid, std::string password) = 0; | ||
/// @brief Get the status of the current wifi connection | ||
virtual wifiStatus GetStatus() = 0; | ||
|
||
// Register for Scan Notification to handle when scans are completed | ||
std::shared_ptr<ScanNotificationTy> ScanCompleteNotification() { | ||
return mScanNotification; | ||
}; | ||
|
||
// Register for Status notifications to handle changes in status | ||
std::shared_ptr<Notification<wifiStatus>> WifiStatusNotification() { | ||
return mStatusUpdate; | ||
}; | ||
|
||
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; | ||
protected: | ||
std::shared_ptr<ScanNotificationTy> mScanNotification = | ||
std::make_shared<ScanNotificationTy>(); | ||
std::shared_ptr<Notification<wifiStatus>> mStatusUpdate = | ||
std::make_shared<Notification<wifiStatus>>(); | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1,90 @@ | ||
#pragma once | ||
#include <vector> | ||
#include <functional> | ||
#include <map> | ||
#include <memory> | ||
|
||
template <class... notifyData> | ||
class Notification{ | ||
public: | ||
typedef std::function<void(notifyData...)> HandlerTy; | ||
template <class... notifyData> class Handler; | ||
template <class... notifyData> class Notification { | ||
friend class Handler<notifyData...>; | ||
|
||
Notification() = default; | ||
void onNotify(HandlerTy aHandler); | ||
void notify(notifyData... notifySendData); | ||
public: | ||
typedef std::function<void(notifyData...)> HandlerTy; | ||
typedef int HandlerID; | ||
|
||
private: | ||
std::vector<HandlerTy> mFunctionHandlers; | ||
}; | ||
Notification() { mIdMaker = 0; }; | ||
void notify(notifyData... notifySendData); | ||
|
||
protected: | ||
HandlerID onNotify(HandlerTy aHandler); | ||
void unregister(HandlerID aHandler); | ||
|
||
private: | ||
std::map<HandlerID, HandlerTy> mFunctionHandlers; | ||
HandlerID mIdMaker; | ||
}; | ||
|
||
template <class... handlerData> | ||
void Notification<handlerData...>::onNotify(HandlerTy aHandler){ | ||
mFunctionHandlers.push_back(std::move(aHandler)); | ||
int Notification<handlerData...>::onNotify(HandlerTy aHandler) { | ||
if (aHandler) { | ||
mFunctionHandlers[++mIdMaker] = std::move(aHandler); | ||
return mIdMaker; | ||
} else { | ||
return -1; | ||
} | ||
} | ||
|
||
template <class... outboundData> | ||
void Notification<outboundData...>::notify(outboundData... notifySendData){ | ||
for (auto handler : mFunctionHandlers){ | ||
handler(notifySendData...); | ||
void Notification<outboundData...>::notify(outboundData... notifySendData) { | ||
for (auto handler : mFunctionHandlers) { | ||
handler.second(notifySendData...); | ||
} | ||
} | ||
|
||
template <class... handlerData> | ||
void Notification<handlerData...>::unregister(HandlerID aHandlerId) { | ||
auto handlerToUnRegister = | ||
std::find_if(mFunctionHandlers.begin(), mFunctionHandlers.end(), | ||
[aHandlerId](auto registeredHandler) { | ||
return aHandlerId == registeredHandler.first; | ||
}); | ||
if (handlerToUnRegister != mFunctionHandlers.end()) { | ||
mFunctionHandlers.erase(handlerToUnRegister); | ||
} | ||
} | ||
|
||
template <class... notifyData> class Handler { | ||
public: | ||
typedef std::function<void(notifyData...)> callableTy; | ||
void operator=(Handler &other) = delete; | ||
|
||
Handler() = default; | ||
Handler(std::shared_ptr<Notification<notifyData...>> aNotification, | ||
callableTy aCallable = nullptr) | ||
: mNotification(aNotification), | ||
mHandlerId(aNotification->onNotify(aCallable)) {} | ||
|
||
virtual ~Handler() { | ||
if (mHandlerId >= 0) { | ||
mNotification->unregister(mHandlerId); | ||
} | ||
} | ||
|
||
void operator=(callableTy aHandler) { | ||
if (mHandlerId >= 0) { | ||
mNotification->unregister(mHandlerId); | ||
mHandlerId = -1; | ||
} | ||
} | ||
if (aHandler) { | ||
mHandlerId = mNotification->onNotify(aHandler); | ||
} | ||
} | ||
|
||
void | ||
SetNotification(std::shared_ptr<Notification<notifyData...>> aNotification) { | ||
mNotification = aNotification; | ||
} | ||
|
||
private: | ||
std::shared_ptr<Notification<notifyData...>> mNotification = nullptr; | ||
int mHandlerId = -1; | ||
}; |
Oops, something went wrong.