arduino-blume/teng/status.hpp

44 lines
1.2 KiB
C++
Raw Normal View History

2023-06-14 19:22:11 +02:00
#pragma once
#include <Arduino.h>
2023-06-24 02:59:22 +02:00
2023-06-14 19:22:11 +02:00
#include "settings.hpp"
#include "services.hpp"
// needs to be in separate file because sketch preprocessor reorders stuff
2023-06-24 02:59:22 +02:00
enum DeviceStatus : byte { ERROR = 0, BUSY, WAIT_CONNECT, CONNECTED, MEASURING };
2023-06-14 19:22:11 +02:00
void setStatusLED(DeviceStatus s, bool value) {
switch (s) {
case ERROR:
digitalWrite(LED_RED, value);
break;
case BUSY:
digitalWrite(LED_YELLOW, value);
2023-06-24 02:59:22 +02:00
digitalWrite(LED_RED, value);
2023-06-14 19:22:11 +02:00
break;
case WAIT_CONNECT:
digitalWrite(LED_YELLOW, value);
2023-06-24 02:59:22 +02:00
break;
case CONNECTED:
2023-06-14 19:22:11 +02:00
digitalWrite(LED_GREEN, value);
break;
2023-06-24 02:59:22 +02:00
/* case MEASURING_BASELINE: */
/* digitalWrite(LED_RED, value); */
/* digitalWrite(LED_GREEN, value); */
/* break; */
case MEASURING:
2023-06-14 19:22:11 +02:00
digitalWrite(LED_YELLOW, value);
digitalWrite(LED_GREEN, value);
break;
}
}
2023-06-24 02:59:22 +02:00
2023-06-14 19:22:11 +02:00
DeviceStatus deviceStatus = WAIT_CONNECT;
void setStatus(DeviceStatus s) {
setStatusLED(deviceStatus, LOW);
setStatusLED(s, HIGH);
deviceStatus = s;
tengStatus.writeValue(deviceStatus);
}