Skip to content

Commit 4fd4ebb

Browse files
committed
only read file when updated
1 parent c6f94e2 commit 4fd4ebb

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

stack/modules/d7ap/phy.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ static channel_id_t default_channel_id = {
125125

126126
static channel_id_t current_channel_id = EMPTY_CHANNEL_ID;
127127

128+
static uint8_t gain_offset = 0;
129+
128130
/*
129131
* FSK packet handler structure
130132
*/
@@ -361,10 +363,8 @@ uint16_t phy_calculate_tx_duration(phy_channel_class_t channel_class, phy_coding
361363

362364
static void configure_eirp(eirp_t eirp)
363365
{
364-
int8_t factory_settings[D7A_FILE_FACTORY_SETTINGS_SIZE]; //Byte 0 is gain offset
365-
d7ap_fs_read_file(D7A_FILE_FACTORY_SETTINGS_FILE_ID, 0, factory_settings, D7A_FILE_FACTORY_SETTINGS_SIZE);
366-
eirp -= factory_settings[0];
367-
DPRINT("Set Tx power: %d dBm including offset of %i\n", eirp, factory_settings[0]);
366+
eirp -= gain_offset;
367+
DPRINT("Set Tx power: %d dBm including offset of %i\n", eirp, gain_offset);
368368

369369
hw_radio_set_tx_power(eirp);
370370
}
@@ -443,6 +443,16 @@ void continuous_tx_expiration()
443443
DPRINT("Continuous TX is now terminated");
444444
}
445445

446+
void fact_settings_file_change_callback()
447+
{
448+
uint8_t fact_settings[D7A_FILE_FACTORY_SETTINGS_SIZE];
449+
d7ap_fs_read_file(D7A_FILE_FACTORY_SETTINGS_FILE_ID, 0, fact_settings, D7A_FILE_FACTORY_SETTINGS_SIZE);
450+
451+
gain_offset = (int8_t)fact_settings[0];
452+
453+
DPRINT("gain set to %i\n", gain_offset);
454+
}
455+
446456

447457
error_t phy_init(void) {
448458

@@ -469,6 +479,10 @@ error_t phy_init(void) {
469479
hw_radio_set_dc_free(HW_DC_FREE_NONE);
470480
#endif
471481

482+
fact_settings_file_change_callback();
483+
484+
d7ap_fs_register_file_modified_callback(D7A_FILE_FACTORY_SETTINGS_FILE_ID, &fact_settings_file_change_callback);
485+
472486
configure_syncword(PHY_SYNCWORD_CLASS0, &default_channel_id);
473487
configure_channel(&default_channel_id);
474488
configure_eirp(10);

0 commit comments

Comments
 (0)