Arduino-OWI
One-Wire Interface (OWI) library for Arduino
OWI.h
Go to the documentation of this file.
1 
19 #ifndef HARDWARE_OWI_H
20 #define HARDWARE_OWI_H
21 
22 #include "OWI.h"
23 #include "Driver/DS2482.h"
24 
29 namespace Hardware {
30 class OWI : public ::OWI {
31 public:
37  OWI(TWI& twi, uint8_t subaddr = 0) :
38  m_bridge(twi, 0x18 | (subaddr & 0x03))
39  {
40  }
41 
48  virtual bool reset()
49  {
50  return (m_bridge.one_wire_reset());
51  }
52 
60  virtual uint8_t read(uint8_t bits = CHARBITS)
61  {
62  uint8_t res = 0;
63  if (bits == CHARBITS) {
64  m_bridge.one_wire_read_byte(res);
65  }
66  else {
67  uint8_t adjust = CHARBITS - bits;
68  bool value = 0;
69  while (bits--) {
70  res >>= 1;
71  m_bridge.one_wire_read_bit(value);
72  res |= (value ? 0x80 : 0x00);
73  }
74  res >>= adjust;
75  }
76  return (res);
77  }
78 
86  virtual void write(uint8_t value, uint8_t bits = CHARBITS)
87  {
88  if (bits == CHARBITS) {
89  m_bridge.one_wire_write_byte(value);
90  }
91  else {
92  while (bits--) {
93  m_bridge.one_wire_write_bit(value & 0x01);
94  value >>= 1;
95  }
96  }
97  }
98 
108  virtual int8_t triplet(uint8_t& dir)
109  {
110  return (m_bridge.one_wire_triplet(dir));
111  }
112 
119  {
120  return (m_bridge.device_reset());
121  }
122 
131  bool device_configuration(bool apu = true, bool spu = false, bool iws = false)
132  {
133  return (m_bridge.write_configuration(apu, spu, iws));
134  }
135 
142  bool channel_select(uint8_t chan)
143  {
144  return (m_bridge.channel_select(chan));
145  }
146 
147 protected:
148  DS2482 m_bridge;
149 };
150 };
151 #endif
bool device_configuration(bool apu=true, bool spu=false, bool iws=false)
Definition: OWI.h:131
OWI(TWI &twi, uint8_t subaddr=0)
Definition: OWI.h:37
virtual int8_t triplet(uint8_t &dir)
Definition: OWI.h:108
Definition: OWI.h:29
DS2482 m_bridge
Definition: OWI.h:148
bool device_reset()
Definition: OWI.h:118
bool channel_select(uint8_t chan)
Definition: OWI.h:142
virtual void write(uint8_t value, uint8_t bits=CHARBITS)
Definition: OWI.h:86
virtual uint8_t read(uint8_t bits=CHARBITS)
Definition: OWI.h:60
virtual bool reset()
Definition: OWI.h:48
#define CHARBITS
Definition: OWI.h:23
Hardware::TWI twi
Definition: Alarm.ino:9