-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (65 loc) · 1.63 KB
/
main.cpp
File metadata and controls
80 lines (65 loc) · 1.63 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <Arduino.h>
#include <NimBLEDevice.h>
#include "./bleretro32/bleretro32.h"
#include "./xbox.h"
#include "./esp32-arcade.h"
pad_definition_t pad_list[] = {
{"Xbox Wireless Controller", xbox_to_retro},
{"ESP32 Arcade", esp32_arcade_to_retro}};
#define PIN_STATUS_LED 7 // 2 is board led
#define STATUS_LED_FAST_TIME 200
#define STATUS_LED_SLOW_TIME 1200
bool GetLedStatus(CnnStatus cnn_status)
{
static long last = 0;
long on_time;
long off_time;
switch (cnn_status)
{
case CnnStatus::Scanning:
on_time = STATUS_LED_FAST_TIME;
off_time = STATUS_LED_FAST_TIME;
break;
case CnnStatus::DeviceFound:
case CnnStatus::Connecting:
on_time = STATUS_LED_SLOW_TIME;
off_time = STATUS_LED_FAST_TIME;
break;
case CnnStatus::Connected:
on_time = STATUS_LED_FAST_TIME;
off_time = STATUS_LED_SLOW_TIME;
break;
default:
on_time = STATUS_LED_SLOW_TIME;
off_time = STATUS_LED_FAST_TIME;
break;
}
auto act_time = millis();
if (act_time < (last + on_time))
{
return true;
}
else if (act_time < (last + on_time + off_time))
{
return false;
}
else
{
last = act_time;
return true;
}
}
#define LOOP_DELAY 5
void setup()
{
Serial.begin(115200);
Serial.printf("Starting BLERetro32\n");
pinMode(PIN_STATUS_LED, OUTPUT);
BLERetro32_Setup(pad_list, sizeof(pad_list) / sizeof(pad_definition_t));
}
void loop()
{
auto cnn_status = BLERetro32_Loop();
digitalWrite(PIN_STATUS_LED, GetLedStatus(cnn_status));
delay(LOOP_DELAY);
}