Skip to content

Commit

Permalink
Implement the G Force Recording System (#7)
Browse files Browse the repository at this point in the history
* Removed `pulseTriggered()` and added `returnString()`. (#87)

* Renamed `OnUpdate` to avoid duplication. (#87)

* Renamed `OnUpdate` to avoid duplication. (#87)
  • Loading branch information
ATATC authored Sep 26, 2024
1 parent 44721c6 commit a8a47d0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.cpp
Original file line number Diff line number Diff line change
@@ -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); }

Expand Down
2 changes: 1 addition & 1 deletion src/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/WheelSpeedSensor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "WheelSpeedSensor.h"
#include "Utils.h"

WheelSpeedSensor::WheelSpeedSensor(const ArrayList<int> &pins, OnUpdate onUpdate) :
WheelSpeedSensor::WheelSpeedSensor(const ArrayList<int> &pins, OnWheelSpeedSensorUpdate onUpdate) :
Device<float>(pins), _t1(0), _t2(0), _consecutive(false), _onUpdate(onUpdate) {}

void WheelSpeedSensor::initialize(const ArrayList<String> &parentTags) {
Expand All @@ -15,7 +15,7 @@ void WheelSpeedSensor::initialize(const ArrayList<String> &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;
Expand Down
6 changes: 3 additions & 3 deletions src/WheelSpeedSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

#include "Device.h"

typedef void (*OnUpdate)(float ws);
typedef void (*OnWheelSpeedSensorUpdate)(float ws);

class WheelSpeedSensor : public Device<float> {
protected:
unsigned long _t1, _t2;
bool _consecutive;
const OnUpdate _onUpdate;
const OnWheelSpeedSensorUpdate _onUpdate;

public:
WheelSpeedSensor(const ArrayList<int> &pins, OnUpdate onUpdate);
WheelSpeedSensor(const ArrayList<int> &pins, OnWheelSpeedSensorUpdate onUpdate);
void initialize(const ArrayList<String> &parentTags) override;
float read() override;
};
Expand Down

0 comments on commit a8a47d0

Please sign in to comment.