From 2b04e6f53ca84fad1c5ce92a9c6d77efd4c835d2 Mon Sep 17 00:00:00 2001 From: dooku Date: Sun, 18 Jul 2021 13:48:29 +0200 Subject: [PATCH 1/2] Added prefix (SHT4X, SCD4X) to enums --- fw/Core/Inc/scd4x.h | 10 +++++----- fw/Core/Inc/sht4x.h | 22 +++++++++++----------- fw/Core/Src/scd4x.c | 10 +++++----- fw/Core/Src/sht4x.c | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/fw/Core/Inc/scd4x.h b/fw/Core/Inc/scd4x.h index 5b6726b..e76a6ca 100644 --- a/fw/Core/Inc/scd4x.h +++ b/fw/Core/Inc/scd4x.h @@ -33,11 +33,11 @@ */ typedef enum { - START_PERIODIC_MEASUREMENT = 0x21B1, - READ_MEASUREMENT = 0xEC05, - STOP_PERIODIC_MEASUREMENT = 0x3F86, - GET_DATA_READY_STATUS = 0xe4b8, - PERFORM_FACTORY_RESET = 0x3632 + SCD4X_START_PERIODIC_MEASUREMENT = 0x21B1, + SCD4X_READ_MEASUREMENT = 0xEC05, + SCD4X_STOP_PERIODIC_MEASUREMENT = 0x3F86, + SCD4X_GET_DATA_READY_STATUS = 0xe4b8, + SCD4X_PERFORM_FACTORY_RESET = 0x3632 } scd4x_cmd_t; /* diff --git a/fw/Core/Inc/sht4x.h b/fw/Core/Inc/sht4x.h index a33e6b2..8389107 100644 --- a/fw/Core/Inc/sht4x.h +++ b/fw/Core/Inc/sht4x.h @@ -33,17 +33,17 @@ */ typedef enum { - START_MEAS_HIGH_PRECISION = 0xFD, - START_MEAS_MEDIUM_PRECISION = 0xF6, - START_MEAS_LOW_PRECISION = 0xE0, - READ_SERIAL = 0x89, - SOFT_RESET = 0x94, - HEATER_200_mW_1_s = 0x39, - HEATER_200_mW_01_s = 0x32, - HEATER_110_mW_1_s = 0x2F, - HEATER_110_mW_01_s = 0x24, - HEATER_20_mW_1_s = 0x1E, - HEATER_20_mW_01_s = 0x15 + SHT4X_START_MEAS_HIGH_PRECISION = 0xFD, + SHT4X_START_MEAS_MEDIUM_PRECISION = 0xF6, + SHT4X_START_MEAS_LOW_PRECISION = 0xE0, + SHT4X_READ_SERIAL = 0x89, + SHT4X_SOFT_RESET = 0x94, + SHT4X_HEATER_200_mW_1_s = 0x39, + SHT4X_HEATER_200_mW_01_s = 0x32, + SHT4X_HEATER_110_mW_1_s = 0x2F, + SHT4X_HEATER_110_mW_01_s = 0x24, + SHT4X_HEATER_20_mW_1_s = 0x1E, + SHT4X_HEATER_20_mW_01_s = 0x15 } sht4x_cmd_t; /* diff --git a/fw/Core/Src/scd4x.c b/fw/Core/Src/scd4x.c index b39fcdf..c241ae6 100644 --- a/fw/Core/Src/scd4x.c +++ b/fw/Core/Src/scd4x.c @@ -30,17 +30,17 @@ int8_t scd4x_read_data(uint8_t *buffer, int len) int8_t scd4x_start_periodic_measurement( void ) { - return scd4x_send_cmd(START_PERIODIC_MEASUREMENT); + return scd4x_send_cmd(SCD4X_START_PERIODIC_MEASUREMENT); } int8_t scd4x_stop_periodic_measurement( void ) { - return scd4x_send_cmd(STOP_PERIODIC_MEASUREMENT); + return scd4x_send_cmd(SCD4X_STOP_PERIODIC_MEASUREMENT); } int8_t scd4x_perform_factory_reset( void ) { - return scd4x_send_cmd(PERFORM_FACTORY_RESET); + return scd4x_send_cmd(SCD4X_PERFORM_FACTORY_RESET); } int8_t scd4x_read_measurement(int * co2, int *temperature, int *relative_humidity) @@ -66,8 +66,8 @@ int8_t scd4x_read_measurement(int * co2, int *temperature, int *relative_humidit // start measurement - buffer[0] = READ_MEASUREMENT >> 8; - buffer[1] = READ_MEASUREMENT & 0x00ff; + buffer[0] = SCD4X_READ_MEASUREMENT >> 8; + buffer[1] = SCD4X_READ_MEASUREMENT & 0x00ff; result = i2c_transmit(SCD4X_I2C_ADDRESS<<1, buffer, 2); // TODO: Proc to vraci NACK? Vyresit. diff --git a/fw/Core/Src/sht4x.c b/fw/Core/Src/sht4x.c index f07d94c..263219b 100644 --- a/fw/Core/Src/sht4x.c +++ b/fw/Core/Src/sht4x.c @@ -23,7 +23,7 @@ int8_t sht4x_measure(int *temperature, int *relative_humidity) int result; // start measurement - buffer[0] = START_MEAS_HIGH_PRECISION; + buffer[0] = SHT4X_START_MEAS_HIGH_PRECISION; result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1); // TODO: Proc to vraci NACK? Vyresit. /* From d2f53073ec5332dfa59cc70b41eaa5df44a5cf88 Mon Sep 17 00:00:00 2001 From: dooku Date: Sun, 18 Jul 2021 13:58:35 +0200 Subject: [PATCH 2/2] Changed temperature calculation --- fw/Core/Src/scd4x.c | 2 +- fw/Core/Src/sht4x.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fw/Core/Src/scd4x.c b/fw/Core/Src/scd4x.c index c241ae6..56f1d9a 100644 --- a/fw/Core/Src/scd4x.c +++ b/fw/Core/Src/scd4x.c @@ -88,7 +88,7 @@ int8_t scd4x_read_measurement(int * co2, int *temperature, int *relative_humidit uint32_t co2_ticks = (buffer[0] << 8) + buffer[1]; uint32_t t_ticks = (buffer[3] << 8) + buffer[4]; uint32_t rh_ticks = (buffer[6] << 8) + buffer[7]; - int t_degC = 10*(-45 + 175 * t_ticks / 65535); + int t_degC = -450 + 10 * 175 * t_ticks / 65535; int rh_pRH = 100 * rh_ticks / 65535; if (rh_pRH > 100) { rh_pRH = 100; diff --git a/fw/Core/Src/sht4x.c b/fw/Core/Src/sht4x.c index 263219b..63221fa 100644 --- a/fw/Core/Src/sht4x.c +++ b/fw/Core/Src/sht4x.c @@ -40,7 +40,7 @@ int8_t sht4x_measure(int *temperature, int *relative_humidity) // Convert to T and RH; taken directly from pseudocode in SHT4x datasheet, page 3 uint32_t t_ticks = (buffer[0] << 8) + buffer[1]; uint32_t rh_ticks = (buffer[3] << 8) + buffer[4]; - int t_degC = 10*(-45 + 175 * t_ticks / 65535); + int t_degC = -450 + 10 * 175 * t_ticks / 65535; /* temperature * 10 */ int rh_pRH = -6 + 125 * rh_ticks / 65535; if (rh_pRH > 100) { rh_pRH = 100;