-
Notifications
You must be signed in to change notification settings - Fork 3
/
notebook_adapter.cpp
47 lines (36 loc) · 972 Bytes
/
notebook_adapter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#define COMMAND_QUERY '?'
#define COMMAND_FAST 'V'
#define COMMAND_TRANSMIT 'U'
#define COMMAND_QUERY_PAYLOAD "107\r M764 rev 764100"
#define DATA_MODE_TIMEOUT_MS 1000
#include <Arduino.h>
#include "led_blaster.h"
#include "notebook_adapter.h"
namespace NotebookAdapter {
unsigned long last_data_ms = 0;
bool command_mode = true;
void emulate(uint8_t serial_byte) {
if (millis() - last_data_ms > DATA_MODE_TIMEOUT_MS) {
LedBlaster::enable_fast_mode(false);
command_mode = true;
}
Serial.write(serial_byte);
switch(serial_byte) {
case COMMAND_QUERY:
if (command_mode) {
Serial.print(COMMAND_QUERY_PAYLOAD);
Serial.write((byte)0);
}
break;
case COMMAND_FAST:
if (command_mode) {
LedBlaster::enable_fast_mode(true);
}
break;
case COMMAND_TRANSMIT:
command_mode = false;
break;
}
last_data_ms = millis();
}
}