Skip to content

Commit 578b166

Browse files
committed
Run pre-commit
1 parent f2a7437 commit 578b166

File tree

5 files changed

+140
-149
lines changed

5 files changed

+140
-149
lines changed

obc/app/drivers/ina230/ina230.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ static obc_error_code_t initTca6424PinState();
102102
* otherwise returns an appropriate error code
103103
*/
104104
obc_error_code_t initINA230() {
105-
#ifndef USE_MOCK_I2C
106-
i2cReadRegFuncPtr = i2cReadReg;
107-
i2cWriteRegFuncPtr = i2cWriteReg;
108-
#endif
105+
#ifndef USE_MOCK_I2C
106+
i2cReadRegFuncPtr = i2cReadReg;
107+
i2cWriteRegFuncPtr = i2cWriteReg;
108+
#endif
109109
obc_error_code_t errCode;
110110
for (uint8_t i = 0; i < INA230_DEVICE_COUNT; ++i) {
111111
const ina230_config_t device = ina230Devices[i];
@@ -226,13 +226,12 @@ obc_error_code_t getINA230ShuntVoltage(uint8_t i2cAddress, float* shuntVoltage)
226226

227227
// Read the 16-bit shunt voltage register
228228
errCode = i2cReadRegFuncPtr(i2cAddress, INA230_SHUNT_VOLTAGE_REGISTER_ADDR, shuntVoltageRaw, 2,
229-
I2C_TRANSFER_TIMEOUT_TICKS); // last param not sure
229+
I2C_TRANSFER_TIMEOUT_TICKS); // last param not sure
230230
if (errCode != OBC_ERR_CODE_SUCCESS) return errCode;
231231

232232
// Combine the two bytes into a 16-bit value
233233
int16_t shuntVoltageValue = (shuntVoltageRaw[0] << 8) | shuntVoltageRaw[1];
234234

235-
236235
// Convert to actual voltage (signed value)
237236
*shuntVoltage = shuntVoltageValue * INA230_SHUNT_VOLTAGE_LSB;
238237

@@ -320,8 +319,9 @@ obc_error_code_t getINA230BusVoltageForDevice(uint8_t deviceIndex, float* busVol
320319

321320
obc_error_code_t getINA230Power(uint8_t i2cAddress, float* power) {
322321
obc_error_code_t errCode;
323-
if (power == NULL || (i2cAddress != INA230_I2C_ADDRESS_ONE && i2cAddress != INA230_I2C_ADDRESS_TWO)) return OBC_ERR_CODE_INVALID_ARG;
324-
uint8_t powerRaw[INA_REG_CONF_BUFF_SIZE] = {};
322+
if (power == NULL || (i2cAddress != INA230_I2C_ADDRESS_ONE && i2cAddress != INA230_I2C_ADDRESS_TWO))
323+
return OBC_ERR_CODE_INVALID_ARG;
324+
uint8_t powerRaw[INA_REG_CONF_BUFF_SIZE] = {};
325325
RETURN_IF_ERROR_CODE(
326326
i2cReadRegFuncPtr(i2cAddress, INA230_POWER_REGISTER_ADDR, powerRaw, 2, I2C_TRANSFER_TIMEOUT_TICKS));
327327
uint16_t powerValue = (powerRaw[0] << 8) | powerRaw[1];
@@ -338,7 +338,8 @@ obc_error_code_t getINA230PowerForDevice(uint8_t deviceIndex, float* power) {
338338
// function to get current
339339
obc_error_code_t getINA230Current(uint8_t i2cAddress, float* current) {
340340
obc_error_code_t errCode;
341-
if (current == NULL || (i2cAddress != INA230_I2C_ADDRESS_ONE && i2cAddress != INA230_I2C_ADDRESS_TWO)) return OBC_ERR_CODE_INVALID_ARG;
341+
if (current == NULL || (i2cAddress != INA230_I2C_ADDRESS_ONE && i2cAddress != INA230_I2C_ADDRESS_TWO))
342+
return OBC_ERR_CODE_INVALID_ARG;
342343
uint8_t currentRaw[INA_REG_CONF_BUFF_SIZE] = {};
343344
RETURN_IF_ERROR_CODE(
344345
i2cReadRegFuncPtr(i2cAddress, INA230_CURRENT_REGISTER_ADDR, currentRaw, 2, I2C_TRANSFER_TIMEOUT_TICKS));
@@ -353,4 +354,4 @@ obc_error_code_t getINA230CurrentForDevice(uint8_t deviceIndex, float* current)
353354
return getINA230Current(i2cAddress, current);
354355
}
355356

356-
// allow loop through
357+
// allow loop through

obc/app/drivers/ina230/ina230.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ extern "C" {
88
#include <stdint.h>
99

1010
#ifdef USE_MOCK_I2C
11-
#ifndef TICK_TYPE_H
12-
typedef uint32_t TickType_t;
13-
#endif
11+
#ifndef TICK_TYPE_H
12+
typedef uint32_t TickType_t;
13+
#endif
1414
#else
15-
#include "os_portmacro.h"
15+
#include "os_portmacro.h"
1616
#endif
1717

1818
typedef enum { INA230_DEVICE_ONE = 0x00, INA230_DEVICE_TWO, INA230_DEVICE_COUNT } ina230_device_t;
@@ -36,4 +36,4 @@ obc_error_code_t getINA230CurrentForDevice(uint8_t deviceIndex, float* power);
3636

3737
#ifdef __cplusplus
3838
}
39-
#endif
39+
#endif

test/mocks/mock_i2c_hal.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,51 @@ void i2cSend(void* i2c, unsigned char* data, unsigned int length) {}
1515
void i2cReceive(void* i2c, unsigned char* data, unsigned int length) {}
1616
void i2cClearSCD(void* i2c) {}
1717

18-
obc_error_code_t i2cWriteReg(uint8_t sAddr, uint8_t reg, uint8_t *data, uint16_t numBytes) {
19-
// Simulate a successful write
20-
return OBC_ERR_CODE_SUCCESS;
18+
obc_error_code_t i2cWriteReg(uint8_t sAddr, uint8_t reg, uint8_t* data, uint16_t numBytes) {
19+
// Simulate a successful write
20+
return OBC_ERR_CODE_SUCCESS;
2121
}
2222

23-
24-
obc_error_code_t i2cReadReg(uint8_t sAddr, uint8_t reg, uint8_t *data, uint16_t numBytes, TickType_t transferTimeoutTicks) {
25-
if ((sAddr == 0b1000000U || sAddr == 0b1000001U) && numBytes == 2) {
26-
// 0x01 - shunt voltage
27-
// 0x02 - bus voltage
28-
// 0x03 - power
29-
// 0x04 - current
30-
if (reg == 0x01 || reg == 0x02 || reg == 0x03 || reg == 0x04 ) { // Bus voltage register
31-
data[0] = mockData[0]; // High byte
32-
data[1] = mockData[1]; // Low byte
33-
}
34-
return OBC_ERR_CODE_SUCCESS;
23+
obc_error_code_t i2cReadReg(uint8_t sAddr, uint8_t reg, uint8_t* data, uint16_t numBytes,
24+
TickType_t transferTimeoutTicks) {
25+
if ((sAddr == 0b1000000U || sAddr == 0b1000001U) && numBytes == 2) {
26+
// 0x01 - shunt voltage
27+
// 0x02 - bus voltage
28+
// 0x03 - power
29+
// 0x04 - current
30+
if (reg == 0x01 || reg == 0x02 || reg == 0x03 || reg == 0x04) { // Bus voltage register
31+
data[0] = mockData[0]; // High byte
32+
data[1] = mockData[1]; // Low byte
3533
}
36-
// Default mock behavior
3734
return OBC_ERR_CODE_SUCCESS;
35+
}
36+
// Default mock behavior
37+
return OBC_ERR_CODE_SUCCESS;
3838
}
3939

4040
void setMockBusVoltageValue(float expectedVoltage) {
41-
uint16_t expectedVal = (uint16_t)((expectedVoltage / 0.00125f) + 0.5f);
42-
mockData[0] = (0xFF00 & expectedVal) >> 8; // High byte
43-
mockData[1] = 0xFF & expectedVal; // Low bytes
41+
uint16_t expectedVal = (uint16_t)((expectedVoltage / 0.00125f) + 0.5f);
42+
mockData[0] = (0xFF00 & expectedVal) >> 8; // High byte
43+
mockData[1] = 0xFF & expectedVal; // Low bytes
4444
}
4545

4646
void setMockCurrentValue(float expectedCurrent) {
47-
uint16_t expectedVal = expectedCurrent / 0.001f;
48-
mockData[0] = (0xFF00 & expectedVal) >> 8; // High byte
49-
mockData[1] = 0xFF & expectedVal; // Low bytes
47+
uint16_t expectedVal = expectedCurrent / 0.001f;
48+
mockData[0] = (0xFF00 & expectedVal) >> 8; // High byte
49+
mockData[1] = 0xFF & expectedVal; // Low bytes
5050
}
5151

5252
void setMockPowerValue(float expectedPower) {
53-
// add 0.5 to round to the nearest integer (ensures that .5-.9 rounds up instead of truncating the decimal)
54-
uint16_t expectedVal = (uint16_t)((expectedPower / 0.025f) + 0.5f);
55-
mockData[0] = (0xFF00 & expectedVal) >> 8; // High byte
56-
mockData[1] = 0xFF & expectedVal; // Low bytes
53+
// add 0.5 to round to the nearest integer (ensures that .5-.9 rounds up instead of truncating the decimal)
54+
uint16_t expectedVal = (uint16_t)((expectedPower / 0.025f) + 0.5f);
55+
mockData[0] = (0xFF00 & expectedVal) >> 8; // High byte
56+
mockData[1] = 0xFF & expectedVal; // Low bytes
5757
}
5858

5959
void setMockShuntVoltageValue(float expectedShuntVoltage) {
60-
// if expected value is positive, add 0.5; if negative, subtract 0.5
61-
int32_t raw = (int32_t)((expectedShuntVoltage / 0.0000025f) + (expectedShuntVoltage >= 0 ? 0.5f : -0.5f));
62-
uint16_t expectedVal = (uint16_t)raw; // two's complement encoding for negative values
63-
mockData[0] = (expectedVal >> 8) & 0xFF; // High byte
64-
mockData[1] = expectedVal & 0xFF; // Low byte
65-
}
60+
// if expected value is positive, add 0.5; if negative, subtract 0.5
61+
int32_t raw = (int32_t)((expectedShuntVoltage / 0.0000025f) + (expectedShuntVoltage >= 0 ? 0.5f : -0.5f));
62+
uint16_t expectedVal = (uint16_t)raw; // two's complement encoding for negative values
63+
mockData[0] = (expectedVal >> 8) & 0xFF; // High byte
64+
mockData[1] = expectedVal & 0xFF; // Low byte
65+
}

test/mocks/mock_i2c_hal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ void setMockShuntVoltageValue(float expectedPower);
1010

1111
#ifdef __cplusplus
1212
}
13-
#endif
13+
#endif

0 commit comments

Comments
 (0)