saving config added
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
#include "ad9102_device.h"
|
||||
#include "storage_sd.h"
|
||||
|
||||
#define PROFILE_REPOSITORY_BUFFER_SIZE 1024u
|
||||
#define PROFILE_REPOSITORY_INDEX_BUFFER_SIZE 1024u
|
||||
#define PROFILE_REPOSITORY_INI_BUFFER_SIZE 4096u
|
||||
|
||||
static char *profile_repository_trim(char *text)
|
||||
{
|
||||
@@ -114,6 +115,52 @@ static void profile_repository_reset_profile(profile_t *profile)
|
||||
profile->ds1809.apply_position = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Apply a `<prefix><field>=value` sweep key.
|
||||
*
|
||||
* @return true when @p key carries @p prefix, i.e. belongs to this sweep.
|
||||
*/
|
||||
static bool profile_repository_apply_sweep_key(sweep_config_t *sweep,
|
||||
const char *prefix,
|
||||
const char *key,
|
||||
const char *value)
|
||||
{
|
||||
const size_t prefix_length = strlen(prefix);
|
||||
const char *field;
|
||||
|
||||
if (strncmp(key, prefix, prefix_length) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
field = key + prefix_length;
|
||||
if (strcmp(field, "enable") == 0)
|
||||
{
|
||||
sweep->enabled = (uint8_t)profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(field, "min_code") == 0)
|
||||
{
|
||||
sweep->min_code = profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(field, "max_code") == 0)
|
||||
{
|
||||
sweep->max_code = profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(field, "step_code") == 0)
|
||||
{
|
||||
sweep->step_code = profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(field, "step_period_us") == 0)
|
||||
{
|
||||
sweep->step_period_us = profile_repository_parse_u16(value);
|
||||
}
|
||||
else if (strcmp(field, "pause_ms") == 0)
|
||||
{
|
||||
sweep->pause_ms = profile_repository_parse_u16(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void profile_repository_apply_key_value(profile_t *profile, const char *key, const char *value)
|
||||
{
|
||||
bool bool_value;
|
||||
@@ -123,6 +170,12 @@ static void profile_repository_apply_key_value(profile_t *profile, const char *k
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile_repository_apply_sweep_key(&profile->laser2_current_sweep, "laser2_current_sweep_", key, value) ||
|
||||
profile_repository_apply_sweep_key(&profile->stm32_dac_sweep, "stm32_dac_sweep_", key, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(key, "profile_name") == 0)
|
||||
{
|
||||
profile_repository_copy_string(profile->display_name, sizeof(profile->display_name), value);
|
||||
@@ -351,13 +404,15 @@ static void profile_repository_apply_key_value(profile_t *profile, const char *k
|
||||
|
||||
static bool profile_repository_load_ini_file(const char *profile_path, profile_t *profile)
|
||||
{
|
||||
char buffer[PROFILE_REPOSITORY_BUFFER_SIZE];
|
||||
/* Static: profiles are parsed only from the main loop, and the stack already holds FatFs' FIL. */
|
||||
static char buffer[PROFILE_REPOSITORY_INI_BUFFER_SIZE];
|
||||
UINT bytes_read = 0u;
|
||||
char *cursor;
|
||||
FRESULT result;
|
||||
|
||||
result = storage_sd_read_bytes(profile_path, 0u, buffer, sizeof(buffer) - 1u, &bytes_read);
|
||||
if (result != FR_OK)
|
||||
result = storage_sd_read_bytes(profile_path, 0u, buffer, sizeof(buffer), &bytes_read);
|
||||
/* A file that fills the whole buffer leaves no room for the terminator: reject it rather than drop keys. */
|
||||
if ((result != FR_OK) || (bytes_read >= sizeof(buffer)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -412,7 +467,7 @@ static bool profile_repository_load_by_valid_line_index(uint16_t target_index,
|
||||
profile_t *out_profile,
|
||||
uint16_t *out_total_valid_lines)
|
||||
{
|
||||
char buffer[PROFILE_REPOSITORY_BUFFER_SIZE];
|
||||
char buffer[PROFILE_REPOSITORY_INDEX_BUFFER_SIZE];
|
||||
UINT bytes_read = 0u;
|
||||
char *cursor;
|
||||
uint16_t valid_line_index = 0u;
|
||||
|
||||
+5
-16
@@ -1,10 +1,6 @@
|
||||
/**
|
||||
* @file sweep.h
|
||||
* @brief Hardware-agnostic periodic staircase sweep between two output codes.
|
||||
*
|
||||
* The output steps from `min_code` up to `max_code` (inclusive) every step
|
||||
* period, then returns to `min_code` and holds it for an extra pause before
|
||||
* the next sweep starts.
|
||||
* @brief Hardware-agnostic periodic staircase sweep (see sweep_config_t).
|
||||
*/
|
||||
|
||||
#ifndef SWEEP_H
|
||||
@@ -13,16 +9,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Host-supplied sweep parameters.
|
||||
*/
|
||||
typedef struct sweep_config_t {
|
||||
uint16_t min_code;
|
||||
uint16_t max_code;
|
||||
uint16_t step_code;
|
||||
uint16_t step_period_us;
|
||||
uint16_t pause_ms;
|
||||
} sweep_config_t;
|
||||
#include "app_types.h"
|
||||
|
||||
/**
|
||||
* @brief Sweep state advanced from the periodic tick interrupt.
|
||||
@@ -39,7 +26,9 @@ typedef struct sweep_t {
|
||||
} sweep_t;
|
||||
|
||||
/**
|
||||
* @brief Validate the configuration and start sweeping from `min_code` on the next tick.
|
||||
* @brief Validate the sweep parameters and start from `min_code` on the next tick.
|
||||
*
|
||||
* The `enabled` field of @p config is not consulted: whether to start is the caller's decision.
|
||||
*
|
||||
* @return false (sweep left stopped) if bounds, step or period are invalid.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user