Skip to content

Commit dd050da

Browse files
committed
Transitional config packet & background sound option
1 parent c2ff588 commit dd050da

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

Firmware/LowLevel/include/nv_config.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838

3939
#define NV_CONFIG_MAX_SAVE_INTERVAL 60000UL // Don't save more often than once a minute
4040

41-
// config_bitmask. Don't mistake with LL_HIGH_LEVEL_CONFIG_BIT. Similar, but not mandatory equal!
42-
#define NV_CONFIG_BIT_DFPIS5V 1 << 0 // DFP is set to 5V
43-
4441
#define NV_RECORD_ID 0x4F4D4331 // Record struct identifier "OMC1" for future flexible length Record.config
4542
#define NV_RECORD_ALIGNMENT (_Alignof(uint32_t)) // Ptr alignment of Record.id for quick in memory access
4643

@@ -51,7 +48,6 @@ namespace nv_config {
5148
// (a new extension-crc isn't valid with a old Record.config. Thus the new extension values may get set i.e. with default values)
5249
struct Config {
5350
// Config bitmask:
54-
// Bit 0: DFP is 5V (enable full sound). See NV_CONFIG_BIT_DFPIS5V
5551
uint8_t config_bitmask = 0; // Don't mistake with LL_HIGH_LEVEL_CONFIG_BIT. Similar, but not mandatory equal!
5652
uint8_t volume = VOLUME_DEFAULT; // Sound volume (0-100%)
5753
iso639_1 language = {'e', 'n'}; // Default to 'en'

Firmware/LowLevel/include/soundsystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ namespace soundSystem {
129129
void playSoundAdHoc(const TrackDef&); // Play sound track number immediately without waiting until the end of sound
130130

131131
void setDFPis5V(const bool t_dfpis5v); // Set if DFP is set to 5V Vcc
132+
void setEnableBackground(const bool); // Set if background sounds shall get played (true) or not (false)
132133

133134
void setLanguage(const iso639_1 language_p, const bool quiet = false); // Set language to the pointing ISO639-1 (2 char) language code and announce if changed and not quiet
134135

Firmware/LowLevel/src/main.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ uint16_t ui_interval = 1000; // UI send msg (LED/State) interval (
113113

114114
nv_config::Config *nv_cfg; // Non-volatile configuration
115115

116-
// Some vars related to PACKET_ID_LL_HIGH_LEVEL_CONFIG_*
117-
uint8_t config_comms_version = 0; // comms packet version (>0 if implemented)
118-
uint8_t config_bitmask = 0; // See LL_HIGH_LEVEL_CONFIG_BIT_*
119-
120116
void sendMessage(void *message, size_t size);
121117
void sendUIMessage(void *message, size_t size);
122118
void onPacketReceived(const uint8_t *buffer, size_t size);
@@ -419,7 +415,8 @@ void setup() {
419415
sound_available = soundSystem::begin();
420416
if (sound_available) {
421417
p.neoPixelSetValue(0, 0, 0, 255, true);
422-
soundSystem::setDFPis5V(nv_cfg->config_bitmask & NV_CONFIG_BIT_DFPIS5V);
418+
soundSystem::setDFPis5V(nv_cfg->config_bitmask & LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V);
419+
soundSystem::setEnableBackground(nv_cfg->config_bitmask & LL_HIGH_LEVEL_CONFIG_BIT_BACKGROUND_SOUNDS);
423420
soundSystem::setLanguage(nv_cfg->language, true);
424421
soundSystem::setVolume(nv_cfg->volume);
425422
// Do NOT play any initial sound now, as we've to handle the special case of
@@ -565,7 +562,7 @@ void onUIPacketReceived(const uint8_t *buffer, size_t size) {
565562
void sendConfigMessage(uint8_t pkt_type) {
566563
struct ll_high_level_config ll_config;
567564
ll_config.type = pkt_type;
568-
ll_config.config_bitmask = config_bitmask;
565+
ll_config.config_bitmask = nv_cfg->config_bitmask;
569566
ll_config.volume = nv_cfg->volume;
570567
strncpy(ll_config.language, nv_cfg->language, 2);
571568
sendMessage(&ll_config, sizeof(struct ll_high_level_config));
@@ -605,27 +602,20 @@ void onPacketReceived(const uint8_t *buffer, size_t size) {
605602
} else if (buffer[0] == PACKET_ID_LL_HIGH_LEVEL_STATE && size == sizeof(struct ll_high_level_state)) {
606603
// copy the state
607604
last_high_level_state = *((struct ll_high_level_state *)buffer);
608-
} else if ((buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ || buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP) && size == sizeof(struct ll_high_level_config)) {
609-
// Read and handle received config
605+
} else if (buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_REQ || buffer[0] == PACKET_ID_LL_HIGH_LEVEL_CONFIG_RSP) {
606+
// Transitional flexible length preparation (see PR #110)
607+
// FIXME: Check Ptr!
610608
struct ll_high_level_config *pkt = (struct ll_high_level_config *)buffer;
611-
612-
config_comms_version = min(pkt->comms_version, LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION); // The lower comms_version is leading
613-
config_bitmask = pkt->config_bitmask; // Take over as sent. HL is leading (for now)
614-
615-
// nv_config.Config specific members ...
616-
// config_bitmask. Do NOT mistake with global config_bitmask (ll_high_level_config.config_bitmask). Similar, but not mandatory the same in future,
617-
// to ensure that a possible instable/flipping future global config_bitmask bit doesn't wear level our flash, we only add those which are known to be stable
618-
// and useful to store.
619-
nv_cfg->config_bitmask = config_bitmask & (LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V | LL_HIGH_LEVEL_CONFIG_BIT_BACKGROUND_SOUNDS);
609+
nv_cfg->config_bitmask = pkt->config_bitmask;
620610
#ifdef ENABLE_SOUND_MODULE
621-
soundSystem::setDFPis5V(nv_cfg->config_bitmask & NV_CONFIG_BIT_DFPIS5V);
611+
soundSystem::setDFPis5V(nv_cfg->config_bitmask & LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V);
612+
soundSystem::setEnableBackground(nv_cfg->config_bitmask & LL_HIGH_LEVEL_CONFIG_BIT_BACKGROUND_SOUNDS);
622613
#endif
623614
// Volume
624615
if (pkt->volume >= 0) {
625616
nv_cfg->volume = pkt->volume;
626617
#ifdef ENABLE_SOUND_MODULE
627618
soundSystem::setVolume(nv_cfg->volume);
628-
// TODO: Set sound background option
629619
#endif
630620
}
631621

Firmware/LowLevel/src/soundsystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace soundSystem
7272
etl::queue<TrackDef, SOUND_QUEUE_SIZE, etl::memory_model::MEMORY_MODEL_SMALL> active_sounds_;
7373
bool sound_available_ = false; // Sound module available as well as SD-Card with some kind of files
7474
bool dfp_is_5v = false; // Enable full sound if DFP is set to 5V Vcc
75+
bool enable_background_ = false; // Enable background sounds
7576
uint8_t volume = VOLUME_DEFAULT; // Last set volume (%)
7677
std::string language_str = "en"; // Default ISO639-1 language string
7778
uint8_t play_folder = 1; // Default play folder, has to be related to language_str
@@ -181,6 +182,10 @@ namespace soundSystem
181182
dfp_is_5v = t_dfpis5v;
182183
}
183184

185+
void setEnableBackground(const bool t_bool) {
186+
enable_background_ = t_bool;
187+
}
188+
184189
void setLanguage(const iso639_1 language_p, const bool quiet) { // Set language to the pointing ISO639-1 (2 char) language code and announce if changed && not quiet
185190
uint8_t last_play_folder = play_folder;
186191

@@ -244,6 +249,8 @@ namespace soundSystem
244249
switch (t_track_def.type)
245250
{
246251
case TrackTypes::background:
252+
if(!enable_background_)
253+
return;
247254
myMP3.stop();
248255
delay(50); // (sometimes) required for "MH2024K-24SS"
249256
myMP3.playMp3FolderTrack(t_track_def.num);

0 commit comments

Comments
 (0)