Dash OTA dogfooding nits

This commit is contained in:
cpq committed 2026-06-09 11:56:40 +01:00
1 parent 73037880e6
commit 27459efc61
29 files changed
+2635 -1478

No files matched your search

+16 -14
View File
@@ -6,23 +6,25 @@
static bool s_led1;
static char s_version[10];
static void read_status(void) {
MG_INFO(("READING STATUS"));
mg_snprintf(s_version, sizeof(s_version), "1.2.3");
// These conditionals make this file work on both microcontroller and desktop
// Useful for developing the UI on desktop, and copying to an MCU project.
static bool status_fn(enum mg_dash_op op, struct mg_dash_user *u) {
(void) u;
if (op == MG_DASH_READ) {
MG_INFO(("READING STATUS"));
mg_snprintf(s_version, sizeof(s_version), "1.2.3");
// These conditionals make this file work on both microcontroller and desktop
#if MG_ARCH == MG_ARCH_CUBE
s_led1 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0); // Read LED state into field
s_led1 = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0);
#endif
}
static void write_status(void) {
MG_INFO(("WRITING STATUS"));
return true;
}
if (op == MG_DASH_WRITE) {
MG_INFO(("WRITING STATUS"));
#if MG_ARCH == MG_ARCH_CUBE
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, s_led1); // Write LED state from field
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, s_led1);
#endif
return true;
}
return false;
}
static struct mg_field fields_status[] = {
@@ -32,7 +34,7 @@ static struct mg_field fields_status[] = {
};
static struct mg_field_set field_set_status = {
"status", fields_status, read_status, write_status, 0, 0, NULL,
"status", fields_status, status_fn, NULL, NULL, NULL,
};
void mg_dash_init(struct mg_mgr *mgr) {
@@ -44,7 +44,7 @@
<div>
This toggle button is a stylised checkbox.
<code>data-bind="status.led1"</code> binds it to the device variable.
<code>data-autosave="1"</code> makes it send <code>{"led1": VALUE}</code> to the device every time the user toggles the
<code>data-autosave="1"</code> makes it send <code>{"status":{"led1": VALUE}}</code> to the device every time the user toggles the
button. On the device side, <code>read_status()</code> or <code>write_status()</code> are called every time
the LED state is read or written.
</div>