makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / lib / THERMAL / lm75a.cpp
blob76a1c347dae7bf6315f718c82132952340df3ca9
1 #ifdef HAS_THERMAL_LM75A
2 #include "lm75a.h"
3 #include "logging.h"
6 int LM75A::init()
8 uint8_t buffer[5];
10 ReadAccRegister(LM75A_REG_TOS, buffer, 2);
12 DBGLN("thermal lma75 read Tos = 0x%x", buffer[0]);
14 if(buffer[0] == 0)
16 ERRLN("thermal lma75 init failed!");
17 return -1;
20 return 0;
23 uint8_t LM75A::read_lm75a()
25 uint8_t buffer[5];
26 ReadAccRegister(LM75A_REG_TEMP, buffer, 2);
28 // ignore the second byte as it's the decimal part of a degree.
29 return buffer[0];
32 void LM75A::update_lm75a_threshold(uint8_t tos, uint8_t thyst)
34 uint8_t buffer[5];
35 buffer[0] = thyst;
36 buffer[1] = 0;
37 WriteAccRegister(LM75A_REG_THYST, buffer, 2);
39 buffer[0] = tos;
40 buffer[1] = 0;
41 WriteAccRegister(LM75A_REG_TOS, buffer, 2);
44 void LM75A::ReadAccRegister(uint8_t reg, uint8_t *data, int size)
46 Wire.beginTransmission(LM75A_I2C_ADDRESS);
47 Wire.write(reg);
48 Wire.endTransmission();
50 Wire.requestFrom(LM75A_I2C_ADDRESS, size); // request 1 bytes from slave device
51 Wire.readBytes(data, size);
54 void LM75A::WriteAccRegister(uint8_t reg, uint8_t *data, int size)
56 Wire.beginTransmission(LM75A_I2C_ADDRESS);
57 Wire.write(reg);
58 Wire.write(data, size);
59 Wire.endTransmission();
61 #endif