-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.ino
114 lines (90 loc) · 2.76 KB
/
Controller.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//------------------------------------------------------------------
// Library includes
//------------------------------------------------------------------
#include <EncoderMenuSwitch.h>
#include <OpenSmart32.h>
#include <XpnManager.h>
#include "Menuino.h"
// PIN definicitons
#define BOARD_LED 13
#define ENCODER_PIN_A 25
#define ENCODER_PIN_B 27
#define ENCODER_PIN_SWITCH 29
#define XPN_PIN_TXRX 31
// Hardware declarations
OpenSmart32 display;
EncoderMenuSwitch encoder;
XpnManager* xpn;
// MENUino declaration
Menuino menuino;
//------------------------------------------------------------------
// Arduino main routines
//------------------------------------------------------------------
void setup()
{
// Shut down board LED
pinMode(BOARD_LED, OUTPUT);
digitalWrite(BOARD_LED, HIGH);
Serial.begin(115200);
display.Initialize();
encoder.Initialize(ENCODER_PIN_A, ENCODER_PIN_B, ENCODER_PIN_SWITCH);
xpn = XpnManager::getInstance();
xpn->Initialize(XPN_PIN_TXRX);
menuino.Initialize(&display);
}
void loop()
{
xpn->Dispatch();
display.Dispatch();
encoder.Dispatch();
}
//----------------------------------------------
// Display click callback
//----------------------------------------------
void OnDisplayClick(uint16_t xpos, uint16_t ypos)
{
menuino.HandleDisplayClick(xpos, ypos);
}
//----------------------------------------------
// Encoder movement callback
//----------------------------------------------
void OnEncoderMoved(EncoderMenuSwitch::EncoderDirection dir)
{
menuino.HandleEncoderMoved(dir);
}
//----------------------------------------------
// Encoder click callback
//----------------------------------------------
void OnEncoderClick()
{
menuino.HandleEncoderClick();
}
//------------------------------------------------------
// XPN Callback: XPN connection stablished
//------------------------------------------------------
void OnXpnMasterConnected()
{
OnXpnPowerChanged(xpn->GetPowerStatus());
}
//------------------------------------------------------
// XPN Callback: XPN power notification
//------------------------------------------------------
void OnXpnPowerChanged(uint8_t state)
{
menuino.HandleMasterStatusNotify(state);
}
//------------------------------------------------------
// XPN Callback: Locomotive status notification
//------------------------------------------------------
void OnXpnEngineChanged(XpnEngine *engine)
{
menuino.HandleEngineNotify(engine);
}
//------------------------------------------------------
// XPN Callback: network status notification
//------------------------------------------------------
void OnXpnNetworkStatus(uint8_t state)
{
// TODO: should be a separate LED in the controller
digitalWrite(LED_BUILTIN, state);
}