Skip to content

Commit ca3a4a9

Browse files
committed
Implement ConfigManager with serial command interface
1 parent 5b3d4b7 commit ca3a4a9

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

fw/src/main.cpp

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "version.h"
77
#include "sqm_utils.h"
88
#include "amsky01_utils.h"
9+
#include "config.h"
910

1011
// Firmware and hardware version info
1112
#define DEVICE_NAME "AMSKY01A"
@@ -26,6 +27,8 @@ AMS_TSL2591 amsSensor;
2627
// Initialize MLX90641 thermal sensor
2728
MLX90641 mlxSensor;
2829

30+
// Initialize configuration manager
31+
ConfigManager configManager;
2932

3033
// Variables for LEDs
3134
bool trigger_led_state = false;
@@ -57,11 +60,76 @@ static void processSerialCommand(const char *cmd)
5760
thrmap_streaming = false;
5861
Serial.println("# thrmap streaming OFF");
5962
}
63+
else if (strcmp(cmd, "config_show") == 0)
64+
{
65+
configManager.printConfig();
66+
}
67+
else if (strcmp(cmd, "config_save") == 0)
68+
{
69+
configManager.save();
70+
}
71+
else if (strcmp(cmd, "config_reset") == 0)
72+
{
73+
configManager.reset();
74+
}
75+
else if (strncmp(cmd, "set ", 4) == 0)
76+
{
77+
// Parse "set <param> <value>" commands
78+
const char* params = cmd + 4;
79+
char param[32];
80+
char value[32];
81+
82+
if (sscanf(params, "%s %s", param, value) == 2)
83+
{
84+
if (strcmp(param, "sqm_offset") == 0) {
85+
configManager.setSqmOffset(atof(value));
86+
Serial.print("# Set sqm_offset = "); Serial.println(value);
87+
}
88+
else if (strcmp(param, "sqm_multiplier") == 0) {
89+
configManager.setSqmMultiplier(atof(value));
90+
Serial.print("# Set sqm_multiplier = "); Serial.println(value);
91+
}
92+
else if (strcmp(param, "alert_enabled") == 0) {
93+
configManager.setAlertEnabled(atoi(value));
94+
Serial.print("# Set alert_enabled = "); Serial.println(value);
95+
}
96+
else if (strcmp(param, "alert_cloud_temp") == 0) {
97+
configManager.setAlertCloudTempThreshold(atof(value));
98+
Serial.print("# Set alert_cloud_temp = "); Serial.println(value);
99+
}
100+
else if (strcmp(param, "alert_cloud_below") == 0) {
101+
configManager.setAlertCloudBelow(atoi(value));
102+
Serial.print("# Set alert_cloud_below = "); Serial.println(value);
103+
}
104+
else if (strcmp(param, "alert_light_lux") == 0) {
105+
configManager.setAlertLightThreshold(atof(value));
106+
Serial.print("# Set alert_light_lux = "); Serial.println(value);
107+
}
108+
else if (strcmp(param, "alert_light_above") == 0) {
109+
configManager.setAlertLightAbove(atoi(value));
110+
Serial.print("# Set alert_light_above = "); Serial.println(value);
111+
}
112+
else if (strcmp(param, "device_label") == 0) {
113+
configManager.setDeviceLabel(value);
114+
Serial.print("# Set device_label = "); Serial.println(value);
115+
}
116+
else {
117+
Serial.print("# Unknown parameter: "); Serial.println(param);
118+
}
119+
}
120+
else {
121+
Serial.println("# Invalid set command format. Use: set <param> <value>");
122+
}
123+
}
124+
else
125+
{
126+
Serial.print("# Unknown command: "); Serial.println(cmd);
127+
}
60128
}
61129

62130
static void handleSerialCommands()
63131
{
64-
static char buf[32];
132+
static char buf[64];
65133
static uint8_t pos = 0;
66134

67135
while (Serial.available() > 0)
@@ -158,6 +226,10 @@ void setup() {
158226
} else {
159227
// MLX sensor is not available
160228
}
229+
230+
// Initialize configuration manager
231+
configManager.begin();
232+
configManager.printConfig();
161233
}
162234

163235
void loop() {

0 commit comments

Comments
 (0)