2023-07-31 14:28:10 -04:00
|
|
|
#pragma once
|
|
|
|
#include "SparkFunLIS3DH.h"
|
|
|
|
|
2023-09-14 00:34:04 -04:00
|
|
|
#include "HardwareAbstract.hpp"
|
|
|
|
#include "battery.hpp"
|
2023-10-22 14:35:49 -04:00
|
|
|
#include "lvgl.h"
|
|
|
|
#include "wifihandler.hpp"
|
|
|
|
#include <Arduino.h>
|
2023-07-31 14:28:10 -04:00
|
|
|
#include <IRrecv.h>
|
|
|
|
#include <IRremoteESP8266.h>
|
|
|
|
#include <IRsend.h>
|
|
|
|
#include <IRutils.h>
|
|
|
|
#include <Preferences.h>
|
2023-08-11 18:16:48 -04:00
|
|
|
#include <PubSubClient.h>
|
2023-07-31 14:28:10 -04:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2023-08-11 18:16:48 -04:00
|
|
|
|
2023-07-31 14:28:10 -04:00
|
|
|
#include "omoteconfig.h"
|
2023-10-22 14:35:49 -04:00
|
|
|
|
2023-09-14 00:34:04 -04:00
|
|
|
#include "BatteryInterface.h"
|
|
|
|
#include "display.hpp"
|
2023-10-22 14:35:49 -04:00
|
|
|
#include "keys.hpp"
|
|
|
|
#include "wifiHandlerInterface.h"
|
2023-07-31 14:28:10 -04:00
|
|
|
|
2023-09-14 00:34:04 -04:00
|
|
|
class HardwareRevX : public HardwareAbstract {
|
2023-07-31 14:28:10 -04:00
|
|
|
public:
|
|
|
|
enum class WakeReason { RESET, IMU, KEYPAD };
|
|
|
|
|
2023-10-22 14:35:49 -04:00
|
|
|
HardwareRevX();
|
2023-07-31 14:28:10 -04:00
|
|
|
|
2023-09-14 00:34:04 -04:00
|
|
|
// HardwareAbstract
|
2023-07-31 14:28:10 -04:00
|
|
|
virtual void init() override;
|
2023-10-22 14:35:49 -04:00
|
|
|
virtual void debugPrint(const char *fmt, ...) override;
|
2023-09-14 00:34:04 -04:00
|
|
|
|
|
|
|
virtual std::shared_ptr<BatteryInterface> battery() override;
|
|
|
|
virtual std::shared_ptr<DisplayAbstract> display() override;
|
|
|
|
virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
|
2023-10-22 14:35:49 -04:00
|
|
|
virtual std::shared_ptr<KeyPressAbstract> keys() override;
|
2023-09-17 06:14:39 -04:00
|
|
|
|
|
|
|
virtual char getCurrentDevice() override;
|
|
|
|
virtual void setCurrentDevice(char currentDevice) override;
|
2023-10-22 14:35:49 -04:00
|
|
|
|
2023-09-17 06:14:39 -04:00
|
|
|
virtual bool getWakeupByIMUEnabled() override;
|
|
|
|
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) override;
|
|
|
|
|
|
|
|
virtual uint16_t getSleepTimeout() override;
|
|
|
|
virtual void setSleepTimeout(uint16_t sleepTimeout) override;
|
|
|
|
|
2023-09-14 00:34:04 -04:00
|
|
|
/// @brief To be ran in loop out in main
|
|
|
|
// TODO move to a freertos task
|
2023-10-22 14:35:49 -04:00
|
|
|
void loopHandler() override;
|
|
|
|
|
2023-07-31 14:28:10 -04:00
|
|
|
protected:
|
|
|
|
// Init Functions to setup hardware
|
|
|
|
void initIO();
|
|
|
|
void restorePreferences();
|
|
|
|
void slowDisplayWakeup();
|
|
|
|
void setupIMU();
|
|
|
|
void setupIR();
|
|
|
|
|
|
|
|
void activityDetection();
|
|
|
|
void enterSleep();
|
|
|
|
void configIMUInterrupts();
|
|
|
|
|
|
|
|
// Tasks
|
|
|
|
void startTasks();
|
|
|
|
|
|
|
|
private:
|
2023-09-14 00:34:04 -04:00
|
|
|
std::shared_ptr<Battery> mBattery;
|
|
|
|
std::shared_ptr<Display> mDisplay;
|
|
|
|
std::shared_ptr<wifiHandler> mWifiHandler;
|
2023-10-22 14:35:49 -04:00
|
|
|
std::shared_ptr<Keys> mKeys;
|
2023-07-31 14:28:10 -04:00
|
|
|
// IMU Motion Detection
|
|
|
|
LIS3DH IMU = LIS3DH(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
|
|
|
|
int standbyTimer = SLEEP_TIMEOUT;
|
2023-09-17 06:14:39 -04:00
|
|
|
int sleepTimeout = SLEEP_TIMEOUT;
|
2023-07-31 14:28:10 -04:00
|
|
|
int motion = 0;
|
|
|
|
WakeReason wakeup_reason;
|
|
|
|
|
|
|
|
Preferences preferences;
|
|
|
|
bool wakeupByIMUEnabled = true;
|
|
|
|
byte currentDevice = 1; // Current Device to control (allows switching
|
|
|
|
// mappings between devices)
|
|
|
|
|
|
|
|
// IR declarations
|
|
|
|
IRsend IrSender = IRsend(IR_LED, true);
|
|
|
|
IRrecv IrReceiver = IRrecv(IR_RX);
|
|
|
|
|
|
|
|
static std::shared_ptr<HardwareRevX> mInstance;
|
2023-10-22 14:35:49 -04:00
|
|
|
Handler<TS_Point> mTouchHandler;
|
2023-07-31 14:28:10 -04:00
|
|
|
};
|