Line data Source code
1 : /**
2 : * @file LM75Node.cpp
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "timing/LM75Node.hpp"
10 :
11 : // PDT headers
12 : #include "ers/ers.hpp"
13 : #include "timing/toolbox.hpp"
14 :
15 : #include <vector>
16 : // #include <fstream>
17 : // #include <sstream>
18 :
19 : namespace dunedaq {
20 : namespace timing {
21 :
22 : //-----------------------------------------------------------------------------
23 0 : LM75Node::LM75Node(const I2CMasterNode* i2c_master, uint8_t address) // NOLINT(build/unsigned)
24 0 : : I2CSlave(i2c_master, address)
25 0 : {}
26 : //-----------------------------------------------------------------------------
27 :
28 : //-----------------------------------------------------------------------------
29 0 : LM75Node::~LM75Node() {}
30 : //-----------------------------------------------------------------------------
31 :
32 : //-----------------------------------------------------------------------------
33 : float
34 0 : LM75Node::read_temperature() const
35 : {
36 0 : std::vector<uint8_t> temp_bytes = this->read_i2cPrimitive(2); // NOLINT(build/unsigned)
37 0 : uint16_t temp_raw = (temp_bytes[1] & 0x80) >> 7;
38 0 : temp_raw = temp_raw | (temp_bytes[0] << 1);
39 :
40 : // 1s padding for negative values
41 0 : if (temp_raw & 0x0100)
42 : {
43 0 : temp_raw = temp_raw | 0xfe00;
44 : }
45 0 : int16_t temp = static_cast<int16_t>(temp_raw);
46 :
47 0 : TLOG_DEBUG(13) << "LM75 temp data - "
48 0 : << "raw bytes: 0x" << std::hex << (uint)temp_bytes[0] << ", 0x" << (uint)temp_bytes[1] // NOLINT(build/unsigned)
49 0 : << ", combined word: 0x" << temp_raw
50 0 : << ", temp [C]: " << temp*0.5;
51 0 : return temp*0.5;
52 0 : }
53 : //-----------------------------------------------------------------------------
54 :
55 : } // namespace timing
56 : } // namespace dunedaq
|