-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFirmataConnection.h
53 lines (48 loc) · 1.13 KB
/
FirmataConnection.h
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
48
49
50
51
52
#pragma once
#include <ArduinoJson.h>
#include <Firmata.h>
class FirmataConnection
{
public:
static void begin()
{
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION);
Firmata.attach(START_SYSEX, SystemExtensionRequestCallback);
Firmata.begin(9600);
}
static void ProcessData()
{
while (Firmata.available())
{
Firmata.processInput();
}
}
static void SendResultToHost(JsonObject & ResultantObject)
{
char Buffer[256];
ResultantObject.printTo(Buffer, sizeof(Buffer));
for (int i = 0; i != 5; ++i)
Firmata.sendString(Buffer);
}
private:
static void SystemExtensionRequestCallback(uint8_t Command, uint8_t ArgumentCount /* argc */ , uint8_t * ArgumentVector /* argv */)
{
switch (Command)
{
case CAPABILITY_QUERY:
{
Firmata.write(START_SYSEX);
Firmata.write(CAPABILITY_RESPONSE);
// No capabilities, innit.
Firmata.write(127);
Firmata.write(END_SYSEX);
break;
}
default:
{
Firmata.sendString("Unsupported command.");
break;
}
}
}
};