forked from DCC-EX/CommandStation-EX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaboxModes.cpp
130 lines (112 loc) · 3.44 KB
/
LaboxModes.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* © 2024 Thierry Paris
* All rights reserved.
*
* This file is part of CommandStation-EX-Labox
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
#include <EEPROM.h>
#include "DCC.h"
#include "LaboxModes.h"
#include "hmi.h"
#include "menuobject.h"
#include "menumanagement.h"
bool LaboxModes::progMode = false;
ProgType LaboxModes::progModeType = ProgType::MAIN;
bool LaboxModes::silentBootMode = false;
int LaboxModes::EEPROMModeProgAddress = 511;
bool LaboxModes::DIAGLABOXMODES=false;
#define DIAG_LMODES if (LaboxModes::DIAGLABOXMODES) DIAG
#ifdef USE_HMI
extern enumHMIState _HMIState;
extern hmi boxHMI;
#endif
void LaboxModes::SetNextMode(ProgType inType)
{
DIAG_LMODES(F("LaboxModes : SetNextMode %c"), (char) inType);
// Reset to Main mode for next reboot.
EEPROM.writeByte(EEPROMModeProgAddress, (char) MAIN);
EEPROM.commit();
}
void LaboxModes::GetCurrentMode()
{
EEPROM.begin(512);
byte mode = EEPROM.read(EEPROMModeProgAddress);
// Modes : EEPROM char progMode ProgModeType SilentMode
// ------------------+-------------+-----------+-------------+--------
// MAIN M false MAIN false
// Reboot form prog B false MAIN true
// CV1ADDR P true CV1ADDR true
// CVREAD Q true CVREAD true
// CVWRITE R true CVWRITE true
// IDENTIFY I true IDENTIFY true
progModeType = (ProgType) mode;
progMode = true;
silentBootMode = true;
if (mode == (char) ProgType::MAIN) {
silentBootMode = false;
progMode = false;
}
if (mode == (char) ProgType::SILENTRETURNTOMAIN) {
progModeType = ProgType::MAIN;
progMode = false;
}
}
/*!
@brief Set prog Mode
@param None
@return None (void).
@note
*/
void LaboxModes::SetProgMode()
{
#ifdef USE_HMI
_HMIDEBUG_FCT_PRINTLN("LaboxModes::setProgMode().. Begin");
LaboxModes::progMode = true;
_HMIState = StateParametersMenu;
if (LaboxModes::progModeType == ProgType::CV1ADDR)
{
boxHMI.menu->setMenu(boxHMI.menu->trainAddrRead);
boxHMI.menu->trainAddrRead->start();
}
if (LaboxModes::progModeType == ProgType::CVREAD)
{
boxHMI.menu->setMenu(boxHMI.menu->trainCVRead);
boxHMI.menu->trainCVRead->start();
}
if (LaboxModes::progModeType == ProgType::CVWRITE)
{
boxHMI.menu->setMenu(boxHMI.menu->trainCVWrite);
boxHMI.menu->trainCVWrite->start();
}
if (LaboxModes::progModeType == ProgType::IDENTIFY)
{
boxHMI.menu->setMenu(boxHMI.menu->trainIdent);
boxHMI.menu->trainIdent->start();
}
_HMIDEBUG_FCT_PRINTLN("LaboxModes::setProgMode().. End");
#endif
}
void LaboxModes::Restart(ProgType inType)
{
DIAG_LMODES(F("LaboxModes : Restart"));
if (EEPROM.readByte(EEPROMModeProgAddress) != (char) inType) {
EEPROM.writeByte(EEPROMModeProgAddress, (char) inType);
EEPROM.commit();
}
delay(500);
ESP.restart();
}