Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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, ...) {
Expand Down
1 change: 0 additions & 1 deletion Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion air_quality.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
0 bettery.c → battery.c
100755 → 100644
File renamed without changes.
11 changes: 4 additions & 7 deletions mhz19.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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;
}
31 changes: 21 additions & 10 deletions senseair.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
}
48 changes: 48 additions & 0 deletions us100.c
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 16 additions & 0 deletions us100.h
Original file line number Diff line number Diff line change
@@ -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