20
20
#include " Wippersnapper_V2.h"
21
21
22
22
#define SD_FAT_TYPE 3
23
+ #define MAX_LOG_FILE_SZ 500 // /< Maximum log file size of 500 bytes
23
24
24
25
// forward decl.
25
26
class Wippersnapper_V2 ;
@@ -35,13 +36,32 @@ class ws_sdcard {
35
36
ws_sdcard ();
36
37
~ws_sdcard ();
37
38
bool InitSDCard ();
39
+ bool parseConfigFile ();
40
+ #ifdef OFFLINE_MODE_DEBUG
41
+ bool waitForSerialConfig ();
42
+ #endif
43
+ bool CreateNewLogFile ();
44
+ bool isModeOffline () { return is_mode_offline; }
45
+
46
+ bool LogGPIOSensorEventToSD (uint8_t pin, float value,
47
+ wippersnapper_sensor_SensorType read_type);
48
+ bool LogGPIOSensorEventToSD (uint8_t pin, bool value,
49
+ wippersnapper_sensor_SensorType read_type);
50
+ bool LogGPIOSensorEventToSD (uint8_t pin, uint16_t value,
51
+ wippersnapper_sensor_SensorType read_type);
52
+ bool LogDS18xSensorEventToSD (wippersnapper_ds18x20_Ds18x20Event *event_msg);
53
+
54
+ private:
38
55
bool ConfigureRTC (const char *rtc_type);
39
56
uint32_t GetTimestamp ();
40
- bool mode_offline; // TODO: Refactor to getter/setter
41
- bool
42
- PushSignalToSharedBuffer (wippersnapper_signal_BrokerToDevice &msg_signal);
57
+ bool InitDS1307 ();
58
+ bool InitDS3231 ();
59
+ bool InitPCF8523 ();
60
+ bool InitSoftRTC ();
61
+ bool validateJson (const char *input);
62
+ void CheckIn (uint8_t max_digital_pins, uint8_t max_analog_pins,
63
+ float ref_voltage);
43
64
44
- bool parseConfigFile ();
45
65
wippersnapper_sensor_SensorType ParseSensorType (const char *sensor_type);
46
66
bool ParseDigitalIOAdd (wippersnapper_digitalio_DigitalIOAdd &msg_DigitalIOAdd,
47
67
const char *pin, float period, bool value,
@@ -60,36 +80,21 @@ class ws_sdcard {
60
80
wippersnapper_sensor_SensorType read_type);
61
81
void BuildJSONDoc (JsonDocument &doc, const char *pin, bool value,
62
82
wippersnapper_sensor_SensorType read_type);
63
- bool LogGPIOSensorEventToSD (uint8_t pin, float value,
64
- wippersnapper_sensor_SensorType read_type);
65
- bool LogGPIOSensorEventToSD (uint8_t pin, bool value,
66
- wippersnapper_sensor_SensorType read_type);
67
- bool LogGPIOSensorEventToSD (uint8_t pin, uint16_t value,
68
- wippersnapper_sensor_SensorType read_type);
69
- bool LogDS18xSensorEventToSD (wippersnapper_ds18x20_Ds18x20Event *event_msg);
70
-
71
- #ifdef OFFLINE_MODE_DEBUG
72
- bool waitForSerialConfig ();
73
- bool validateJson (const char *input);
74
- #endif
75
- private:
76
- bool InitDS1307 ();
77
- bool InitDS3231 ();
78
- bool InitPCF8523 ();
79
- bool InitSoftRTC ();
80
- void CheckIn (uint8_t max_digital_pins, uint8_t max_analog_pins,
81
- float ref_voltage);
82
- SdFat _sd; // /< SD object from Adafruit SDFat library
83
- String _serialInput; // /< Serial input buffer
84
- const char *json_test_data; // /< Json test data
85
- bool _use_test_data; // /< True if sample data is being used to test, instead
86
- // /< of serial input, False otherwise.
87
- bool _wokwi_runner; // /< True if `exportedBy` key is "wokwi", otherwise False
88
- const char *_log_filename; // /< Path to the log file
89
- RTC_DS3231 *_rtc_ds3231 = nullptr ; // /< DS3231 RTC object
90
- RTC_DS1307 *_rtc_ds1307 = nullptr ; // /< DS1307 RTC object
83
+ bool
84
+ PushSignalToSharedBuffer (wippersnapper_signal_BrokerToDevice &msg_signal);
85
+ SdFat _sd; // /< SD object from Adafruit SDFat library
86
+ bool is_mode_offline; // /< True if offline mode is enabled, False otherwise
87
+ String _serialInput; // /< Serial input buffer
88
+ const char *json_test_data; // /< Json test data
89
+ const char *_log_filename; // /< Path to the log file
90
+ int _sz_log_file; // /< Size of the current log file, in Bytes
91
+ RTC_DS3231 *_rtc_ds3231 = nullptr ; // /< DS3231 RTC object
92
+ RTC_DS1307 *_rtc_ds1307 = nullptr ; // /< DS1307 RTC object
91
93
RTC_PCF8523 *_rtc_pcf8523 = nullptr ; // /< PCF8523 RTC object
92
94
RTC_Millis *_rtc_soft = nullptr ; // /< Software RTC object
95
+ // Testing
96
+ bool _use_test_data; // /< True if sample data is being used for testing
97
+ bool _is_using_wokwi; // /< True if `exportedBy` key is "wokwi"
93
98
};
94
99
extern Wippersnapper_V2 WsV2;
95
100
#endif // WS_SDCARD_H
0 commit comments