working on getting outputs correct for ECG
This commit is contained in:
parent
5ae3ffcc8a
commit
1add30252c
2 changed files with 207 additions and 185 deletions
File diff suppressed because one or more lines are too long
32
src/main.cpp
32
src/main.cpp
|
|
@ -1,15 +1,19 @@
|
||||||
|
#include "esp32-hal-gpio.h"
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SerialCmd.h>
|
#include <SerialCmd.h>
|
||||||
#include <cstdint>
|
|
||||||
#include <screen.h>
|
#include <screen.h>
|
||||||
|
|
||||||
#define BAUD 115200
|
#define BAUD 115200
|
||||||
|
|
||||||
|
#define ECG_PIN 3
|
||||||
|
|
||||||
SerialCmd cmd(Serial);
|
SerialCmd cmd(Serial);
|
||||||
|
|
||||||
unsigned long lastStatus = 0;
|
unsigned long lastStatus = 0;
|
||||||
|
|
||||||
|
bool read_ecg = false;
|
||||||
|
|
||||||
void register_commands() {
|
void register_commands() {
|
||||||
cmd.on("/ping", "— responds with pong",
|
cmd.on("/ping", "— responds with pong",
|
||||||
[](CmdArgs &args) { Serial.println("pong"); });
|
[](CmdArgs &args) { Serial.println("pong"); });
|
||||||
|
|
@ -25,11 +29,25 @@ void register_commands() {
|
||||||
|
|
||||||
cmd.on("/status", "— print device status", [](CmdArgs &args) {
|
cmd.on("/status", "— print device status", [](CmdArgs &args) {
|
||||||
Serial.printf("uptime: %lus\n", millis() / 1000);
|
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",
|
cmd.on("/scanI2C", "-scans for any recognizable I2C devices",
|
||||||
[](CmdArgs &args) { Screen::wire_search(3); });
|
[](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(
|
cmd.onDefault(
|
||||||
[](CmdArgs &args) { Serial.printf("unknown: %s\n", args.command()); });
|
[](CmdArgs &args) { Serial.printf("unknown: %s\n", args.command()); });
|
||||||
|
|
||||||
|
|
@ -47,16 +65,20 @@ void setup() {
|
||||||
delay(10000);
|
delay(10000);
|
||||||
Serial.println("Delay Complete");
|
Serial.println("Delay Complete");
|
||||||
|
|
||||||
Screen::setup_screen();
|
|
||||||
|
|
||||||
Screen::test_fillrect();
|
|
||||||
|
|
||||||
register_commands();
|
register_commands();
|
||||||
|
pinMode(ECG_PIN, INPUT);
|
||||||
|
analogSetPinAttenuation(ECG_PIN, ADC_11db);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
cmd.poll();
|
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
|
// Periodic status to prove non-blocking
|
||||||
if (millis() - lastStatus >= 10000) {
|
if (millis() - lastStatus >= 10000) {
|
||||||
lastStatus = millis();
|
lastStatus = millis();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue