Skip to content

Implement the G Force Recording System #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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