diff --git a/Debug.c b/Debug.c index 5977488..e9f4c11 100755 --- a/Debug.c +++ b/Debug.c @@ -14,7 +14,9 @@ void vprint(const char *fmt, va_list argp) { } #ifdef DO_DEBUG_UART -#define UART_PORT HAL_UART_PORT_0 +#ifndef DEBUG_UART_PORT +#define DEBUG_UART_PORT HAL_UART_PORT_1 +#endif bool DebugInit() { halUARTCfg_t halUARTConfig; halUARTConfig.configured = TRUE; @@ -28,7 +30,7 @@ bool DebugInit() { halUARTConfig.intEnable = TRUE; halUARTConfig.callBackFunc = NULL; HalUARTInit(); - if (HalUARTOpen(UART_PORT, &halUARTConfig) == HAL_UART_SUCCESS) { + if (HalUARTOpen(DEBUG_UART_PORT, &halUARTConfig) == HAL_UART_SUCCESS) { LREPMaster("Initialized debug module \r\n"); return true; } @@ -39,7 +41,7 @@ void LREPMaster(uint8 *data) { if (data == NULL) { return; } - HalUARTWrite(UART_PORT, data, osal_strlen((char *)data)); + HalUARTWrite(DEBUG_UART_PORT, data, osal_strlen((char *)data)); } void LREP(char *format, ...) { diff --git a/Debug.h b/Debug.h index c9ed0a9..c7da137 100755 --- a/Debug.h +++ b/Debug.h @@ -31,7 +31,6 @@ (byte & 0x02 ? '1' : '0'), \ (byte & 0x01 ? '1' : '0') -extern halUARTCfg_t halUARTConfig; void vprint(const char *fmt, va_list argp); extern bool DebugInit(void); diff --git a/air_quality.h b/air_quality.h index a1a0113..73f51b4 100644 --- a/air_quality.h +++ b/air_quality.h @@ -2,9 +2,10 @@ #define AIR_QUALITY_H #define AIR_QUALITY_INVALID_RESPONSE 0xFFFF +#define AIR_QUALITY_ABC_RESPONSE 0xFFF0 typedef void (*request_measure_t)(void); -typedef uint16 (*read_t)(void); +typedef uint16 (*read_t)(uint8 *); typedef void (*set_ABC_t)(bool isEnabled); typedef struct { diff --git a/bettery.c b/battery.c old mode 100755 new mode 100644 similarity index 100% rename from bettery.c rename to battery.c diff --git a/mhz19.c b/mhz19.c index 9c14508..0cb9b64 100644 --- a/mhz19.c +++ b/mhz19.c @@ -6,14 +6,14 @@ #include "hal_uart.h" #ifndef CO2_UART_PORT -#define CO2_UART_PORT HAL_UART_PORT_1 +#define CO2_UART_PORT HAL_UART_PORT_0 #endif #define MHZ18_RESPONSE_LENGTH 13 static void MHZ19_SetABC(bool isEnabled); static void MHZ19_RequestMeasure(void); -static uint16 MHZ19_Read(void); +static uint16 MHZ19_Read(uint8 *response); zclAirSensor_t MHZ19_dev = {&MHZ19_RequestMeasure, &MHZ19_Read, &MHZ19_SetABC}; @@ -34,17 +34,14 @@ void MHZ19_RequestMeasure(void) { HalUARTWrite(CO2_UART_PORT, MHZ19_COMMAND_GET_PPM, sizeof(MHZ19_COMMAND_GET_PPM) / sizeof(MHZ19_COMMAND_GET_PPM[0])); } -uint16 MHZ19_Read(void) { - uint8 response[MHZ18_RESPONSE_LENGTH]; - HalUARTRead(CO2_UART_PORT, (uint8 *)&response, sizeof(response) / sizeof(response[0])); +uint16 MHZ19_Read(uint8 *response) { if (response[0] != 0xFF || response[1] != 0x86) { LREPMaster("MHZ18 Invalid response\r\n"); - HalLedSet(HAL_LED_ALL, HAL_LED_MODE_FLASH); return AIR_QUALITY_INVALID_RESPONSE; } const uint16 ppm = (((uint16)response[2]) << 8) | response[3]; - LREP("MHZ18 Received COâ‚‚=%d ppm\r\n", ppm); + //LREP("MHZ18 Received COâ‚‚=%d ppm\r\n", ppm); return ppm; } \ No newline at end of file diff --git a/senseair.c b/senseair.c index 5bda0e2..ea85557 100644 --- a/senseair.c +++ b/senseair.c @@ -6,11 +6,11 @@ #include "hal_uart.h" #ifndef CO2_UART_PORT -#define CO2_UART_PORT HAL_UART_PORT_1 +#define CO2_UART_PORT HAL_UART_PORT_0 #endif static void SenseAir_RequestMeasure(void); -static uint16 SenseAir_Read(void); +static uint16 SenseAir_Read(uint8 *); static void SenseAir_SetABC(bool isEnabled); extern zclAirSensor_t sense_air_dev = {&SenseAir_RequestMeasure, &SenseAir_Read, &SenseAir_SetABC}; @@ -33,19 +33,30 @@ void SenseAir_RequestMeasure(void) { HalUARTWrite(CO2_UART_PORT, readCO2, sizeof(readCO2) / sizeof(readCO2[0])); } -uint16 SenseAir_Read(void) { - uint8 response[SENSEAIR_RESPONSE_LENGTH]; - HalUARTRead(CO2_UART_PORT, (uint8 *)&response, sizeof(response) / sizeof(response[0])); - +uint16 SenseAir_Read(uint8 *response) { + + LREPMaster("Read startet \r\n"); + + uint8 is_equal = 1; + for (uint8 i=0; i<5; ++i) { + if (response[i] != enableABC[i]) { + is_equal = 0; + break; + } + } + + if (is_equal) + return AIR_QUALITY_ABC_RESPONSE; + if (response[0] != 0xFE || response[1] != 0x04) { LREPMaster("Invalid response\r\n"); return AIR_QUALITY_INVALID_RESPONSE; } const uint8 length = response[2]; - const uint16 status = (((uint16)response[3]) << 8) | response[4]; - const uint16 ppm = (((uint16)response[length + 1]) << 8) | response[length + 2]; - - LREP("SenseAir Received COâ‚‚=%d ppm Status=0x%X\r\n", ppm, status); + //const uint16 status = (((uint16)response[3]) << 8) | response[4]; + uint16 ppm = (((uint16)response[length + 1]) << 8) | response[length + 2]; + //LREP("SenseAir Received CO2=%d ppm Status=0x%X\r\n", ppm, status); + //printf("SenseAir Received CO2=%d ppm Status=0x%X\r\n", ppm, status); return ppm; } \ No newline at end of file diff --git a/us100.c b/us100.c new file mode 100644 index 0000000..d940f50 --- /dev/null +++ b/us100.c @@ -0,0 +1,48 @@ +#include "Debug.h" +#include "us100.h" +#include "OnBoard.h" + +#ifndef US100_UART_PORT +#define US100_UART_PORT HAL_UART_PORT_0 +#endif + + +uint8 readDistance[] = {0x55}; +uint8 readTemp[] = {0x50}; + +void US100_RequestMeasureDistance(void) { + current_phase = DISTANCE_MEASURMENT; + HalUARTWrite(US100_UART_PORT, readDistance, sizeof(readDistance) / sizeof(readDistance[0])); +} +void US100_RequestMeasureTemp(void) { + current_phase = TEMPERATURE_MEASURMENT; + HalUARTWrite(US100_UART_PORT, readTemp, sizeof(readTemp) / sizeof(readTemp[0])); +} + +uint16 US100_ReadDistance(void) +{ + + uint8 response[2]; + HalUARTRead(US100_UART_PORT, (uint8 *)&response, sizeof(response) / sizeof(response[0])); + uint16 mmDist = response[0] * 256 + response[1]; + if((mmDist > 1) && (mmDist < 10000)) + { + printf("Distance=%d\r\n", mmDist); + LREP("Distance=%d \r\n", 0); + return mmDist; + } + return 0; +} + +uint16 US100_ReadTemp(void){ + uint8 response[1]; + HalUARTRead(US100_UART_PORT, (uint8 *)&response, sizeof(response) / sizeof(response[0])); + + uint16 temp = response[0]; + if((temp > 1) && (temp < 130)) // temprature is in range + { + temp -= 45; // correct 45º offset + printf("Temperature=%d\r\n", temp); + } +return temp; +} \ No newline at end of file diff --git a/us100.h b/us100.h new file mode 100644 index 0000000..1297fdf --- /dev/null +++ b/us100.h @@ -0,0 +1,16 @@ +#ifndef us100_h +void US100_RequestMeasureDistance(void); +void US100_RequestMeasureTemp(void); +uint16 US100_ReadDistance(void); +uint16 US100_ReadTemp(void); + +enum { + DISTANCE_MEASURMENT = 0, + TEMPERATURE_MEASURMENT = 1, + NOTHING = 2 +}; + +extern uint8 current_phase; + +#define us100_h +#endif