Add X42 as EEPROM reset command + handling + visualization

MMU-193
pull/260/head
D.R.racer 2023-02-17 10:22:29 +01:00
parent 9fce324bff
commit 14d12caf8a
2 changed files with 51 additions and 4 deletions

View File

@ -2,12 +2,13 @@
#include "application.h"
#include "registers.h"
#include "modules/leds.h"
#include "modules/globals.h"
#include "modules/user_input.h"
#include "modules/finda.h"
#include "modules/fsensor.h"
#include "modules/globals.h"
#include "modules/leds.h"
#include "modules/permanent_storage.h"
#include "modules/serial.h"
#include "modules/user_input.h"
#include "logic/command_base.h"
#include "logic/cut_filament.h"
@ -179,6 +180,51 @@ void Application::ReportWriteRegister(const mp::RequestMsg &rq) {
modules::serial::WriteToUSART(rsp, len);
}
/// Performs a blocking (!) LED "snake" from one side to the other and back.
/// Intended only for visualization of EEPROM reset, not to be used in while the MMU is running normally
namespace EEPROMResetVis {
static void Delay(){
uint32_t start = mt::timebase.Millis();
while( ! mt::timebase.Elapsed(start, 100) ){
ml::leds.Step();
}
}
static void __attribute__((noinline)) Green(uint8_t i){
ml::leds.SetPairButOffOthers(i, ml::on, ml::off);
Delay();
}
static void __attribute__((noinline)) Red(uint8_t i){
ml::leds.SetPairButOffOthers(i, ml::on, ml::off);
Delay();
}
static void Run(){
for(uint8_t i = 0; i < ml::leds.LedPairsCount(); ++i){
Green(i);
Red(i);
}
for(uint8_t i = ml::leds.LedPairsCount(); i != 0; --i){
Red(i);
Green(i);
}
}
} // namespace EEPROMResetVis
void Application::ProcessReset(uint8_t resetType){
switch(resetType){
case 42: // perform an EEPROM reset if the resetType == The Answer to the Ultimate Question of Life, the Universe, and Everything :)
mps::EraseAll();
EEPROMResetVis::Run();
[[fallthrough]];
default: // anything else "just" restarts the board
hal::cpu::Reset();
}
}
void Application::ProcessRequestMsg(const mp::RequestMsg &rq) {
switch (rq.code) {
case mp::RequestMsgCodes::Button:
@ -196,7 +242,7 @@ void Application::ProcessRequestMsg(const mp::RequestMsg &rq) {
break;
case mp::RequestMsgCodes::Reset:
// immediately reset the board - there is no response in this case
hal::cpu::Reset();
ProcessReset(rq.value);
break;
case mp::RequestMsgCodes::Version:
case mp::RequestMsgCodes::Read:

View File

@ -46,6 +46,7 @@ private:
void ReportReadRegister(const mp::RequestMsg &rq);
void ReportWriteRegister(const mp::RequestMsg &rq);
void ProcessRequestMsg(const mp::RequestMsg &rq);
void ProcessReset(uint8_t resetType);
uint16_t lastCommandProcessedMs;