Skip to content
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

1SirFishy Onboarding #95

Closed
wants to merge 9 commits into from
Closed

Conversation

kepler452b123
Copy link

Purpose

I read instructions and executed instructions

New Changes

Nothing new, except the style

Testing

Absolutely none. Fully confident it works

Outstanding Changes

N.

data sheet and also started working on the
function that reads temperatures from
LM75BD. Positive readings work, but tests say that
the address and negative readings are incorrect."
ure register of the driver is successful. Also
successfully converts the readings to celsius
to static in the driver read function
JUST POINTERS TO FIRST INDEX, NOW PASSING buf1 and buf2
TO I2CSEND AND I2CRECEIVE INSTEAD OF &buf1 AND &buf2) TO
FIX MEANINGLESS TESTING ERRORS
lm75bd/lm75bd.c Outdated Show resolved Hide resolved
@@ -27,8 +27,34 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {
}

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if temp is NULL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this was addressed

lm75bd/lm75bd.c Outdated
buf1[0] = 0b00000000;
i2cSendTo(devAddr, buf1 , 1);
i2cReceiveFrom(devAddr, buf2, 2);
uint16_t tempReading = 0b0000000000000000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use 0 for readabity since 0 = 0b0000000000000000

lm75bd/lm75bd.c Outdated
Comment on lines 39 to 41
tempReading = tempReading | buf2[0];
tempReading = tempReading << 8;
tempReading = tempReading | buf2[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be done in one step instead of splitting it up into 3 just do tempReading |= (buf2[0] << 8) | buf2[1];

lm75bd/lm75bd.c Outdated
Comment on lines 48 to 57
if (tempReading < 1024)
{
*temp = (float)tempReading / 8.0;
}

else
{
tempReading = tempReading ^ 0b0000011111111111;
*temp = (float)((-(tempReading + 1.0)) / 8.0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make tempReading and int you don't need this you can just do *temp = (float)tempReading*0.125

if (event.type == THERMAL_MGR_EVENT_MEASURE_TEMP_CMD)
{
float temp;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the return value to see if the function failed

else if (event.type == THERMAL_MGR_EVENT_CHECK_FOR_INTPT)
{
float temp;
readTempLM75BD(LM75BD_OBC_I2C_ADDR, &temp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the return value to see if the function failed

{
overTemperatureDetected();
}
if (temp <= 75)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just do else since if its not > 75 then it will be <= 75

lm75bd/lm75bd.c Outdated
uint8_t buf1[1];
uint8_t buf2[2];
buf1[0] = 0b00000000;
i2cSendTo(devAddr, buf1 , 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the return value to see if the function failed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the provided logging macros

lm75bd/lm75bd.c Outdated
uint8_t buf2[2];
buf1[0] = 0b00000000;
i2cSendTo(devAddr, buf1 , 1);
i2cReceiveFrom(devAddr, buf2, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the return value to see if the function failed

changing binary representations to integers in driver
functions. Also included error checks, as well as input
validations for pointer arguments. Did not use error functions
such as LOG_IF_ERROR_CODE(functionToCall()) and
RETURN_IF_ERROR_CODE(functionToCall()), as these were
added to the main repo after I had initially forked
and cloned the repo.
Copy link
Contributor

@Navtajh04 Navtajh04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple more things

@@ -27,8 +27,34 @@ error_code_t lm75bdInit(lm75bd_config_t *config) {
}

error_code_t readTempLM75BD(uint8_t devAddr, float *temp) {
/* Implement this driver function */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this was addressed

lm75bd/lm75bd.c Outdated
/* Implement this driver function */
uint8_t bufRead[1];
uint8_t bufWrite[2];
bufRead[0] = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do uint8_t bufRead[1] = {0} when you initialize the array

Comment on lines +33 to +36
if (temp == NULL)
{
return ERR_CODE_INVALID_ARG;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally best to validate the parameters at the top of your function before you do anything else

lm75bd/lm75bd.c Outdated
Comment on lines 37 to 46
error_code_t sendResult = i2cSendTo(devAddr, bufRead , 1);
if (sendResult != ERR_CODE_SUCCESS)
{
return sendResult;
}
error_code_t receiveResult = i2cReceiveFrom(devAddr,bufWrite, 2);
if (receiveResult != ERR_CODE_SUCCESS)
{
return receiveResult;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use RETURN_IF_ERROR_CODE so that these errors gets logged as well

Copy link
Contributor

@Navtajh04 Navtajh04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Navtajh04 Navtajh04 closed this Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants