-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdcc.cpp
More file actions
81 lines (63 loc) · 2.61 KB
/
dcc.cpp
File metadata and controls
81 lines (63 loc) · 2.61 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
81
/*******************************************************************************************************
File: dcc_rs.cpp
Author: Aiko Pras
History: 2022/06/08 AP Version 1.0
Purpose: Implements the safety decoder specific DCC message reception
******************************************************************************************************/
#include <Arduino.h>
#include <AP_DCC_Decoder_Core.h> // To include all objects, such as dcc, accCmd, etc.
#include "dcc_rs.h"
// Object instantiation
DccSystem dccSystem;
RsBus rsBus;
extern DccTimer watchdogTimer; // Is instantiated in safety.cpp
//******************************************************************************************************
bool DccSystem::watchdogMsgReceived() {
if (!watchdogReceived) return false;
watchdogReceived = false;
return true;
}
bool DccSystem::resetMsgReceived() {
if (!resetReceived) return false;
resetReceived = false;
return true;
}
//******************************************************************************************************
void DccSystem::update() {
if (dcc.input()) {
switch (dcc.cmdType) {
case Dcc::MyAccessoryCmd:
// A watchdog command has been received.
// Watchdog Messages should address the first device of the decoder and may be a + or a - command
// Note that the AP_DCC_Library filters duplicates, thus we need to send alternating + and - commands
if (accCmd.turnout == 1) {
watchdogReceived = true;
watchdogTimer.restart();
}
break;
case Dcc::MyPomCmd:
// A Programming on Main (PoM) message is received
cvProgramming.processMessage(Dcc::MyPomCmd);
break;
case Dcc::SmCmd:
// A Service Mode (SM - Programming track) message is received
cvProgramming.processMessage(Dcc::SmCmd);
break;
case Dcc::ResetCmd:
case Dcc::MyEmergencyStopCmd:
// The ResetCmd is send after the STOP button on the LH100 is pushed, or after TC Einfrieren
// MyEmergencyStopCmd is never received from a LZV100, but included for possible future versions
resetReceived = true;
break;
case Dcc::SomeLocoMovesFlag:
// The SomeLocoMovesFlag indicates that a loco speed command with a speed > 0 has been received.
// Such flag indicates that at least one train is (still) moving
// The test if trains are still moving must be initiated (set to false) by the state machine
trainsMoveFlag = true;
break;
default:
// Nothing
break;
}
}
}