Converted tfmini custom component into an external component

This commit is contained in:
John Dillenburg
2025-03-01 13:14:31 -06:00
parent abfc6939dd
commit 177179d8a4
11 changed files with 416 additions and 178 deletions

View File

@@ -7,6 +7,7 @@ class ADXL345Sensor : public PollingComponent {
public:
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
Sensor *off_vertical = new Sensor();
Sensor *jitter = new Sensor();
ADXL345Sensor() : PollingComponent(100) { }
@@ -23,8 +24,16 @@ class ADXL345Sensor : public PollingComponent {
void update() override {
sensors_event_t event;
accel.getEvent(&event);
double pitch_amount = atan(event.acceleration.y / sqrt(pow(event.acceleration.x, 2) + pow(event.acceleration.z, 2))) * 180 / PI;
double roll_amount = atan(-1 * event.acceleration.x / sqrt(pow(event.acceleration.y, 2) + pow(event.acceleration.z, 2))) * 180 / PI;
off_vertical->publish_state(max(abs(pitch_amount), abs(roll_amount)));
double pitch_amount = atan(event.acceleration.y /
sqrt(pow(event.acceleration.x, 2) + pow(event.acceleration.z, 2))) * 180 / PI;
double roll_amount = atan(-1 * event.acceleration.x /
sqrt(pow(event.acceleration.y, 2) + pow(event.acceleration.z, 2))) * 180 / PI;
// double pitch_amount = atan2(event.acceleration.y,
// sqrt(pow(event.acceleration.x, 2) + pow(event.acceleration.z, 2))) * 180 / PI;
// double roll_amount = atan2(-1 * event.acceleration.x,
// sqrt(pow(event.acceleration.y, 2) + pow(event.acceleration.z, 2))) * 180 / PI;
off_vertical -> publish_state(max(abs(pitch_amount), abs(roll_amount)));
jitter -> publish_state(abs(event.acceleration.x) + abs(event.acceleration.y) +
abs(event.acceleration.z));
}
};