BLEUart bleuart;
+void handlePacket(void);
+
void app_error_handler_bare([[maybe_unused]] uint32_t error_code)
{
Serial.println("Received an error");
void loop(void)
{
if (bleuart.available())
- Serial.print((char)bleuart.read());
+ handlePacket();
delay(10);
}
+
+void handlePacket(void)
+{
+ char buf[64];
+ char *p = buf;
+ do {
+ *p++ = bleuart.read();
+ } while (bleuart.available());
+ *p = '\0';
+
+ switch (buf[0]) {
+ case 'L':
+ Sharp::setMessage(buf + 1);
+ break;
+ case 'T':
+ Serial.println("Setting time!");
+ RTC::setTicks(std::atoi(buf + 1) * 60);
+ break;
+ default:
+ break;
+ }
+}
+
Adafruit_SharpMem Sharp::display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
TaskHandle_t Sharp::taskHandle;
bool Sharp::holdRendering = false;
+char Sharp::message[16] = "";
#define BLACK 0
#define WHITE 1
if (auto t = RTC::ticks(); t != old) {
old = t;
- display.setCursor(0, 60);
- display.printf("%2d:%02d", t / 60, t % 60);
+ display.setCursor(0, 10);
+ display.printf("%2d:%02d:%02d", t / 3600, (t % 3600) /
+ 60, t % 60);
+ if (*message != '\0') {
+ display.setCursor(0, 100);
+ display.printf("%-16s", message);
+ }
display.refresh();
}
}
static Adafruit_SharpMem display;
static TaskHandle_t taskHandle;
static bool holdRendering;
+ static char message[16];
public:
static void begin(void);
holdRendering = false;
}
+ inline static void setMessage(const char *s) {
+ strncpy(message, s, 16);
+ }
+
private:
static void updateTask(void *);
};
return rtcCount;
}
+ inline static void setTicks(unsigned int t) {
+ rtcCount = t;
+ }
+
private:
static void handler(nrf_drv_rtc_int_type_t type);
};