浏览代码

api/storage: Move week days to storage

Helmut Pozimski 1 年之前
父节点
当前提交
34dc5d09ef
共有 3 个文件被更改,包括 13 次插入10 次删除
  1. 2 3
      main/api.c
  2. 3 3
      main/storage.c
  3. 8 4
      main/storage.h

+ 2 - 3
main/api.c

@@ -13,12 +13,11 @@
 #include <cJSON.h>
  
 #include "storage.h"
- 
+
 #define TAG "api"
-#define NUM_WEEK_DAYS 7
 #define BUF_LEN 1000
 
-static char WEEK_DAYS[NUM_WEEK_DAYS][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
+
 
 static char* extract_wakeup(const char* uri) {
 	return strrchr(uri, '/') +1;

+ 3 - 3
main/storage.c

@@ -25,7 +25,7 @@ esp_err_t storage_init(char* name) {
    return nvs_open(name, NVS_READWRITE, &handle);
 }
 
-esp_err_t write_wakeup_time_str(char* key, int16_t value) {
+esp_err_t write_wakeup_time_str(const char* key, int16_t value) {
 	esp_err_t ret = nvs_set_i16(handle, key, value);
 	return ret | nvs_commit(handle);
 }
@@ -36,7 +36,7 @@ esp_err_t write_wakeup_time_tm(struct tm* datetime, int16_t value) {
 	return write_wakeup_time_str(key, value);
 }
 
-esp_err_t read_wakeup_time_str(char* key, int16_t* value) {
+esp_err_t read_wakeup_time_str(const char* key, int16_t* value) {
 	return nvs_get_i16(handle, key, value);
 }
 
@@ -46,7 +46,7 @@ esp_err_t read_wakeup_time_tm(struct tm* datetime, int16_t* value) {
 	return read_wakeup_time_str(key, value);
 }
 
-esp_err_t delete_wakeup_time_str(char* key) {
+esp_err_t delete_wakeup_time_str(const char* key) {
 	esp_err_t ret = nvs_erase_key(handle, key);
 	return ret | nvs_commit(handle);
 }

+ 8 - 4
main/storage.h

@@ -3,16 +3,20 @@
  *
  * SPDX-License-Identifier: GPL-2.0-only
  */
- 
+
 #include <stdint.h>
 #include <time.h>
 #include <esp_err.h>
 #include <nvs_flash.h>
 
+#define NUM_WEEK_DAYS 7
+
+static const char WEEK_DAYS[NUM_WEEK_DAYS][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
+
 esp_err_t storage_init(char* name);
 esp_err_t write_wakeup_time_tm(struct tm* datetime, int16_t value);
-esp_err_t write_wakeup_time_str(char* key, int16_t value);
+esp_err_t write_wakeup_time_str(const char* key, int16_t value);
 esp_err_t read_wakeup_time_tm(struct tm* datetime, int16_t* value);
-esp_err_t read_wakeup_time_str(char* key, int16_t* value);
-esp_err_t delete_wakeup_time_str(char* key);
+esp_err_t read_wakeup_time_str(const char* key, int16_t* value);
+esp_err_t delete_wakeup_time_str(const char* key);
 void delete_outdated_entries(struct tm* datetime, char* namespace);