saving config added
This commit is contained in:
+48
-28
@@ -202,6 +202,7 @@ static void app_write_tec_modulation_sample(void);
|
||||
static void app_set_stm32_dac(uint16_t code, uint8_t enabled);
|
||||
static void app_update_sweep_timer(void);
|
||||
static void app_stop_sweeps(void);
|
||||
static bool app_apply_sweep_config(sweep_t *sweep, const sweep_config_t *config);
|
||||
static void app_prepare_status_response(void);
|
||||
static void app_capture_live_frame(bool update_temperature_loops, bool drive_laser_currents);
|
||||
static void app_decode_work_packet(const uint16_t *packet_words);
|
||||
@@ -594,6 +595,34 @@ static void app_stop_sweeps(void)
|
||||
app_update_sweep_timer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop @p sweep and restart it with @p config when enabled.
|
||||
*
|
||||
* @return false if an enabled configuration could not be started.
|
||||
*/
|
||||
static bool app_apply_sweep_config(sweep_t *sweep, const sweep_config_t *config)
|
||||
{
|
||||
const bool dac_target = (sweep == &g_app.stm32_dac_sweep);
|
||||
bool started = true;
|
||||
|
||||
sweep_stop(sweep);
|
||||
if (config->enabled != 0u)
|
||||
{
|
||||
/* The laser current is only driven in WORK mode; idle entry stops the sweep again. */
|
||||
started = dac_target ? (config->max_code <= STM32_DAC_MAX_CODE) : (g_app.mode == APP_MODE_WORK);
|
||||
__disable_irq();
|
||||
started = started && sweep_start(sweep, config, APP_SWEEP_TICK_US);
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
if (dac_target && (sweep->enabled == 0u))
|
||||
{
|
||||
stm32_dac_output_set(g_app.stm32_dac.code, g_app.stm32_dac.enabled);
|
||||
}
|
||||
app_update_sweep_timer();
|
||||
return started;
|
||||
}
|
||||
|
||||
static void app_apply_profile_auxiliary_outputs(const profile_t *profile)
|
||||
{
|
||||
if (profile == NULL)
|
||||
@@ -603,6 +632,10 @@ static void app_apply_profile_auxiliary_outputs(const profile_t *profile)
|
||||
|
||||
ad9833_apply(profile->ad9833.enabled, profile->ad9833.triangle, profile->ad9833.frequency_word);
|
||||
app_set_stm32_dac(profile->stm32_dac.code, profile->stm32_dac.enabled);
|
||||
if (!app_apply_sweep_config(&g_app.stm32_dac_sweep, &profile->stm32_dac_sweep))
|
||||
{
|
||||
app_set_error(APP_STATUS_FLAG_SD_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
static void app_prepare_status_response(void)
|
||||
@@ -676,6 +709,10 @@ static bool app_activate_profile(const profile_t *profile, uint16_t index, bool
|
||||
app_apply_work_config_to_board();
|
||||
app_set_mode(APP_MODE_WORK);
|
||||
g_app.resume_mode = APP_MODE_WORK;
|
||||
if (!app_apply_sweep_config(&g_app.laser2_current_sweep, &profile->laser2_current_sweep))
|
||||
{
|
||||
app_set_error(APP_STATUS_FLAG_SD_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if (profile->ds1809.apply_position)
|
||||
@@ -1386,8 +1423,7 @@ static void app_handle_sweep_control_packet(const app_packet_t *packet)
|
||||
{
|
||||
sweep_config_t config;
|
||||
sweep_t *sweep;
|
||||
bool dac_target;
|
||||
bool started = true;
|
||||
uint16_t flags;
|
||||
|
||||
if ((packet == NULL) || !packet->checksum_valid ||
|
||||
((packet->words[0] & ~APP_SWEEP_ALLOWED_FLAGS) != 0u))
|
||||
@@ -1397,32 +1433,16 @@ static void app_handle_sweep_control_packet(const app_packet_t *packet)
|
||||
return;
|
||||
}
|
||||
|
||||
dac_target = (packet->words[0] & APP_SWEEP_FLAG_TARGET_STM32_DAC) != 0u;
|
||||
sweep = dac_target ? &g_app.stm32_dac_sweep : &g_app.laser2_current_sweep;
|
||||
sweep_stop(sweep);
|
||||
|
||||
if ((packet->words[0] & APP_SWEEP_FLAG_ENABLE) != 0u)
|
||||
{
|
||||
config.min_code = packet->words[1];
|
||||
config.max_code = packet->words[2];
|
||||
config.step_code = packet->words[3];
|
||||
config.step_period_us = packet->words[4];
|
||||
config.pause_ms = packet->words[5];
|
||||
|
||||
/* The laser current is only driven in WORK mode; idle entry stops the sweep again. */
|
||||
started = dac_target ? (config.max_code <= STM32_DAC_MAX_CODE) : (g_app.mode == APP_MODE_WORK);
|
||||
__disable_irq();
|
||||
started = started && sweep_start(sweep, &config, APP_SWEEP_TICK_US);
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
if (dac_target && (sweep->enabled == 0u))
|
||||
{
|
||||
stm32_dac_output_set(g_app.stm32_dac.code, g_app.stm32_dac.enabled);
|
||||
}
|
||||
app_update_sweep_timer();
|
||||
|
||||
if (!started)
|
||||
flags = packet->words[0];
|
||||
sweep = ((flags & APP_SWEEP_FLAG_TARGET_STM32_DAC) != 0u) ? &g_app.stm32_dac_sweep
|
||||
: &g_app.laser2_current_sweep;
|
||||
config.enabled = ((flags & APP_SWEEP_FLAG_ENABLE) != 0u) ? 1u : 0u;
|
||||
config.min_code = packet->words[1];
|
||||
config.max_code = packet->words[2];
|
||||
config.step_code = packet->words[3];
|
||||
config.step_period_us = packet->words[4];
|
||||
config.pause_ms = packet->words[5];
|
||||
if (!app_apply_sweep_config(sweep, &config))
|
||||
{
|
||||
app_set_error(APP_STATUS_FLAG_UART_DECODE_ERROR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user