@@ -474,7 +474,7 @@ uint32_t ws_sdcard::HexStrToInt(const char *hex_str) {
474
474
*/
475
475
bool ws_sdcard::ParseUartAdd (JsonObject &component,
476
476
wippersnapper_uart_UartAdd &msg_uart_add) {
477
- // Configure the Serial
477
+ // Configure the UART Serial
478
478
msg_uart_add.has_cfg_serial = true ;
479
479
snprintf (msg_uart_add.cfg_serial .pin_rx ,
480
480
sizeof (msg_uart_add.cfg_serial .pin_rx ), " %d" ,
@@ -493,30 +493,29 @@ bool ws_sdcard::ParseUartAdd(JsonObject &component,
493
493
msg_uart_add.cfg_serial .use_sw_serial = component[" useSwSerial" ] | false ;
494
494
msg_uart_add.cfg_serial .sw_serial_invert =
495
495
component[" swSerialInvert" ] | false ;
496
- // Configure the UART device
496
+
497
+ // Configure the UART Device
497
498
msg_uart_add.has_cfg_device = true ;
498
499
strncpy (msg_uart_add.cfg_device .device_id ,
499
500
component[" deviceId" ] | UNKNOWN_VALUE,
500
501
sizeof (msg_uart_add.cfg_device .device_id ) - 1 );
501
- // set UartDeviceType
502
502
const char *device_type = component[" deviceType" ] | " UNKNOWN" ;
503
503
if (strcmp (device_type, " gps" ) == 0 ) {
504
504
msg_uart_add.cfg_device .device_type =
505
505
wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GPS;
506
506
msg_uart_add.cfg_device .which_config =
507
507
wippersnapper_uart_UartDeviceConfig_gps_tag;
508
- msg_uart_add.cfg_device .config .gps .period = component[" period" ] | 0 .0 ;
508
+ msg_uart_add.cfg_device .config .gps .period = component[" gps " ][ " period" ] | 30 .0 ;
509
509
// TODO: We do not have parsing for GPS PMTK or UBX implemented yet
510
510
// This is a minimum possible implementation
511
- // TODO: We will want to add parsing for GPS PMTK, at least
512
511
} else if (strcmp (device_type, " pm25aqi" ) == 0 ) {
513
512
msg_uart_add.cfg_device .device_type =
514
513
wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_PM25AQI;
515
514
msg_uart_add.cfg_device .which_config =
516
515
wippersnapper_uart_UartDeviceConfig_pm25aqi_tag;
517
- msg_uart_add.cfg_device .config .pm25aqi .period = component[" period" ] | 0.0 ;
518
516
msg_uart_add.cfg_device .config .pm25aqi .is_pm1006 =
519
517
component[" isPm1006" ] | false ;
518
+ msg_uart_add.cfg_device .config .pm25aqi .period = component[" pm25aqi" ][" period" ] | 30.0 ;
520
519
// Fill sensor types
521
520
pb_size_t sensor_type_count = 0 ;
522
521
for (JsonObject sensor_type : component[" sensorTypes" ].as <JsonArray>()) {
@@ -527,16 +526,13 @@ bool ws_sdcard::ParseUartAdd(JsonObject &component,
527
526
msg_uart_add.cfg_device .config .pm25aqi .sensor_types_count =
528
527
sensor_type_count;
529
528
} else if (strcmp (device_type, " generic_input" ) == 0 ) {
530
- // TODO: Fill device name (requires an update to uart.pb.h so it's not a
531
- // pb_callback field)
532
529
msg_uart_add.cfg_device .device_type =
533
530
wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GENERIC_INPUT;
534
531
msg_uart_add.cfg_device .which_config =
535
532
wippersnapper_uart_UartDeviceConfig_generic_uart_input_tag;
536
533
msg_uart_add.cfg_device .config .generic_uart_input .line_ending =
537
534
ParseUartLineEnding (component[" lineEnding" ] | " LF" );
538
- msg_uart_add.cfg_device .config .generic_uart_input .period =
539
- component[" period" ] | 0.0 ;
535
+ msg_uart_add.cfg_device .config .generic_uart_input .period = component[" generic_input" ][" period" ] | 30.0 ;
540
536
// Fill sensor types
541
537
pb_size_t sensor_type_count = 0 ;
542
538
for (JsonObject sensor_type : component[" sensorTypes" ].as <JsonArray>()) {
@@ -599,11 +595,6 @@ bool ws_sdcard::ParseI2cDeviceAddReplace(
599
595
wippersnapper_i2c_I2cDeviceAddOrReplace &msg_i2c_add) {
600
596
strcpy (msg_i2c_add.i2c_device_name ,
601
597
component[" i2cDeviceName" ] | UNKNOWN_VALUE);
602
- msg_i2c_add.i2c_device_period = component[" period" ] | 0.0 ;
603
- if (msg_i2c_add.i2c_device_period < 0.0 ) {
604
- WS_DEBUG_PRINTLN (" [SD] Parsing Error: Invalid I2C device period!" );
605
- return false ;
606
- }
607
598
608
599
msg_i2c_add.has_i2c_device_description = true ;
609
600
strcpy (msg_i2c_add.i2c_device_description .i2c_bus_scl ,
@@ -630,14 +621,15 @@ bool ws_sdcard::ParseI2cDeviceAddReplace(
630
621
const char *mux_channel = component[" i2cMuxChannel" ] | " 0xFFFF" ;
631
622
msg_i2c_add.i2c_device_description .i2c_mux_channel = HexStrToInt (mux_channel);
632
623
624
+ // Set the period
633
625
bool is_gps = component[" isGps" ] | false ;
634
- WS_DEBUG_PRINT (" [SD] is_gps = " );
635
- WS_DEBUG_PRINTLN (is_gps ? " true" : " false" );
636
626
if (is_gps) {
637
627
msg_i2c_add.is_gps = true ;
638
- msg_i2c_add.gps_config .period = component[" period" ] | 15.0 ;
628
+ msg_i2c_add.gps_config .period = component[" gps " ][ " period" ] | 15.0 ;
639
629
msg_i2c_add.has_gps_config = true ;
640
630
return true ; // early-out, we don't need to set sensor types for GPS
631
+ } else {
632
+ msg_i2c_add.i2c_device_period = component[" period" ] | 0.0 ;
641
633
}
642
634
643
635
msg_i2c_add.i2c_device_sensor_types_count = 0 ;
0 commit comments