@@ -474,7 +474,7 @@ uint32_t ws_sdcard::HexStrToInt(const char *hex_str) {
474474*/
475475bool ws_sdcard::ParseUartAdd (JsonObject &component,
476476 wippersnapper_uart_UartAdd &msg_uart_add) {
477- // Configure the Serial
477+ // Configure the UART Serial
478478 msg_uart_add.has_cfg_serial = true ;
479479 snprintf (msg_uart_add.cfg_serial .pin_rx ,
480480 sizeof (msg_uart_add.cfg_serial .pin_rx ), " %d" ,
@@ -493,30 +493,29 @@ bool ws_sdcard::ParseUartAdd(JsonObject &component,
493493 msg_uart_add.cfg_serial .use_sw_serial = component[" useSwSerial" ] | false ;
494494 msg_uart_add.cfg_serial .sw_serial_invert =
495495 component[" swSerialInvert" ] | false ;
496- // Configure the UART device
496+
497+ // Configure the UART Device
497498 msg_uart_add.has_cfg_device = true ;
498499 strncpy (msg_uart_add.cfg_device .device_id ,
499500 component[" deviceId" ] | UNKNOWN_VALUE,
500501 sizeof (msg_uart_add.cfg_device .device_id ) - 1 );
501- // set UartDeviceType
502502 const char *device_type = component[" deviceType" ] | " UNKNOWN" ;
503503 if (strcmp (device_type, " gps" ) == 0 ) {
504504 msg_uart_add.cfg_device .device_type =
505505 wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GPS;
506506 msg_uart_add.cfg_device .which_config =
507507 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 ;
509509 // TODO: We do not have parsing for GPS PMTK or UBX implemented yet
510510 // This is a minimum possible implementation
511- // TODO: We will want to add parsing for GPS PMTK, at least
512511 } else if (strcmp (device_type, " pm25aqi" ) == 0 ) {
513512 msg_uart_add.cfg_device .device_type =
514513 wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_PM25AQI;
515514 msg_uart_add.cfg_device .which_config =
516515 wippersnapper_uart_UartDeviceConfig_pm25aqi_tag;
517- msg_uart_add.cfg_device .config .pm25aqi .period = component[" period" ] | 0.0 ;
518516 msg_uart_add.cfg_device .config .pm25aqi .is_pm1006 =
519517 component[" isPm1006" ] | false ;
518+ msg_uart_add.cfg_device .config .pm25aqi .period = component[" pm25aqi" ][" period" ] | 30.0 ;
520519 // Fill sensor types
521520 pb_size_t sensor_type_count = 0 ;
522521 for (JsonObject sensor_type : component[" sensorTypes" ].as <JsonArray>()) {
@@ -527,16 +526,13 @@ bool ws_sdcard::ParseUartAdd(JsonObject &component,
527526 msg_uart_add.cfg_device .config .pm25aqi .sensor_types_count =
528527 sensor_type_count;
529528 } 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)
532529 msg_uart_add.cfg_device .device_type =
533530 wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GENERIC_INPUT;
534531 msg_uart_add.cfg_device .which_config =
535532 wippersnapper_uart_UartDeviceConfig_generic_uart_input_tag;
536533 msg_uart_add.cfg_device .config .generic_uart_input .line_ending =
537534 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 ;
540536 // Fill sensor types
541537 pb_size_t sensor_type_count = 0 ;
542538 for (JsonObject sensor_type : component[" sensorTypes" ].as <JsonArray>()) {
@@ -599,11 +595,6 @@ bool ws_sdcard::ParseI2cDeviceAddReplace(
599595 wippersnapper_i2c_I2cDeviceAddOrReplace &msg_i2c_add) {
600596 strcpy (msg_i2c_add.i2c_device_name ,
601597 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- }
607598
608599 msg_i2c_add.has_i2c_device_description = true ;
609600 strcpy (msg_i2c_add.i2c_device_description .i2c_bus_scl ,
@@ -630,14 +621,15 @@ bool ws_sdcard::ParseI2cDeviceAddReplace(
630621 const char *mux_channel = component[" i2cMuxChannel" ] | " 0xFFFF" ;
631622 msg_i2c_add.i2c_device_description .i2c_mux_channel = HexStrToInt (mux_channel);
632623
624+ // Set the period
633625 bool is_gps = component[" isGps" ] | false ;
634- WS_DEBUG_PRINT (" [SD] is_gps = " );
635- WS_DEBUG_PRINTLN (is_gps ? " true" : " false" );
636626 if (is_gps) {
637627 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 ;
639629 msg_i2c_add.has_gps_config = true ;
640630 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 ;
641633 }
642634
643635 msg_i2c_add.i2c_device_sensor_types_count = 0 ;
0 commit comments