Skip to content

Commit 0fb17a6

Browse files
committed
wip: json is maybe not the best way to store data in an embedded thingy
1 parent 613a157 commit 0fb17a6

File tree

6 files changed

+9
-24
lines changed

6 files changed

+9
-24
lines changed

firmware/esp32-s3/.vscode/c_cpp_properties.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
"${env:IDF_PATH}/components/**"
1111
],
1212
"browse": {
13-
"path": [
14-
"${env:IDF_PATH}/components",
15-
"${workspaceFolder}"
16-
],
13+
"path": ["${env:IDF_PATH}/components", "${workspaceFolder}"],
1714
"limitSymbolsToIncludedHeaders": true
1815
}
1916
}
2017
],
2118
"env": {
22-
"IDF_PATH": "~/esp/esp-idf",
19+
"IDF_PATH": "${workspaceFolder}/../../ressources/espressif/esp-idf",
2320
"IDF_TOOL_PATH": "~/.espressif/tools"
2421
},
2522
"version": 4

firmware/esp32-s3/main/config_storage.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ static const char *TAG = "MACROLEV";
1515

1616
#define BOOT_MODE_PIN GPIO_NUM_0
1717
#define STORAGE_NAMESPACE "storage"
18+
#define STORAGE_BASE_PATH "/spiffs"
1819
#define JSON_FILENAME "config.json"
19-
#define CDC_ACCUM_BUF_SIZE 1024
20+
#define CDC_ACCUM_BUF_SIZE (250 * 1024) // 250kb max
2021

2122
#define MARKER "[EOF]"
2223
#define MARKER_LEN (sizeof(MARKER) - 1)
@@ -32,8 +33,7 @@ esp_err_t save_json_to_file(const char *filename, cJSON *json) {
3233
}
3334

3435
char filepath[64];
35-
// snprintf(filepath, sizeof(filepath), "/%s", filename);
36-
snprintf(filepath, sizeof(filepath), filename);
36+
snprintf(filepath, sizeof(filepath), "%s/%s", STORAGE_BASE_PATH, filename);
3737

3838
FILE *f = fopen(filepath, "w");
3939
if (f == NULL) {
@@ -105,7 +105,7 @@ static void usb_cdc_rx_queue_handler_task(void *pvParameters) {
105105
ESP_LOGI(TAG, "Received %d bytes from USB", msg.buf_len);
106106

107107
// Check for buffer overflow
108-
if (cdc_accum_len + msg.buf_len < CDC_ACCUM_BUF_SIZE) {
108+
if (cdc_accum_len + msg.buf_len <= CDC_ACCUM_BUF_SIZE) {
109109
memcpy(&cdc_accum_buf[cdc_accum_len], msg.buf, msg.buf_len);
110110
cdc_accum_len += msg.buf_len;
111111

@@ -137,7 +137,7 @@ static void usb_cdc_rx_queue_handler_task(void *pvParameters) {
137137
}
138138
}
139139
} else {
140-
ESP_LOGE(TAG, "CDC accumulation buffer overflow. Resetting buffer.");
140+
ESP_LOGE(TAG, "CDC accumulation buffer overflow. Resetting buffer. cdc_accum_len: %d, CDC_ACCUM_BUF_SIZE: %d", cdc_accum_len, CDC_ACCUM_BUF_SIZE);
141141
cdc_accum_len = 0;
142142
}
143143
}
@@ -149,7 +149,7 @@ static esp_err_t init_spiffs(void) {
149149
ESP_LOGI(TAG, "Initializing SPIFFS");
150150

151151
esp_vfs_spiffs_conf_t conf = {
152-
.base_path = "/",
152+
.base_path = STORAGE_BASE_PATH,
153153
.partition_label = NULL,
154154
.max_files = 1,
155155
.format_if_mount_failed = true

firmware/esp32-s3/main/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ void app_main(void) {
2727
// Main loop
2828
while (1) {
2929
vTaskDelay(pdMS_TO_TICKS(10));
30-
// if (xQueueReceive(usb_queue, &msg, portMAX_DELAY)) {
3130
// if (msg.buf_len) {
3231
// // Print received data
3332
// ESP_LOGI(TAG, "Data from channel %d with length %d", msg.itf, msg.buf_len);

firmware/esp32-s3/main/sensors.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
#include <stdio.h>
1010
#include <string.h>
1111

12-
/**
13-
* chip dependent
14-
* - usb
15-
* - config r/w
16-
* - how to read adc values
17-
*
18-
* lib
19-
* - config parse
20-
* - runtime
21-
*/
22-
2312
static const char *TAG = "MACROLEV";
2413

2514
/**

firmware/esp32-s3/main/usb.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event) {
9494
void usb_init(void) {
9595
// Initialize TinyUSB
9696
ESP_LOGI(TAG, "USB initialization");
97-
extern const tinyusb_config_t tusb_cfg;
9897
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
9998

10099
// Create the CDC RX queue

firmware/esp32-s3/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"id":15,"layout":{"x":0,"y":1,"height":1,"width":1},"hardware":{"adcChannel":0,"muxChannel":2,"magnetDirection":"NORTH_UP","switchMagneticProfileId":0},"deadzones":{"startOffset":0,"endOffset":0},"actuationDistance":0,"releaseDistance":0,"rapidTrigger":{"isEnabled":0,"isContinuous":0,"actuationDistanceDelta":0,"releaseDistanceDelta":0},"layers":[{"holdTimeBeforeActuation":0,"isAutoCapsEnabled":0,"autoCapsVelocityTreshold":0,"keycodes":[{"type":"NORMAL","value":0}]}]},{"id":15,"layout":{"x":0,"y":1,"height":1,"width":1},"hardware":{"adcChannel":0,"muxChannel":2,"magnetDirection":"NORTH_UP","switchMagneticProfileId":0},"deadzones":{"startOffset":0,"endOffset":0},"actuationDistance":0,"releaseDistance":0,"rapidTrigger":{"isEnabled":0,"isContinuous":0,"actuationDistanceDelta":0,"releaseDistanceDelta":0},"layers":[{"holdTimeBeforeActuation":0,"isAutoCapsEnabled":0,"autoCapsVelocityTreshold":0,"keycodes":[{"type":"NORMAL","value":0}]}]},{"id":15,"layout":{"x":0,"y":1,"height":1,"width":1},"hardware":{"adcChannel":0,"muxChannel":2,"magnetDirection":"NORTH_UP","switchMagneticProfileId":0},"deadzones":{"startOffset":0,"endOffset":0},"actuationDistance":0,"releaseDistance":0,"rapidTrigger":{"isEnabled":0,"isContinuous":0,"actuationDistanceDelta":0,"releaseDistanceDelta":0},"layers":[{"holdTimeBeforeActuation":0,"isAutoCapsEnabled":0,"autoCapsVelocityTreshold":0,"keycodes":[{"type":"NORMAL","value":0}]}]}]

0 commit comments

Comments
 (0)