-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathReButtonApp.ino
95 lines (72 loc) · 1.74 KB
/
ReButtonApp.ino
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <Arduino.h>
#include "src/Common.h"
#include <ReButton.h>
#include "src/input/Input.h"
#include "src/action/Action.h"
#define LOOP_WAIT_TIME (10) // [msec.]
#define POWER_OFF_TIME (1000) // [msec.]
void setup()
{
////////////////////
// Setup auto shutdown
AutoShutdownBegin(CONFIG_AUTO_SHUTDOWN_TIMEOUT);
DisplayBegin();
////////////////////
// Read CONFIG
ConfigRead();
Serial.printf("Firmware version is %s.\n", CONFIG_FIRMWARE_VERSION);
Serial.println("Parameters:");
Serial.println("-----");
ConfigPrint();
Serial.println("-----");
if (ReButton::IsButtonPressed() && ReButton::IsJumperShort())
{
Serial.println("Force factory reset.");
ConfigResetFactorySettings();
ConfigWrite();
return;
}
////////////////////
// INPUT
InputBegin();
for (;;)
{
InputTask();
if (!InputIsCapturing()) break;
DisplayColor(InputToDisplayColor(InputGetCurrentValue()));
delay(LOOP_WAIT_TIME);
}
INPUT_TYPE input = InputGetConfirmValue();
Serial.printf("Button is %s.\n", InputGetInputString(input));
////////////////////
// FLASH
DisplayStartAction(InputToDisplayColor(input));
////////////////////
// ACTION
ACTION_TYPE action = InputToAction(input);
Serial.printf("Action is %s.\n", ActionGetActionString(action));
if (!ActionTaskBlocking(action)) return;
////////////////////
// FINISH
Serial.println("Finish.");
DisplayStartFinish(InputToDisplayColor(input));
delay(1500);
////////////////////
// Power off
ReButton::PowerSupplyEnable(false);
delay(POWER_OFF_TIME);
}
void loop()
{
////////////////////
// FINISH (Error)
for (int i = 0; i < 3; i++)
{
DisplayColor(DISPLAY_ERROR);
delay(200);
DisplayColor(DISPLAY_OFF);
delay(200);
}
ReButton::PowerSupplyEnable(false);
delay(POWER_OFF_TIME);
}