Ver Fonte

storage: Change data type to int32_t to allow for negative values

Helmut Pozimski há 1 ano atrás
pai
commit
2b93711273
3 ficheiros alterados com 11 adições e 11 exclusões
  1. 1 1
      main/api.c
  2. 6 6
      main/storage.c
  3. 4 4
      main/storage.h

+ 1 - 1
main/api.c

@@ -47,7 +47,7 @@ static esp_err_t wakeup_get_handler(httpd_req_t *req) {
 		return ESP_OK;	
 	}
 	
-	uint16_t wakeup_minutes;
+	int16_t wakeup_minutes;
 	esp_err_t ret = read_wakeup_time_str(wakeup_str, &wakeup_minutes);
 	
 	if (ret == ESP_OK) {

+ 6 - 6
main/storage.c

@@ -25,22 +25,22 @@ esp_err_t storage_init(char* name) {
    return nvs_open(name, NVS_READWRITE, &handle);
 }
 
-esp_err_t write_wakeup_time_str(char* key, uint16_t value) {
-	esp_err_t ret = nvs_set_u16(handle, key, value);
+esp_err_t write_wakeup_time_str(char* key, int16_t value) {
+	esp_err_t ret = nvs_set_i16(handle, key, value);
 	return ret | nvs_commit(handle);
 }
 
-esp_err_t write_wakeup_time_tm(struct tm* datetime, uint16_t value) {
+esp_err_t write_wakeup_time_tm(struct tm* datetime, int16_t value) {
 	char key[9];
 	format_date(datetime, key);
 	return write_wakeup_time_str(key, value);
 }
 
-esp_err_t read_wakeup_time_str(char* key, uint16_t* value) {
-	return nvs_get_u16(handle, key, value);
+esp_err_t read_wakeup_time_str(char* key, int16_t* value) {
+	return nvs_get_i16(handle, key, value);
 }
 
-esp_err_t read_wakeup_time_tm(struct tm* datetime, uint16_t* value) {
+esp_err_t read_wakeup_time_tm(struct tm* datetime, int16_t* value) {
 	char key[9];
 	format_date(datetime, key);
 	return read_wakeup_time_str(key, value);

+ 4 - 4
main/storage.h

@@ -10,9 +10,9 @@
 #include <nvs_flash.h>
 
 esp_err_t storage_init(char* name);
-esp_err_t write_wakeup_time_tm(struct tm* datetime, uint16_t value);
-esp_err_t write_wakeup_time_str(char* key, uint16_t value);
-esp_err_t read_wakeup_time_tm(struct tm* datetime, uint16_t* value);
-esp_err_t read_wakeup_time_str(char* key, uint16_t* value);
+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 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);
 void delete_outdated_entries(struct tm* datetime, char* namespace);