Rename Boards/ to Devices/ (#414)
This commit is contained in:
committed by
GitHub
parent
c7c9618f48
commit
c1ff024657
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "SdlTouch.h"
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
/** Hack: variable comes from LvglTask.cpp */
|
||||
extern lv_disp_t* displayHandle;
|
||||
|
||||
class SdlDisplay final : public tt::hal::display::DisplayDevice {
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const override { return "SDL Display"; }
|
||||
std::string getDescription() const override { return ""; }
|
||||
|
||||
bool start() override { return true; }
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
|
||||
bool supportsLvgl() const override { return true; }
|
||||
bool startLvgl() override { return displayHandle != nullptr; }
|
||||
bool stopLvgl() override { tt_crash("Not supported"); }
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return std::make_shared<SdlTouch>(); }
|
||||
|
||||
bool supportsDisplayDriver() const override { return false; }
|
||||
std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable getDisplayDriver() override { return nullptr; }
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/keyboard/KeyboardDevice.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
class SdlKeyboard final : public tt::hal::keyboard::KeyboardDevice {
|
||||
|
||||
lv_indev_t* _Nullable handle = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const override { return "SDL Keyboard"; }
|
||||
std::string getDescription() const override { return "SDL keyboard device"; }
|
||||
|
||||
bool startLvgl(lv_display_t* display) override {
|
||||
handle = lv_sdl_keyboard_create();
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
bool stopLvgl() override { tt_crash("Not supported"); }
|
||||
|
||||
bool isAttached() const override { return true; }
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return handle; }
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/touch/TouchDevice.h"
|
||||
#include <Tactility/TactilityCore.h>
|
||||
|
||||
class SdlTouch final : public tt::hal::touch::TouchDevice {
|
||||
|
||||
lv_indev_t* _Nullable handle = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
std::string getName() const override { return "SDL Mouse"; }
|
||||
|
||||
std::string getDescription() const override { return "SDL mouse/touch pointer device"; }
|
||||
|
||||
bool start() override { return true; }
|
||||
|
||||
bool stop() override { tt_crash("Not supported"); }
|
||||
|
||||
bool supportsLvgl() const override { return true; }
|
||||
|
||||
bool startLvgl(lv_display_t* display) override {
|
||||
handle = lv_sdl_mouse_create();
|
||||
return handle != nullptr;
|
||||
}
|
||||
|
||||
bool stopLvgl() override { tt_crash("Not supported"); }
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return handle; }
|
||||
|
||||
bool supportsTouchDriver() override { return false; }
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDriver> _Nullable getTouchDriver() override { return nullptr; };
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "SimulatorPower.h"
|
||||
|
||||
constexpr auto* TAG = "SimulatorPower";
|
||||
|
||||
bool SimulatorPower::supportsMetric(MetricType type) const {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case IsCharging:
|
||||
case Current:
|
||||
case BatteryVoltage:
|
||||
case ChargeLevel:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // Safety guard for when new enum values are introduced
|
||||
}
|
||||
|
||||
bool SimulatorPower::getMetric(MetricType type, MetricData& data) {
|
||||
switch (type) {
|
||||
using enum MetricType;
|
||||
case IsCharging:
|
||||
data.valueAsBool = true;
|
||||
return true;
|
||||
case Current:
|
||||
data.valueAsInt32 = 42;
|
||||
return true;
|
||||
case BatteryVoltage:
|
||||
data.valueAsUint32 = 4032;
|
||||
return true;
|
||||
case ChargeLevel:
|
||||
data.valueAsUint8 = 100;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // Safety guard for when new enum values are introduced
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
#include <memory>
|
||||
|
||||
using tt::hal::power::PowerDevice;
|
||||
|
||||
class SimulatorPower final : public PowerDevice {
|
||||
|
||||
bool allowedToCharge = false;
|
||||
|
||||
public:
|
||||
|
||||
SimulatorPower() = default;
|
||||
~SimulatorPower() override = default;
|
||||
|
||||
std::string getName() const override { return "Power Mock"; }
|
||||
std::string getDescription() const override { return ""; }
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
bool supportsChargeControl() const override { return true; }
|
||||
bool isAllowedToCharge() const override { return allowedToCharge; }
|
||||
void setAllowedToCharge(bool canCharge) override { allowedToCharge = canCharge; }
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <memory>
|
||||
|
||||
using tt::hal::sdcard::SdCardDevice;
|
||||
|
||||
class SimulatorSdCard final : public SdCardDevice {
|
||||
|
||||
State state;
|
||||
std::shared_ptr<tt::Lock> lock;
|
||||
std::string mountPath;
|
||||
|
||||
public:
|
||||
|
||||
SimulatorSdCard() : SdCardDevice(MountBehaviour::AtBoot),
|
||||
state(State::Unmounted),
|
||||
lock(std::make_shared<tt::Mutex>(tt::Mutex::Type::Recursive))
|
||||
{}
|
||||
|
||||
std::string getName() const override { return "Mock SD Card"; }
|
||||
std::string getDescription() const override { return ""; }
|
||||
|
||||
bool mount(const std::string& newMountPath) override {
|
||||
state = State::Mounted;
|
||||
mountPath = newMountPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unmount() override {
|
||||
state = State::Unmounted;
|
||||
mountPath = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string getMountPath() const override { return mountPath; }
|
||||
|
||||
std::shared_ptr<tt::Lock> getLock() const override { return lock; }
|
||||
|
||||
State getState(TickType_t timeout) const override { return state; }
|
||||
};
|
||||
Reference in New Issue
Block a user