Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into issue_178
Browse files Browse the repository at this point in the history
  • Loading branch information
boerge1 committed Mar 25, 2024
2 parents a146237 + 91e3a5a commit 59f4e08
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 47 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ Die SD Karte (Ordner mp3 und advert) hat sich gegenüber der Version 3.1.6 geän

# Change Log

## Version 3.1.7 (09.03.2024)
## Version 3.1.7 (26.03.2024)
- [Issue 178](https://github.com/tonuino/TonUINO-TNG/issues/178): Use Nano Every optional with HW Serial connection to the DfPlayer

## Version 3.1.7 (01.03.2024)
## Version 3.1.7 (25.03.2024)
- [Issue 182](https://github.com/tonuino/TonUINO-TNG/issues/182): Quiz game: do not repeat a question until no question remains
- [Issue 176](https://github.com/tonuino/TonUINO-TNG/issues/176): Implement the memory game

## Version 3.1.6 (18.02.2024)
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.1.7 09.03.24\n"));
LOG(init_log, s_error, F("V3.1.7 26.03.24\n"));

Tonuino::getTonuino().setup();
}
Expand Down
1 change: 0 additions & 1 deletion src/poti.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Poti: public CommandSource {
public:

Poti(const Settings& settings, Mp3& mp3);
virtual ~Poti() {}
commandRaw getCommandRaw() override;

private:
Expand Down
16 changes: 16 additions & 0 deletions src/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@

#include "array.hpp"

inline void setBit (uint8_t &v, uint8_t b) { v |= (1<<b); }
inline void clearBit(uint8_t &v, uint8_t b) { v &= ~(1<<b); }
inline bool getBit (uint8_t &v, uint8_t b) { return v & (1<<b); }

template<uint8_t BITS>
class bitfield {
public:
void setBit (uint8_t n) { uint8_t &v = bits[n/8]; ::setBit (v, n%8); }
void clearBit(uint8_t n) { uint8_t &v = bits[n/8]; ::clearBit(v, n%8); }
bool getBit (uint8_t n) { uint8_t &v = bits[n/8]; return ::getBit(v, n%8); }
void setAll (uint8_t v) { for (uint8_t i = 0; i < BITS/8+1; ++i) bits[i] = v; }

private:
uint8_t bits[BITS/8+1]{};
};

template<typename T>
void swap(T &lhs, T &rhs) {
const T t = lhs;
Expand Down
1 change: 0 additions & 1 deletion src/rotary_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class RotaryEncoder: public CommandSource {
public:

RotaryEncoder(const Settings& settings);
virtual ~RotaryEncoder() {}
commandRaw getCommandRaw() override;

static void changed();
Expand Down
26 changes: 13 additions & 13 deletions src/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ struct Settings {
folderSettings getShortCut(uint8_t shortCut);
void setShortCut(uint8_t shortCut, const folderSettings& value);

uint32_t cookie;
byte version;
uint8_t maxVolume;
uint8_t minVolume;
uint8_t initVolume;
uint8_t eq;
uint8_t dummy;
uint32_t standbyTimer;
uint8_t invertVolumeButtons;
shortCuts_t shortCuts;
uint8_t adminMenuLocked;
pin_t adminMenuPin;
uint8_t pauseWhenCardRemoved;
uint32_t cookie {};
byte version {};
uint8_t maxVolume {};
uint8_t minVolume {};
uint8_t initVolume {};
uint8_t eq {};
uint8_t dummy {};
uint32_t standbyTimer {};
uint8_t invertVolumeButtons {};
shortCuts_t shortCuts {};
uint8_t adminMenuLocked {};
pin_t adminMenuPin {};
uint8_t pauseWhenCardRemoved{};
};

// emulates EEPROM.put() .get() and .update() on LGT8F328P platform
Expand Down
36 changes: 35 additions & 1 deletion src/state_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ void Quiz::entry() {
a.push(3);
}

remainingQuestions = 0;

timer.start(timeout);

if (numAnswer == 0)
Expand Down Expand Up @@ -895,7 +897,33 @@ void Quiz::react(command_e const &cmd_e) {
case QuizState::playQuestion:
case QuizState::playSolution:
case QuizState::playWeiter:
question = random(0, numQuestion);
if (remainingQuestions == 0) {
remainingQuestions = numQuestion;
r.setAll(0xFF);
}
question = random(0, remainingQuestions);
LOG(state_log, s_debug, F("random: "), question, F(", remain: "), remainingQuestions);
{
uint8_t i = 0;
while (true) {
if (question == 0) {
while (not r.getBit(i)) ++i;
question = i;
r.clearBit(i);
LOG(state_log, s_debug, F("question: "), question);
break;
}
if (r.getBit(i++)) {
--question;
}
}
}
--remainingQuestions;
LOG(state_log, s_debug, F("r: "), lf_no);
for (uint8_t i = 0; i<numQuestion; ++i)
LOG(state_log, s_debug, r.getBit(i), lf_no);
LOG(state_log, s_debug, F(" "));

trackQuestion = question*(numAnswer+numSolution+1)+1;
a.shuffle();
mp3.enqueueTrack(tonuino.getFolder(), trackQuestion);
Expand Down Expand Up @@ -940,6 +968,9 @@ void Quiz::react(command_e const &cmd_e) {
mp3.enqueueTrack(tonuino.getFolder(), trackQuestion+actAnswer+1);
}
}
else {
mp3.increaseVolume();
}
break;
case command::next:
if (quizState == QuizState::playAnswer) {
Expand Down Expand Up @@ -970,6 +1001,9 @@ void Quiz::react(command_e const &cmd_e) {
mp3.enqueueTrack(tonuino.getFolder(), trackQuestion+actAnswer+1);
}
}
else {
mp3.decreaseVolume();
}
break;
case command::previous:
if (quizState == QuizState::playAnswer) {
Expand Down
58 changes: 30 additions & 28 deletions src/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,16 @@ class Quiz: public Base

void finish();

uint8_t numAnswer;
uint8_t numSolution;
QuizState quizState;
uint8_t question;
uint8_t trackQuestion;
uint8_t numQuestion;
uint8_t actAnswer;
queue<uint8_t, 4> a;
uint8_t numAnswer {};
uint8_t numSolution {};
QuizState quizState {};
uint8_t question {};
uint8_t trackQuestion{};
uint8_t numQuestion {};
uint8_t actAnswer {};
queue<uint8_t, 4> a{};
bitfield<128> r{}; // max in buzzer mode (num answer = 0, num solution = 1)
uint8_t remainingQuestions{};
static constexpr long timeout{ 5 * 60 * 1000l};
};

Expand All @@ -157,8 +159,8 @@ class Memory: public Base

void finish();

uint8_t first;
uint8_t second;
uint8_t first {};
uint8_t second{};
static constexpr long timeout{ 5 * 60 * 1000l};
};

Expand Down Expand Up @@ -248,7 +250,7 @@ class WriteCard : public SM_writeCard
end_writeCard,
run_waitCardRemoved,
};
subState current_subState;
subState current_subState{};
};

class Admin_BaseSetting: public VoiceMenu_tonuino
Expand Down Expand Up @@ -280,10 +282,10 @@ class Admin_Allow: public VoiceMenu_tonuino
allow,
not_allow,
};
subState current_subState;
Settings::pin_t pin;
uint8_t pin_number;
// uint8_t av, bv, cv;
subState current_subState{};
Settings::pin_t pin {};
uint8_t pin_number {};
// uint8_t av{}, bv{}, cv{};
};

class Admin_Entry: public VoiceMenu_tonuino
Expand All @@ -310,7 +312,7 @@ class Admin_NewCard: public Amin_BaseWriteCard
start_writeCard,
run_writeCard,
};
subState current_subState;
subState current_subState{};
};

class Admin_SimpleSetting: public Admin_BaseSetting
Expand All @@ -333,13 +335,13 @@ class Admin_ModCard: public Amin_BaseWriteCard
void entry() final;
void react(command_e const &) final;
private:
pmode_t mode;
enum subState: uint8_t {
start_writeCard,
run_writeCard,
};
subState current_subState;
bool readyToWrite;
pmode_t mode {};
subState current_subState{};
bool readyToWrite {};
};

class Admin_ShortCut: public Admin_BaseSetting
Expand All @@ -353,8 +355,8 @@ class Admin_ShortCut: public Admin_BaseSetting
run_setupCard,
end_setupCard,
};
subState current_subState;
uint8_t shortcut;
subState current_subState{};
uint8_t shortcut {};
};

class Admin_StandbyTimer: public Admin_BaseSetting
Expand All @@ -378,9 +380,9 @@ class Admin_CardsForFolder: public Amin_BaseWriteCard
start_writeCard,
run_writeCard,
};
subState current_subState;
uint8_t special;
uint8_t special2;
subState current_subState{};
uint8_t special {};
uint8_t special2 {};
};

class Admin_InvButtons: public Admin_BaseSetting
Expand Down Expand Up @@ -408,9 +410,9 @@ class Admin_LockAdmin: public Admin_BaseSetting
get_pin,
finished,
};
subState current_subState;
Settings::pin_t pin;
uint8_t pin_number;
subState current_subState{};
Settings::pin_t pin {};
uint8_t pin_number {};
};

class Admin_PauseIfCardRemoved: public Admin_BaseSetting
Expand All @@ -432,7 +434,7 @@ class Admin_MemoryGameCards: public Amin_BaseWriteCard
start_writeCard,
run_writeCard,
};
subState current_subState;
subState current_subState{};
};
#endif

Expand Down

0 comments on commit 59f4e08

Please sign in to comment.