working on getting outputs correct for ECG

This commit is contained in:
David Fitzsimmons 2026-03-02 23:01:30 -05:00
parent 5ae3ffcc8a
commit 1add30252c
2 changed files with 207 additions and 185 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,15 +1,19 @@
#include "esp32-hal-gpio.h"
#include <Adafruit_GFX.h>
#include <Arduino.h>
#include <SerialCmd.h>
#include <cstdint>
#include <screen.h>
#define BAUD 115200
#define ECG_PIN 3
SerialCmd cmd(Serial);
unsigned long lastStatus = 0;
bool read_ecg = false;
void register_commands() {
cmd.on("/ping", "— responds with pong",
[](CmdArgs &args) { Serial.println("pong"); });
@ -25,11 +29,25 @@ void register_commands() {
cmd.on("/status", "— print device status", [](CmdArgs &args) {
Serial.printf("uptime: %lus\n", millis() / 1000);
if (read_ecg) {
Serial.println("ECG reading enabled");
} else {
Serial.println("ECG reading disabled");
}
});
cmd.on("/scanI2C", "-scans for any recognizable I2C devices",
[](CmdArgs &args) { Screen::wire_search(3); });
cmd.on("/ECG", "-turns on | off ECG serial output", [](CmdArgs &args) {
read_ecg = !read_ecg;
if (read_ecg) {
Serial.println("ECG reading enabled");
} else {
Serial.println("ECG reading disabled");
}
});
cmd.onDefault(
[](CmdArgs &args) { Serial.printf("unknown: %s\n", args.command()); });
@ -47,16 +65,20 @@ void setup() {
delay(10000);
Serial.println("Delay Complete");
Screen::setup_screen();
Screen::test_fillrect();
register_commands();
pinMode(ECG_PIN, INPUT);
analogSetPinAttenuation(ECG_PIN, ADC_11db);
}
void loop() {
cmd.poll();
if (read_ecg) {
float ecg_val = analogRead(ECG_PIN);
Serial.printf("#graphf %f\n", ecg_val);
delay(5);
}
// Periodic status to prove non-blocking
if (millis() - lastStatus >= 10000) {
lastStatus = millis();