From 3ccf95b28079f5f116e3ff328b8b6e782ca7584b Mon Sep 17 00:00:00 2001
From: Michael DM Dryden <mdryden@chem.utoronto.ca>
Date: Wed, 5 Apr 2017 17:47:15 -0400
Subject: [PATCH] Added calibration resistor values to EEPROM.

---
 src/config/conf_board.h |  3 +++
 src/settings.c          | 16 ++++++++++++----
 src/settings.h          |  4 +++-
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/config/conf_board.h b/src/config/conf_board.h
index 13aaecc..94192c6 100644
--- a/src/config/conf_board.h
+++ b/src/config/conf_board.h
@@ -30,5 +30,8 @@
 #define SETTINGS_R3M_TRIM 0
 #define SETTINGS_R30M_TRIM 0
 #define SETTINGS_R100M_TRIM 0
+#define SETTINGS_EIS_CAL1 3000U
+#define SETTINGS_EIS_CAL2 3000000UL
+
 
 #endif // CONF_BOARD_H
diff --git a/src/settings.c b/src/settings.c
index ecbfdad..50f48cf 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -31,7 +31,7 @@ void settings_handler(char command){
             break;
             
         case 'W': //Write new settings
-            scanf("%i%hhu%u%i%i%i%i%i%i%i",
+            scanf("%i%hhu%u%i%i%i%i%i%i%i%lu%lu",
                   &settings.settings.max5443_offset,
                   &settings.settings.tcs_enabled,
                   &settings.settings.tcs_clear_threshold,
@@ -41,7 +41,9 @@ void settings_handler(char command){
                   &settings.settings.r300k_trim,
                   &settings.settings.r3M_trim,
                   &settings.settings.r30M_trim,
-                  &settings.settings.r100M_trim);
+                  &settings.settings.r100M_trim,
+                  &settings.settings.eis_cal1,
+                  &settings.settings.eis_cal2);
             settings_write_eeprom();
             break;
             
@@ -80,7 +82,9 @@ void settings_read_eeprom(void){
     printf("#INFO: r3M_trim = %i\n\r", settings.settings.r3M_trim);
     printf("#INFO: r30M_trim = %i\n\r", settings.settings.r30M_trim);
     printf("#INFO: r100M_trim = %i\n\r", settings.settings.r100M_trim);
-    printf("Smax5443_offset.%u:tcs_enabled.%u:tcs_clear_threshold.%u:r100_trim.%i:r3k_trim.%i:r30k_trim.%i:r300k_trim.%i:r3M_trim.%i:r30M_trim.%i:r100M_trim.%i\n\r",
+    printf("#INFO: eis_cal1 = %lu\n\r", settings.settings.eis_cal1);
+    printf("#INFO: eis_cal2 = %lu\n\r", settings.settings.eis_cal2);
+    printf("Smax5443_offset.%u:tcs_enabled.%u:tcs_clear_threshold.%u:r100_trim.%i:r3k_trim.%i:r30k_trim.%i:r300k_trim.%i:r3M_trim.%i:r30M_trim.%i:r100M_trim.%i:eit_cal1.%lu:eis_cal2.%lu\n\r",
            settings.settings.max5443_offset,
            settings.settings.tcs_enabled,
            settings.settings.tcs_clear_threshold,
@@ -90,7 +94,9 @@ void settings_read_eeprom(void){
            settings.settings.r300k_trim,
            settings.settings.r3M_trim,
            settings.settings.r30M_trim,
-           settings.settings.r100M_trim);
+           settings.settings.r100M_trim,
+           settings.settings.eis_cal1,
+           settings.settings.eis_cal2);
 }
 
 void settings_write_eeprom(void){
@@ -111,6 +117,8 @@ void settings_restore_defaults(void){
     settings.settings.r3M_trim = SETTINGS_R3M_TRIM;
     settings.settings.r30M_trim = SETTINGS_R30M_TRIM;
     settings.settings.r100M_trim = SETTINGS_R100M_TRIM;
+    settings.settings.eis_cal1 = SETTINGS_EIS_CAL1;
+    settings.settings.eis_cal2 = SETTINGS_EIS_CAL2;
     
     settings_write_eeprom();
 }
diff --git a/src/settings.h b/src/settings.h
index c63f014..98e53ca 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -28,7 +28,9 @@ struct settings_list { //Make sure this doesn't exceed 32 bytes
     int16_t r300k_trim;
     int16_t r3M_trim;
     int16_t r30M_trim;
-    int16_t r100M_trim; //20 bytes
+    int16_t r100M_trim;
+    uint32_t eis_cal1;
+    uint32_t eis_cal2; //28 bytes
 };
 
 union {
-- 
GitLab