Skip to content

Merge leads_vec_power/Pedal and leads_vec_wsc/Accelerometer into LEADS-Arduino #8

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 4 commits into from
Mar 7, 2025
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
4 changes: 4 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Device KEYWORD1
VoltageSensor KEYWORD1
OnWheelSpeedSensorUpdate KEYWORD1
WheelSpeedSensor KEYWORD1
Acceleration KEYWORD1
OnAccelerometerUpdate KEYWORD1
Accelerometer KEYWORD1
Pedal KEYWORD1
Peer KEYWORD1
returnString KEYWORD2
returnFloat KEYWORD2
Expand Down
10 changes: 10 additions & 0 deletions src/Accelerometer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Accelerometer.h"

String Acceleration::toString() {
return String(yaw) + "," + pitch + "," + roll + "," + forwardAcceleration + "," + lateralAcceleration + "," +
verticalAcceleration;
}

Accelerometer::Accelerometer(OnAccelerometerUpdate onUpdate) : _onUpdate(onUpdate) {}

void Accelerometer::initialize(const ArrayList<String> &parentTags) { Device<Acceleration>::initialize(parentTags); }
25 changes: 25 additions & 0 deletions src/Accelerometer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef ACCELEROMETER_H
#define ACCELEROMETER_H


#include "Device.h"

struct Acceleration {
float yaw = 0, pitch = 0, roll = 0;
float forwardAcceleration = 0, lateralAcceleration = 0, verticalAcceleration = 0;
String toString();
};

typedef void (*OnAccelerometerUpdate)(Acceleration acceleration);

class Accelerometer : public Device<Acceleration> {
protected:
const OnAccelerometerUpdate _onUpdate;

public:
explicit Accelerometer(OnAccelerometerUpdate onUpdate);
void initialize(const ArrayList<String> &parentTags) override;
};


#endif // ACCELEROMETER_H
2 changes: 2 additions & 0 deletions src/LEADS.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "Accelerometer.h"
#include "Controller.h"
#include "Device.h"
#include "Memory.h"
#include "Pedal.h"
#include "Peer.h"
#include "PredefinedTags.h"
#include "Utils.h"
Expand Down
11 changes: 11 additions & 0 deletions src/Pedal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Pedal.h"

Pedal::Pedal(const ArrayList<int> &pins, float restValue, float maxValue) :
Device<float>(pins), _restValue(restValue), _maxValue(maxValue) {}

void Pedal::initialize(const ArrayList<String> &parentTags) {
Device<float>::initialize(parentTags);
pinMode(_pins[0], INPUT);
}

float Pedal::read() { return ((float) analogRead(_pins[0]) / 1023 - _restValue) / _maxValue; }
18 changes: 18 additions & 0 deletions src/Pedal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef PEDAL_H
#define PEDAL_H


#include "Device.h"

class Pedal : public Device<float> {
protected:
float _restValue, _maxValue;

public:
Pedal(const ArrayList<int> &pins, float restValue, float maxValue);
void initialize(const ArrayList<String> &parentTags) override;
float read() override;
};


#endif // PEDAL_H