summaryrefslogtreecommitdiff
path: root/src/driver/lm75.cc
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-14 15:51:11 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-14 15:51:11 +0100
commit51a00f59ea9ecb49471b30921f36821fdfa75bc4 (patch)
tree4c237974cf044d5a7067aba48070ad7f6e3c7d11 /src/driver/lm75.cc
parent693afffd7b89507916ecd759767b0b7e947dca60 (diff)
Add I2C and LM75 drivers
Diffstat (limited to 'src/driver/lm75.cc')
-rw-r--r--src/driver/lm75.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/driver/lm75.cc b/src/driver/lm75.cc
new file mode 100644
index 0000000..0bad4a7
--- /dev/null
+++ b/src/driver/lm75.cc
@@ -0,0 +1,30 @@
+#include "driver/lm75.h"
+#include "driver/i2c.h"
+
+float LM75::getTemp()
+{
+ txbuf[0] = 0;
+ rxbuf[0] = 0;
+ rxbuf[1] = 0;
+ i2c.xmit(address, 1, txbuf, 2, rxbuf);
+
+ return rxbuf[0] + (rxbuf[1] / 256.0);
+}
+
+void LM75::setOS(unsigned char os)
+{
+ txbuf[0] = 0x03;
+ txbuf[1] = os;
+ txbuf[2] = 0;
+ i2c.xmit(address, 3, txbuf, 0, rxbuf);
+}
+
+void LM75::setHyst(unsigned char hyst)
+{
+ txbuf[0] = 0x02;
+ txbuf[1] = hyst;
+ txbuf[2] = 0;
+ i2c.xmit(address, 3, txbuf, 0, rxbuf);
+}
+
+LM75 lm75(0x48);