Skip to content

Commit

Permalink
fixes part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
superkor committed Oct 26, 2024
1 parent 5f1fc62 commit 769405e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
12 changes: 3 additions & 9 deletions lm75bd/lm75bd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {

uint8_t tempPointer = 0x0; //temp pointer reg is set to 0 to specify temperature reading to the device

error_code_t res = i2cSendTo(devAddr, &tempPointer, sizeof(tempPointer)); // write pointer byte 0x0 to the device address for temperature reading
error_code_t errCode = 0;

if (res != ERR_CODE_SUCCESS){
RETURN_IF_ERROR_CODE(res);
}
RETURN_IF_ERROR_CODE(i2cSendTo(devAddr, &tempPointer, sizeof(tempPointer)));// write pointer byte 0x0 to the device address for temperature reading

uint8_t buff[2] = {0, 0}; //0 is MSB, 1 is LSB

res = i2cReceiveFrom(devAddr, buff, sizeof(buff)); //get actual temperature reading

if (res != ERR_CODE_SUCCESS){
RETURN_IF_ERROR_CODE(res);
}
RETURN_IF_ERROR_CODE(i2cReceiveFrom(devAddr, buff, sizeof(buff))); //get actual temperature reading

int16_t val = ((int16_t)(buff[0] << 8 | buff[1]) >> 5);

Expand Down
12 changes: 7 additions & 5 deletions services/thermal_mgr/thermal_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ static void thermalMgr(void *pvParameters) {

thermal_mgr_event_t buffer = {0};


while (1) {
if (xQueueReceive(thermalMgrQueueHandle, &buffer, (TickType_t) portMAX_DELAY) != pdPASS){
continue;
Expand All @@ -81,18 +80,21 @@ static void thermalMgr(void *pvParameters) {
if (buffer.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD){ //temperature reading event
//read temperature
float tempC = 0;
if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC) != ERR_CODE_SUCCESS){
LOG_ERROR("Failed to read temperature sensor\n");
error_code_t res = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC);
if (res != ERR_CODE_SUCCESS){
LOG_ERROR_CODE(res);
continue; //some error occurred
}


addTemperatureTelemetry(tempC); //add to temperature telemetry

} else if (buffer.type == THERMAL_MGR_EVENT_OS_INTERRUPT){
float tempC = 0;
//OS interrupt occurred => T_{th} was reached; Make sure temperature is below T_{hys}!
if (readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC) != ERR_CODE_SUCCESS){
LOG_ERROR("Failed to read temperature sensor\n");
error_code_t res = readTempLM75BD(LM75BD_OBC_I2C_ADDR, &tempC);
if (res != ERR_CODE_SUCCESS){
LOG_ERROR_CODE(res);
continue; //some error occurred
}

Expand Down
2 changes: 1 addition & 1 deletion sys/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL, L

#define RETURN_IF_ERROR_CODE(_ret) \
do { \
error_code_t errCode = _ret; \
errCode = _ret; \
if (errCode != ERR_CODE_SUCCESS) { \
LOG_ERROR_CODE(errCode); \
return errCode; \
Expand Down

0 comments on commit 769405e

Please sign in to comment.