-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Successfully completed the Onboarding Challenge #160
base: level3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,27 @@ error_code_t lm75bdInit(lm75bd_config_t *config) { | |
|
||
error_code_t readTempLM75BD(uint8_t devAddr, float *temp) { | ||
/* Implement this driver function */ | ||
error_code_t errCode; | ||
|
||
uint8_t pointerRegister = 0x00; | ||
uint8_t tempData[2]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generally a good idea to initialize all variables. |
||
int16_t rawTemperature; | ||
|
||
i2cSendTo(devAddr, &pointerRegister, sizeof(pointerRegister)); | ||
i2cReceiveFrom(devAddr, tempData, sizeof(tempData)); | ||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be wrapped inside of the RETURN_IF_ERROR_CODE macro |
||
|
||
rawTemperature = (tempData[0] << 8) | tempData[1]; | ||
//discards the 5 least significant bits | ||
rawTemperature >>= 5; | ||
if (rawTemperature & 0x0400) { | ||
// If the 11th bit is set, take the two's complement of the 11-bit number | ||
rawTemperature |= 0xF800; | ||
*temp = rawTemperature * 0.125; | ||
} else { | ||
// If the 11th bit is not set, temperature is positive | ||
*temp = rawTemperature * 0.125; | ||
} | ||
Comment on lines
+42
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is redundant, just do multiplication and store it |
||
|
||
return ERR_CODE_SUCCESS; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,19 +42,37 @@ void initThermalSystemManager(lm75bd_config_t *config) { | |
} | ||
|
||
error_code_t thermalMgrSendEvent(thermal_mgr_event_t *event) { | ||
/* Send an event to the thermal manager queue */ | ||
|
||
xQueueSend(thermalMgrQueueHandle, event, portMAX_DELAY); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of things need to be changed here
|
||
return ERR_CODE_SUCCESS; | ||
} | ||
|
||
void osHandlerLM75BD(void) { | ||
/* Implement this function */ | ||
thermal_mgr_event_type_t event = THERMAL_MGR_EVENT_INTERUPT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is of type |
||
xQueueSend(thermalMgrQueueHandle, &event, 0); | ||
} | ||
|
||
static void thermalMgr(void *pvParameters) { | ||
/* Implement this task */ | ||
while (1) { | ||
|
||
thermal_mgr_event_t pvbuffer; | ||
if(xQueueReceive(thermalMgrQueueHandle, &pvbuffer, portMAX_DELAY)) { | ||
if (pvbuffer.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an else clause that logs a custom error code for invalid events received |
||
float temp; | ||
lm75bd_config_t config = *(lm75bd_config_t *) pvParameters; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull this to be before the loop |
||
readTempLM75BD(config.devAddr, &temp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOG_IF_ERROR_CODE followed by a if(errCode != success) continue; line |
||
addTemperatureTelemetry(temp); | ||
} | ||
if (pvbuffer.type == THERMAL_MGR_EVENT_INTERUPT) { | ||
float temp; | ||
lm75bd_config_t config = *(lm75bd_config_t *) pvParameters; | ||
readTempLM75BD(config.devAddr, &temp); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here |
||
if(temp > config.overTempThresholdCelsius) { | ||
overTemperatureDetected(); | ||
} else if (temp < config.hysteresisThresholdCelsius) { | ||
safeOperatingConditions(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
typedef enum { | ||
THERMAL_MGR_EVENT_MEASURE_TEMP_CMD, | ||
THERMAL_MGR_EVENT_INTERUPT, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this name more descriptive by including OS or OVER_TEMP inside of it |
||
|
||
} thermal_mgr_event_type_t; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the temp is not null before use