From a8a47d0567aa1d64ed07566f7ada57ce44335ec9 Mon Sep 17 00:00:00 2001 From: "Tianhao (Terry) Fu" Date: Thu, 26 Sep 2024 16:50:13 -0400 Subject: [PATCH] Implement the G Force Recording System (#7) * Removed `pulseTriggered()` and added `returnString()`. (#87) * Renamed `OnUpdate` to avoid duplication. (#87) * Renamed `OnUpdate` to avoid duplication. (#87) --- keywords.txt | 3 ++- src/Utils.cpp | 2 +- src/Utils.h | 2 +- src/WheelSpeedSensor.cpp | 4 ++-- src/WheelSpeedSensor.h | 6 +++--- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/keywords.txt b/keywords.txt index ad81796..3a5a316 100644 --- a/keywords.txt +++ b/keywords.txt @@ -2,9 +2,10 @@ ArrayList KEYWORD1 Controller KEYWORD1 Device KEYWORD1 VoltageSensor KEYWORD1 +OnWheelSpeedSensorUpdate KEYWORD1 WheelSpeedSensor KEYWORD1 Peer KEYWORD1 -pulseTriggered KEYWORD2 +returnString KEYWORD2 returnFloat KEYWORD2 returnDouble KEYWORD2 arraycopy KEYWORD2 diff --git a/src/Utils.cpp b/src/Utils.cpp index 63a47f3..d972b63 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -1,6 +1,6 @@ #include "Utils.h" -bool pulseTriggered(int pin) { return digitalRead(pin) == LOW; } +void returnString(Peer &peer, const String &tag, const String &msg) { peer.write(tag + ":" + msg); } void returnFloat(Peer &peer, const String &tag, float n) { peer.write(tag + ":" + n); } diff --git a/src/Utils.h b/src/Utils.h index a657d2a..11cff44 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -5,7 +5,7 @@ #include "Arduino.h" #include "Peer.h" -bool pulseTriggered(int pin); +void returnString(Peer &peer, const String &tag, const String &msg); void returnFloat(Peer &peer, const String &tag, float n); diff --git a/src/WheelSpeedSensor.cpp b/src/WheelSpeedSensor.cpp index 1c1cd4f..3d269dc 100644 --- a/src/WheelSpeedSensor.cpp +++ b/src/WheelSpeedSensor.cpp @@ -1,7 +1,7 @@ #include "WheelSpeedSensor.h" #include "Utils.h" -WheelSpeedSensor::WheelSpeedSensor(const ArrayList &pins, OnUpdate onUpdate) : +WheelSpeedSensor::WheelSpeedSensor(const ArrayList &pins, OnWheelSpeedSensorUpdate onUpdate) : Device(pins), _t1(0), _t2(0), _consecutive(false), _onUpdate(onUpdate) {} void WheelSpeedSensor::initialize(const ArrayList &parentTags) { @@ -15,7 +15,7 @@ void WheelSpeedSensor::initialize(const ArrayList &parentTags) { float getRPM(unsigned long t1, unsigned long t2) { return float(60000.0 / double(t2 - t1)); } float WheelSpeedSensor::read() { - if (pulseTriggered(_pins[0])) { + if (digitalRead(_pins[0]) == LOW) { if (!_consecutive) { _consecutive = true; _t1 = _t2; diff --git a/src/WheelSpeedSensor.h b/src/WheelSpeedSensor.h index d9d034d..b30d28e 100644 --- a/src/WheelSpeedSensor.h +++ b/src/WheelSpeedSensor.h @@ -4,16 +4,16 @@ #include "Device.h" -typedef void (*OnUpdate)(float ws); +typedef void (*OnWheelSpeedSensorUpdate)(float ws); class WheelSpeedSensor : public Device { protected: unsigned long _t1, _t2; bool _consecutive; - const OnUpdate _onUpdate; + const OnWheelSpeedSensorUpdate _onUpdate; public: - WheelSpeedSensor(const ArrayList &pins, OnUpdate onUpdate); + WheelSpeedSensor(const ArrayList &pins, OnWheelSpeedSensorUpdate onUpdate); void initialize(const ArrayList &parentTags) override; float read() override; };