Skip to content

Commit

Permalink
Prepare background-sound option and small code corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehaenger committed Oct 10, 2024
1 parent 8ad6504 commit c2ff588
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Firmware/LowLevel/src/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct ll_ui_event {

#define LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION 1 // Max. comms packet version supported by this open_mower LL FW
#define LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V 1 << 0 // Enable full sound via mower_config env var "OM_DFP_IS_5V"
#define LL_HIGH_LEVEL_CONFIG_BIT_EMERGENCY_INVERSE 1 << 1 // Sample, for possible future usage, i.e. for SA-Type emergency
#define LL_HIGH_LEVEL_CONFIG_BIT_BACKGROUND_SOUNDS 1 << 1 // Enable background sounds

typedef char iso639_1[2]; // Two char ISO 639-1 language code

Expand Down
20 changes: 9 additions & 11 deletions Firmware/LowLevel/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ uint16_t ui_interval = 1000; // UI send msg (LED/State) interval (
nv_config::Config *nv_cfg; // Non-volatile configuration

// Some vars related to PACKET_ID_LL_HIGH_LEVEL_CONFIG_*
uint8_t comms_version = 0; // comms packet version (>0 if implemented)
uint8_t config_comms_version = 0; // comms packet version (>0 if implemented)
uint8_t config_bitmask = 0; // See LL_HIGH_LEVEL_CONFIG_BIT_*

void sendMessage(void *message, size_t size);
Expand Down Expand Up @@ -566,8 +566,8 @@ void sendConfigMessage(uint8_t pkt_type) {
struct ll_high_level_config ll_config;
ll_config.type = pkt_type;
ll_config.config_bitmask = config_bitmask;
ll_config.volume = 80; // FIXME: Adapt once nv_config or improve-sound got merged
strncpy(ll_config.language, "en", 2); // FIXME: Adapt once nv_config or improve-sound got merged
ll_config.volume = nv_cfg->volume;
strncpy(ll_config.language, nv_cfg->language, 2);
sendMessage(&ll_config, sizeof(struct ll_high_level_config));
}

Expand Down Expand Up @@ -608,18 +608,15 @@ void onPacketReceived(const uint8_t *buffer, size_t size) {
} 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)) {
// Read and handle received config
struct ll_high_level_config *pkt = (struct ll_high_level_config *)buffer;
// Apply comms_version
if (pkt->comms_version <= LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION)
comms_version = pkt->comms_version;
else
comms_version = LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION;

config_bitmask = pkt->config_bitmask; // Take over as sent. HL is leading (for now)
config_comms_version = min(pkt->comms_version, LL_HIGH_LEVEL_CONFIG_MAX_COMMS_VERSION); // The lower comms_version is leading
config_bitmask = pkt->config_bitmask; // Take over as sent. HL is leading (for now)

// nv_config.Config specific members ...
// config_bitmask. Do NOT mistake with global config_bitmask (ll_high_level_config.config_bitmask). Similar, but not mandatory the same in future,
// to ensure that a possible instable/flipping future global config_bitmask doesn't wear level our flash, we only add those which are known to be stable.
(config_bitmask & LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V) ? nv_cfg->config_bitmask |= NV_CONFIG_BIT_DFPIS5V : nv_cfg->config_bitmask &= ~NV_CONFIG_BIT_DFPIS5V;
// 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
// and useful to store.
nv_cfg->config_bitmask = config_bitmask & (LL_HIGH_LEVEL_CONFIG_BIT_DFPIS5V | LL_HIGH_LEVEL_CONFIG_BIT_BACKGROUND_SOUNDS);
#ifdef ENABLE_SOUND_MODULE
soundSystem::setDFPis5V(nv_cfg->config_bitmask & NV_CONFIG_BIT_DFPIS5V);
#endif
Expand All @@ -628,6 +625,7 @@ void onPacketReceived(const uint8_t *buffer, size_t size) {
nv_cfg->volume = pkt->volume;
#ifdef ENABLE_SOUND_MODULE
soundSystem::setVolume(nv_cfg->volume);
// TODO: Set sound background option
#endif
}

Expand Down

0 comments on commit c2ff588

Please sign in to comment.