@@ -44,14 +44,18 @@ ws_sdcard::~ws_sdcard() {
44
44
otherwise.
45
45
*/
46
46
/* *************************************************************************/
47
- bool ws_sdcard::InitSDCard (uint8_t pin_cs) {
48
- /* if (pin_cs == 255)
49
- return false; */
50
- if (_sd.begin (pin_cs)) {
51
- is_mode_offline = true ;
47
+ bool ws_sdcard::InitSDCard () {
48
+ if (WsV2.pin_sd_cs == PIN_SD_CS_ERROR) {
49
+ is_mode_offline = false ;
52
50
return is_mode_offline;
53
51
}
54
- return false ;
52
+
53
+ if (_sd.begin (WsV2.pin_sd_cs )) {
54
+ is_mode_offline = true ;
55
+ } else {
56
+ is_mode_offline = false ;
57
+ }
58
+ return is_mode_offline;
55
59
}
56
60
57
61
/* *************************************************************************/
@@ -881,162 +885,4 @@ bool ws_sdcard::LogDS18xSensorEventToSD(
881
885
LogJSONDoc (doc);
882
886
}
883
887
return true ;
884
- }
885
-
886
- // TODO: Do we even need to use this function anymore now that we're running
887
- // wokwi unit tests?
888
- #ifdef OFFLINE_MODE_DEBUG
889
- /* *************************************************************************/
890
- /* !
891
- @brief Validates a JSON string.
892
- @param input
893
- A JSON string to validate.
894
- @returns True if the provided JSON string is valid, False otherwise.
895
- */
896
- /* *************************************************************************/
897
- bool ws_sdcard::ValidateJSON (const char *input) {
898
- JsonDocument doc, filter;
899
-
900
- DeserializationError error =
901
- deserializeJson (doc, input, DeserializationOption::Filter (filter));
902
- return error == DeserializationError::Ok;
903
- }
904
-
905
- /* *************************************************************************/
906
- /* !
907
- @brief Waits for a valid JSON string to be received via the hardware's
908
- serial input or from a hardcoded test JSON string.
909
- @returns True if a valid JSON string was received, False otherwise.
910
- */
911
- /* *************************************************************************/
912
- bool ws_sdcard::waitForSerialConfig () {
913
-
914
- // We provide three ways to use this function:
915
- // 1. Use a SD card with a JSON config file
916
- // 2. Provide a JSON string via the hardware's serial input
917
- // 3. Use a test JSON string - for debugging purposes ONLY
918
-
919
- json_test_data = " {"
920
- " \" exportVersion\" : \" 1.0.0\" ,"
921
- " \" exportedBy\" : \" tester\" ,"
922
- " \" exportedAt\" : \" 2024-10-28T18:58:23.976Z\" ,"
923
- " \" exportedFromDevice\" : {"
924
- " \" board\" : \" metroesp32s3\" ,"
925
- " \" firmwareVersion\" : \" 1.0.0-beta.93\" ,"
926
- " \" referenceVoltage\" : 2.6,"
927
- " \" totalGPIOPins\" : 11,"
928
- " \" totalAnalogPins\" : 6"
929
- " },"
930
- " \" components\" : ["
931
- " {"
932
- " \" componentAPI\" : \" analogio\" ,"
933
- " \" name\" : \" Analog Pin\" ,"
934
- " \" pinName\" : \" D14\" ,"
935
- " \" type\" : \" analog_pin\" ,"
936
- " \" mode\" : \" ANALOG\" ,"
937
- " \" direction\" : \" INPUT\" ,"
938
- " \" sampleMode\" : \" TIMER\" ,"
939
- " \" analogReadMode\" : \" PIN_VALUE\" ,"
940
- " \" period\" : 5,"
941
- " \" isPin\" : true"
942
- " },"
943
- " {"
944
- " \" componentAPI\" : \" analogio\" ,"
945
- " \" name\" : \" Analog Pin\" ,"
946
- " \" pinName\" : \" D27\" ,"
947
- " \" type\" : \" analog_pin\" ,"
948
- " \" mode\" : \" ANALOG\" ,"
949
- " \" direction\" : \" INPUT\" ,"
950
- " \" sampleMode\" : \" TIMER\" ,"
951
- " \" analogReadMode\" : \" PIN_VALUE\" ,"
952
- " \" period\" : 5,"
953
- " \" isPin\" : true"
954
- " },"
955
- " {"
956
- " \" componentAPI\" : \" digitalio\" ,"
957
- " \" name\" : \" Button (D4)\" ,"
958
- " \" pinName\" : \" D4\" ,"
959
- " \" type\" : \" push_button\" ,"
960
- " \" mode\" : \" DIGITAL\" ,"
961
- " \" sampleMode\" : \" EVENT\" ,"
962
- " \" direction\" : \" INPUT\" ,"
963
- " \" period\" : 5,"
964
- " \" pull\" : \" UP\" ,"
965
- " \" isPin\" : true"
966
- " },"
967
- " {"
968
- " \" componentAPI\" : \" ds18x20\" ,"
969
- " \" name\" : \" DS18B20: Temperature Sensor (°F)\" ,"
970
- " \" sensorTypeCount\" : 2,"
971
- " \" sensorType1\" : \" object-temp-fahrenheit\" ,"
972
- " \" sensorType2\" : \" object-temp\" ,"
973
- " \" pinName\" : \" D12\" ,"
974
- " \" sensorResolution\" : 12,"
975
- " \" period\" : 5"
976
- " },"
977
- " {"
978
- " \" componentAPI\" : \" ds18x20\" ,"
979
- " \" name\" : \" DS18B20: Temperature Sensor (°F)\" ,"
980
- " \" sensorTypeCount\" : 2,"
981
- " \" sensorType1\" : \" object-temp-fahrenheit\" ,"
982
- " \" sensorType2\" : \" object-temp\" ,"
983
- " \" pinName\" : \" D25\" ,"
984
- " \" sensorResolution\" : 12,"
985
- " \" period\" : 5"
986
- " }"
987
- " ]"
988
- " }\\ n\r\n " ;
989
-
990
- _serialInput = " " ; // Clear the serial input buffer
991
- if (!_use_test_data) {
992
- WS_DEBUG_PRINTLN (" [SD] Waiting for incoming JSON string..." );
993
- while (true ) {
994
- // Check if there is data available to read
995
- if (Serial.available () > 0 ) {
996
- // Read and append to _serialInput
997
- char c = Serial.read ();
998
- _serialInput += c;
999
-
1000
- // DEBUG - Check JSON output as an Int and total output
1001
- // WS_DEBUG_PRINT("[SD] Character read: ");
1002
- // WS_DEBUG_PRINTLN((int)c);
1003
- // WS_DEBUG_PRINTLN(_serialInput);
1004
-
1005
- // Check for end of JSON string using \n sequence
1006
- if (_serialInput.endsWith (" \\ n" )) {
1007
- WS_DEBUG_PRINTLN (" [SD] End of JSON string detected!" );
1008
- break ;
1009
- }
1010
- }
1011
- }
1012
- }
1013
-
1014
- // Strip the '\n' off the end of _serialInput
1015
- _serialInput.trim ();
1016
-
1017
- // Print out the received JSON string
1018
- WS_DEBUG_PRINT (" [SD][Debug] JSON string received!" );
1019
- if (_use_test_data) {
1020
- WS_DEBUG_PRINTLN (" [from json test data]" );
1021
- WS_DEBUG_PRINTLN (json_test_data);
1022
- } else {
1023
- WS_DEBUG_PRINTLN (_serialInput);
1024
- }
1025
-
1026
- // Attempt to validate the string as JSON
1027
- if (!_use_test_data) {
1028
- if (!ValidateJSON (_serialInput.c_str ())) {
1029
- WS_DEBUG_PRINTLN (" [SD] Invalid JSON string received!" );
1030
- return false ;
1031
- }
1032
- } else {
1033
- if (!ValidateJSON (json_test_data)) {
1034
- WS_DEBUG_PRINTLN (" [SD] Invalid JSON string received!" );
1035
- return false ;
1036
- }
1037
- }
1038
-
1039
- WS_DEBUG_PRINTLN (" [SD] Valid JSON string received!" );
1040
- return true ;
1041
- }
1042
- #endif
888
+ }
0 commit comments