Version 0.3.20 fix for equipment records create and delete. default tip

Tue, 02 Nov 2021 14:47:43 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 02 Nov 2021 14:47:43 +0100
changeset 120
afd58d4c7b5b
parent 119
1cef3c25426b

Version 0.3.20 fix for equipment records create and delete.

CMakeLists.txt file | annotate | diff | comparison | revisions
main/config.c file | annotate | diff | comparison | revisions
main/setup.c file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat Jul 31 15:44:20 2021 +0200
+++ b/CMakeLists.txt	Tue Nov 02 14:47:43 2021 +0100
@@ -2,7 +2,7 @@
 # in this exact order for cmake to work correctly
 cmake_minimum_required(VERSION 3.5)
 
-set(PROJECT_VER "0.3.19")
+set(PROJECT_VER "0.3.20")
 set(PROJECT_NAME "brewboard")
 
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
--- a/main/config.c	Sat Jul 31 15:44:20 2021 +0200
+++ b/main/config.c	Tue Nov 02 14:47:43 2021 +0100
@@ -67,15 +67,14 @@
 
 void append_equipment()
 {
-return;
     uint8_t *dst = (uint8_t *)&equipment;
     FILE *f = fopen("/spiffs/etc/equipments.conf", "a");
 	      
     if (f == NULL) {
-	ESP_LOGE(TAG, "append /spiffs/etc/equipments.conf failed");
+	ESP_LOGE(TAG, "/spiffs/etc/equipments.conf append failed");
 	return;
     }
-	        
+
     size_t bytes = fwrite(dst, 1, equipment_hdr.recsize, f);
     fclose(f);
     ESP_LOGI(TAG, "/spiffs/etc/equipments.conf appended %d bytes", bytes);
@@ -181,7 +180,7 @@
 	if (bytes != equipment_hdr.recsize) {
 	    ESP_LOGE(TAG, "/spiffs/etc/equipments.conf read record %d, %d/%d bytes", RecNo, bytes, equipment_hdr.recsize);
 	} else {
-	    ESP_LOGD(TAG, "/spiffs/etc/equipments.conf read %d bytes, record %d: %s", bytes, RecNo, equipment.Name);
+	    ESP_LOGI(TAG, "/spiffs/etc/equipments.conf read %d bytes, record %d: %s", bytes, RecNo, equipment.Name);
 	}
     }
 }
@@ -195,7 +194,7 @@
 
     f = fopen("/spiffs/etc/equipments.conf", "r+");
     if (f == NULL) {
-	ESP_LOGE(TAG, "write /spiffs/etc/equipments.conf failed");
+	ESP_LOGE(TAG, "/spiffs/etc/equipments.conf write failed");
 	return;
     }
     fseek(f, (RecNo - 1) * equipment_hdr.recsize + equipment_hdr.hdrsize, SEEK_SET);
@@ -211,7 +210,6 @@
 
 void delete_equipment(int RecNo)
 {
-return;
     int		RecRead = 1, RecWrite = 1;
     FILE	*n, *o;
     uint8_t	*dst;
@@ -219,13 +217,14 @@
 
     n = fopen("/spiffs/etc/equipments.new", "a");
     if (n == NULL) {
-	ESP_LOGE(TAG, "cannot create /spiffs/etc/equipments.new");
+	ESP_LOGE(TAG, "/spiffs/etc/equipments.new create error");
 	return;
     }
     o = fopen("/spiffs/etc/equipments.conf", "r");
     if (o == NULL) {
-	ESP_LOGE(TAG, "cannot open spiffs/etc/equipments.conf for reading");
+	ESP_LOGE(TAG, "/spiffs/etc/equipments.conf open error");
 	fclose(n);
+	unlink("/spiffs/etc/equipments.new");
 	return;
     }
 
@@ -257,7 +256,7 @@
     rename("/spiffs/etc/equipments.conf", "/spiffs/etc/equipments.old");
     rename("/spiffs/etc/equipments.new", "/spiffs/etc/equipments.conf");
     unlink("/spiffs/etc/equipments.old");
-    ESP_LOGI(TAG, "Deleted equipment %d", RecNo);
+    ESP_LOGI(TAG, "Deleted equipment %d, %d left", RecNo, RecWrite - 1);
 }
 
 
--- a/main/setup.c	Sat Jul 31 15:44:20 2021 +0200
+++ b/main/setup.c	Tue Nov 02 14:47:43 2021 +0100
@@ -248,8 +248,10 @@
 					append_equipment();
 					Records++;
 					CurrentRec = Records;
+					config.EquipmentRec = CurrentRec;
 					UpdateRec = true;
 					ESP_LOGI(TAG, "New equipment record %d", CurrentRec);
+					write_config();
 					break;
 
 			    case 2:	if ((CurrentRec != config.EquipmentRec) && (Records > 1)) {

mercurial