summaryrefslogtreecommitdiff
path: root/src/system_fsm
diff options
context:
space:
mode:
authorRobin Howard <robin@rhoward.id.au>2023-11-07 15:46:07 +1100
committerRobin Howard <robin@rhoward.id.au>2023-11-07 16:31:55 +1100
commit135185f12ba07dea8568b06c0a65a00a8af7deb7 (patch)
tree19724b4caf02c6127766be4e9bfd33d006cfdd25 /src/system_fsm
parent3abf599c4f8b04bed4ed67084588204f65a644d0 (diff)
downloadtangara-fw-135185f12ba07dea8568b06c0a65a00a8af7deb7.tar.gz
haptics: adds a wrapper for the DRV2605L haptic motor driver
... with facilities to trigger effects via the system fsm.
Diffstat (limited to 'src/system_fsm')
-rw-r--r--src/system_fsm/booting.cpp3
-rw-r--r--src/system_fsm/include/service_locator.hpp10
-rw-r--r--src/system_fsm/include/system_events.hpp5
-rw-r--r--src/system_fsm/include/system_fsm.hpp2
-rw-r--r--src/system_fsm/system_fsm.cpp5
5 files changed, 25 insertions, 0 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp
index 940e10db..affd3ebc 100644
--- a/src/system_fsm/booting.cpp
+++ b/src/system_fsm/booting.cpp
@@ -5,9 +5,11 @@
*/
#include "collation.hpp"
+#include "haptics.hpp"
#include "system_fsm.hpp"
#include <stdint.h>
+#include <memory>
#include "assert.h"
#include "esp_err.h"
@@ -75,6 +77,7 @@ auto Booting::entry() -> void {
std::unique_ptr<drivers::NvsStorage>(drivers::NvsStorage::OpenSync()));
sServices->touchwheel(
std::unique_ptr<drivers::TouchWheel>{drivers::TouchWheel::Create()});
+ sServices->haptics(std::make_unique<drivers::Haptics>());
auto adc = drivers::AdcBattery::Create();
sServices->battery(std::make_unique<battery::Battery>(
diff --git a/src/system_fsm/include/service_locator.hpp b/src/system_fsm/include/service_locator.hpp
index 327d0c50..4aa57df0 100644
--- a/src/system_fsm/include/service_locator.hpp
+++ b/src/system_fsm/include/service_locator.hpp
@@ -13,6 +13,7 @@
#include "collation.hpp"
#include "database.hpp"
#include "gpios.hpp"
+#include "haptics.hpp"
#include "nvs.hpp"
#include "samd.hpp"
#include "storage.hpp"
@@ -79,6 +80,14 @@ class ServiceLocator {
touchwheel_ = std::move(i);
}
+ auto haptics() -> drivers::Haptics& {
+ return *haptics_;
+ }
+
+ auto haptics(std::unique_ptr<drivers::Haptics> i) {
+ haptics_ = std::move(i);
+ }
+
auto database() -> std::weak_ptr<database::Database> { return database_; }
auto database(std::unique_ptr<database::Database> i) {
@@ -130,6 +139,7 @@ class ServiceLocator {
std::unique_ptr<drivers::Samd> samd_;
std::unique_ptr<drivers::NvsStorage> nvs_;
std::unique_ptr<drivers::TouchWheel> touchwheel_;
+ std::unique_ptr<drivers::Haptics> haptics_;
std::unique_ptr<drivers::Bluetooth> bluetooth_;
std::unique_ptr<audio::TrackQueue> queue_;
diff --git a/src/system_fsm/include/system_events.hpp b/src/system_fsm/include/system_events.hpp
index 4db9beb0..2722fa80 100644
--- a/src/system_fsm/include/system_events.hpp
+++ b/src/system_fsm/include/system_events.hpp
@@ -10,6 +10,7 @@
#include "battery.hpp"
#include "database.hpp"
+#include "haptics.hpp"
#include "service_locator.hpp"
#include "tinyfsm.hpp"
@@ -55,6 +56,10 @@ struct BatteryStateChanged : tinyfsm::Event {
struct BluetoothDevicesChanged : tinyfsm::Event {};
+struct HapticTrigger : tinyfsm::Event {
+ drivers::Haptics::Effect effect;
+};
+
namespace internal {
struct GpioInterrupt : tinyfsm::Event {};
diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp
index 28448e5a..c9803bef 100644
--- a/src/system_fsm/include/system_fsm.hpp
+++ b/src/system_fsm/include/system_fsm.hpp
@@ -50,6 +50,8 @@ class SystemState : public tinyfsm::Fsm<SystemState> {
void react(const internal::GpioInterrupt&);
void react(const internal::SamdInterrupt&);
+ void react(const HapticTrigger&);
+
virtual void react(const DisplayReady&) {}
virtual void react(const BootComplete&) {}
virtual void react(const StorageMounted&) {}
diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp
index 1e92cd62..31aec789 100644
--- a/src/system_fsm/system_fsm.cpp
+++ b/src/system_fsm/system_fsm.cpp
@@ -29,6 +29,11 @@ void SystemState::react(const FatalError& err) {
}
}
+void SystemState::react(const HapticTrigger& trigger) {
+ auto& haptics = sServices->haptics();
+ haptics.PlayWaveformEffect(trigger.effect);
+}
+
void SystemState::react(const internal::GpioInterrupt&) {
auto& gpios = sServices->gpios();
bool prev_key_lock = gpios.Get(drivers::Gpios::Pin::kKeyLock);