Skip to content

Commit

Permalink
Merge pull request #237: Issue_236: Improve hardware diagnostic on st…
Browse files Browse the repository at this point in the history
…artup
  • Loading branch information
boerge1 authored Oct 13, 2024
2 parents e6284fa + 33aecc8 commit 9a8c923
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 127 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.11 geä

# Change Log

## Version 3.2.1 (22.09.2024)
- [Issue 236](https://github.com/tonuino/TonUINO-TNG/issues/236): Improve hardware diagnostic on startup

## Version 3.2.0 (05.09.2024)
- [Issue 231](https://github.com/tonuino/TonUINO-TNG/issues/231): Fix logging of card data (bad order)
- [Issue 229](https://github.com/tonuino/TonUINO-TNG/issues/229): playAdvertisement does not work for some DF Player
Expand Down
2 changes: 1 addition & 1 deletion TonUINO-TNG.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void setup()
LOG(init_log, s_error, F("TonUINO Version 3.1 - refactored by Boerge1\n"));
LOG(init_log, s_error, F("created by Thorsten Voß and licensed under GNU/GPL."));
LOG(init_log, s_error, F("Information and contribution at https://tonuino.de.\n"));
LOG(init_log, s_error, F("V3.2.0 05.09.24\n"));
LOG(init_log, s_error, F("V3.2.1 22.09.24\n"));

#ifdef TonUINO_Classic
LOG(init_log, s_error, F("C "), lf_no);
Expand Down
13 changes: 10 additions & 3 deletions src/chip_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ void Chip_card::sleepCard() {
void Chip_card::initCard() {
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
LOG(card_log, s_info, F("MFRC522:"), mfrc522.PCD_ReadRegister(MFRC522::VersionReg));
LOG_CODE(card_log, s_debug, {
if (not mfrc522.PCD_PerformSelfTest())
LOG(card_log, s_debug, F("mfrc522 self test not successful"));
});
byte ver = mfrc522.PCD_ReadRegister(MFRC522::VersionReg);
LOG(card_log, s_info, F("MFRC522:"), ver);
// Show MFRC522 Card Reader version
// 0 or 255: communication error)
// 136: (clone)
Expand All @@ -247,6 +252,8 @@ void Chip_card::initCard() {
// 146: v2.0
// 18: counterfeit chip
// else: unknown
if ((ver == 0) || (ver == 255))
LOG(card_log, s_error, F("com to mfrc broken"));
}

void Chip_card::stopCard() {
Expand All @@ -271,15 +278,15 @@ cardEvent Chip_card::getCardEvent() {

if (cardRemovedSwitch.on()) {
if (not cardRemoved) {
LOG(card_log, s_info, F("Card Removed"));
LOG(card_log, s_info, F("Card Rem"));
cardRemoved = true;
stopCard();
return cardEvent::removed;
}
}
else {
if (cardRemoved) {
LOG(card_log, s_info, F("Card Inserted"));
LOG(card_log, s_info, F("Card Ins"));
cardRemoved = false;
return cardEvent::inserted;
}
Expand Down
58 changes: 57 additions & 1 deletion src/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,67 @@ command Commands::getCommand(commandRaw b, state_for_command s) {
}

if (ret != command::none) {
LOG(button_log, s_info, F("Command: "), static_cast<uint8_t>(ret));
#ifdef ALLinONE
LOG(button_log, s_debug, F("btn/cmd: "), static_cast<uint8_t>(b), F("/"), static_cast<uint8_t>(ret));
#else
LOG(button_log, s_info , F("btn/cmd: "), getCommandRawStr(b), F("/"), getCommandStr(ret));
#endif
}
return ret;
}

const __FlashStringHelper* Commands::getCommandRawStr(commandRaw cmd) {
switch(cmd) {
case commandRaw::none : return(F("none" )); break;
case commandRaw::start : return(F("start" )); break;
case commandRaw::allLong : return(F("allLong" )); break;
case commandRaw::pause : return(F("pause" )); break;
case commandRaw::pauseLong : return(F("pauseLong" )); break;
case commandRaw::up : return(F("up" )); break;
case commandRaw::upLong : return(F("upLong" )); break;
case commandRaw::upLongRepeat : return(F("upLongRepeat" )); break;
case commandRaw::down : return(F("down" )); break;
case commandRaw::downLong : return(F("downLong" )); break;
case commandRaw::downLongRepeat: return(F("downLongRepeat")); break;
case commandRaw::updownLong : return(F("updownLong" )); break;
#ifdef FIVEBUTTONS
case commandRaw::four : return(F("four" )); break;
case commandRaw::fourLong : return(F("fourLong" )); break;
case commandRaw::fourLongRepeat: return(F("fourLongRepeat")); break;
case commandRaw::five : return(F("five" )); break;
case commandRaw::fiveLong : return(F("fiveLong" )); break;
case commandRaw::fiveLongRepeat: return(F("fiveLongRepeat")); break;
#endif
default : return(F("" )); break;
}
}

const __FlashStringHelper* Commands::getCommandStr (command cmd) {
switch(cmd) {
case command::none : return(F("none" )); break;
case command::admin : return(F("admin" )); break;
case command::shutdown : return(F("shutdown" )); break;
case command::shortcut1 : return(F("shortcut1" )); break;
case command::shortcut2 : return(F("shortcut2" )); break;
case command::shortcut3 : return(F("shortcut3" )); break;
case command::start : return(F("start" )); break;
case command::pause : return(F("pause" )); break;
case command::track : return(F("track" )); break;
case command::volume_up : return(F("volume_up" )); break;
case command::volume_down: return(F("volume_down")); break;
case command::bright_up : return(F("bright_up" )); break;
case command::bright_down: return(F("bright_down")); break;
case command::to_first : return(F("to_first" )); break;
case command::next : return(F("next" )); break;
case command::next10 : return(F("next10" )); break;
case command::previous : return(F("previous" )); break;
case command::previous10 : return(F("previous10" )); break;
case command::select : return(F("select" )); break;
default : return(F("" )); break;
}
}


uint8_t Commands::getButtonCode(commandRaw b) {
switch (b) {
case commandRaw::pause: return 1;
Expand Down
87 changes: 45 additions & 42 deletions src/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,66 +41,66 @@ fiveLong prev 10 vol-- cont.
*/

enum class commandRaw: uint8_t {
none,
start,
allLong,
pause,
pauseLong,
up,
upLong,
upLongRepeat,
down,
downLong,
downLongRepeat,
updownLong,
none = 0,
start = 1,
allLong = 2,
pause = 3,
pauseLong = 4,
up = 5,
upLong = 6,
upLongRepeat = 7,
down = 8,
downLong = 9,
downLongRepeat = 10,
updownLong = 11,
#ifdef FIVEBUTTONS
four,
fourLong,
fourLongRepeat,
five,
fiveLong,
fiveLongRepeat,
four = 12,
fourLong = 13,
fourLongRepeat = 14,
five = 15,
fiveLong = 16,
fiveLongRepeat = 17,
#endif
#ifdef SPECIAL_START_SHORTCUT
specialStart,
specialStart = 18,
#endif
#ifdef SerialInputAsCommand
menu_jump,
menu_jump = 19,
#endif
cmd_end,
cmd_end = 20,
#ifdef BUTTONS3X3
ext_begin = buttonExtSC_begin,
ext_end = ext_begin + buttonExtSC_buttons,
#endif
};

enum class command: uint8_t {
none,
none = 0,
// play/pause/idle
admin,
shutdown,
shortcut1,
shortcut2,
shortcut3,
start,
pause,
track,
volume_up,
volume_down,
bright_up,
bright_down,
to_first,
admin = 1,
shutdown = 2,
shortcut1 = 3,
shortcut2 = 4,
shortcut3 = 5,
start = 6,
pause = 7,
track = 8,
volume_up = 9,
volume_down = 10,
bright_up = 11,
bright_down = 12,
to_first = 13,
// play/pause/idle/adm
next,
next10,
previous,
previous10,
next = 14,
next10 = 15,
previous = 16,
previous10 = 17,
// adm
select,
select = 18,
#ifdef SerialInputAsCommand
menu_jump,
menu_jump = 19,
#endif
adm_end,
adm_end = 20,
#ifdef BUTTONS3X3
ext_begin = buttonExtSC_begin,
ext_end = ext_begin + buttonExtSC_buttons,
Expand Down Expand Up @@ -131,6 +131,9 @@ class Commands {
commandRaw getCommandRaw();
command getCommand (commandRaw b, state_for_command s);

const __FlashStringHelper* getCommandRawStr(commandRaw cmd);
const __FlashStringHelper* getCommandStr (command cmd);

static bool isSelect(command cmd) {
return cmd == command::select
#ifdef SerialInputAsCommand
Expand Down
2 changes: 1 addition & 1 deletion src/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ inline constexpr levelType dfPlayer_busyPinType = levelType::activeHigh;
#if defined(DFMiniMp3_T_CHIP_MH2024K24SS_MP3_TF_16P_V3_0)
inline constexpr unsigned long dfPlayer_timeUntilStarts = 2500;
#elif defined(DFMiniMp3_T_CHIP_GD3200B)
inline constexpr unsigned long dfPlayer_timeUntilStarts = 1500;
inline constexpr unsigned long dfPlayer_timeUntilStarts = 2500;
#else
inline constexpr unsigned long dfPlayer_timeUntilStarts = 1200;
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ DEFINE_LOGGER(tonuino_log , s_debug , void);

DEFINE_LOGGER(init_log , s_info , tonuino_log);
DEFINE_LOGGER(card_log , s_info , tonuino_log);
DEFINE_LOGGER(play_log , s_warning, tonuino_log);
DEFINE_LOGGER(standby_log , s_warning, tonuino_log);
DEFINE_LOGGER(play_log , s_info , tonuino_log);
DEFINE_LOGGER(standby_log , s_info , tonuino_log);
DEFINE_LOGGER(state_log , s_info , tonuino_log);
DEFINE_LOGGER(button_log , s_info , tonuino_log);
DEFINE_LOGGER(modifier_log, s_warning, tonuino_log);
DEFINE_LOGGER(modifier_log, s_info , tonuino_log);
DEFINE_LOGGER(mp3_log , s_info , tonuino_log);
DEFINE_LOGGER(settings_log, s_info , tonuino_log);
DEFINE_LOGGER(batvol_log , s_info , tonuino_log);
Expand Down
22 changes: 11 additions & 11 deletions src/modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const __FlashStringHelper* str_RepeatSingleModifier() { return F("RepeatSingle")

void SleepTimer::loop() {
if (sleepTimer.isActive() && sleepTimer.isExpired()) {
LOG(modifier_log, s_info, str_SleepTimer(), F(" -> expired"));
LOG(modifier_log, s_debug, str_SleepTimer(), F(" -> expired"));
if (not stopAfterTrackFinished || stopAfterTrackFinished_active) {
LOG(modifier_log, s_info, str_SleepTimer(), F(" -> SLEEP!"));
LOG(modifier_log, s_debug, str_SleepTimer(), F(" -> SLEEP!"));
if (SM_tonuino::is_in_state<Play>())
SM_tonuino::dispatch(command_e(commandRaw::pause));
fired = true;
Expand All @@ -35,7 +35,7 @@ void SleepTimer::loop() {
}
bool SleepTimer::handleNext() {
if (stopAfterTrackFinished_active) {
LOG(modifier_log, s_info, str_SleepTimer(), F(" -> SLEEP!"));
LOG(modifier_log, s_debug, str_SleepTimer(), F(" -> SLEEP!"));
mp3.clearFolderQueue();
stopAfterTrackFinished_active = false;
sleepTimer.stop();
Expand All @@ -46,7 +46,7 @@ bool SleepTimer::handleNext() {
}

void SleepTimer::init(pmode_t, uint8_t special /* is minutes*/) {
LOG(modifier_log, s_info, str_SleepTimer(), F(" minutes: "), special);
LOG(modifier_log, s_debug, str_SleepTimer(), F(" minutes: "), special);
fired = false;
stopAfterTrackFinished_active = false;
if (special > 0x80) {
Expand Down Expand Up @@ -76,7 +76,7 @@ bool SleepTimer::handleRFID(const folderSettings &/*newCard*/) {


void DanceGame::init(pmode_t a_mode, uint8_t a_t) {
LOG(modifier_log, s_info, str_danceGame(), F("t : "), a_t);
LOG(modifier_log, s_debug, str_danceGame(), F("t : "), a_t);
mode = a_mode;
if (mode == pmode_t::fi_wa_ai) lastFiWaAi = random(0, 3);
setNextStop(true /*addAdvTime*/);
Expand All @@ -92,12 +92,12 @@ void DanceGame::loop() {
if (stopTimer.isExpired()) {
switch (mode) {
case pmode_t::freeze_dance:
LOG(modifier_log, s_info, str_danceGame(), F(" -> FREEZE!"));
LOG(modifier_log, s_debug, str_danceGame(), F(" -> FREEZE!"));
mp3.playAdvertisement(advertTracks::t_301_freeze_freeze);
setNextStop(true /*addAdvTime*/);
break;
case pmode_t::fi_wa_ai:
LOG(modifier_log, s_info, str_danceGame(), F(" -> Action! "));
LOG(modifier_log, s_debug, str_danceGame(), F(" -> Action! "));
lastFiWaAi = (lastFiWaAi+random(1, 3))%3;
mp3.playAdvertisement(static_cast<uint16_t>(advertTracks::t_306_fire)+lastFiWaAi);
setNextStop(true /*addAdvTime*/);
Expand All @@ -121,13 +121,13 @@ void DanceGame::setNextStop(bool addAdvTime) {
default: break;
}
}
LOG(modifier_log, s_info, str_danceGame(), F(" next stop in "), seconds);
LOG(modifier_log, s_debug, str_danceGame(), F(" next stop in "), seconds);
stopTimer.start(seconds * 1000);
}

bool KindergardenMode::handleNext() {
if (cardQueued) {
LOG(modifier_log, s_info, str_KindergardenMode(), F(" -> NEXT"));
LOG(modifier_log, s_debug, str_KindergardenMode(), F(" -> NEXT"));
cardQueued = false;

tonuino.setMyFolder(nextCard, true /*myFolderIsCard*/);
Expand All @@ -143,7 +143,7 @@ bool KindergardenMode::handleRFID(const folderSettings &newCard) {
return false;

if (!cardQueued) {
LOG(modifier_log, s_info, str_KindergardenMode(), F(" -> queued!"));
LOG(modifier_log, s_debug, str_KindergardenMode(), F(" -> queued!"));
nextCard = newCard;
cardQueued = true;
}
Expand All @@ -160,7 +160,7 @@ bool KindergardenMode::handleButton(command cmd) {


bool RepeatSingleModifier::handleNext() {
LOG(modifier_log, s_info, str_RepeatSingleModifier(), F(" -> REPEAT"));
LOG(modifier_log, s_debug, str_RepeatSingleModifier(), F(" -> REPEAT"));
mp3.loop(); // WA: this will call again Mp3Notify::OnPlayFinished() (error in DFMiniMp3 lib)
// but will be blocked by lastTrackFinished
Mp3Notify::ResetLastTrackFinished(); // unblock this track so that it can be repeated
Expand Down
Loading

0 comments on commit 9a8c923

Please sign in to comment.