Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Arduino.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "OWI.h"
3 #include "Slave/OWI.h"
4 #include "Driver/Arduino.h"
5 
8 
13 void setup()
14 {
15  owi.alarm(true);
16 }
17 
21 void loop()
22 {
23  // Additional sketch code could be placed here before
24  // polling one-wire bus for commands
25  if (!owi.rom_command()) return;
26 
27  const size_t BUF_MAX = 32;
28  uint8_t buf[BUF_MAX];
29  uint16_t value;
30  uint8_t pin;
31  uint8_t mode;
32  uint8_t* bp;
33  uint8_t count;
34  uint8_t res;
35  uint8_t duty;
36 
37  // Read and dispatch remote arduino commands
38  switch (owi.read_command()) {
39  case Arduino::PIN_MODE:
40  pin = owi.read(6);
41  mode = owi.read(2);
42  pinMode(pin, mode);
43  break;
45  pin = owi.read(6);
46  value = digitalRead(pin);
47  owi.write(value, 1);
48  break;
50  pin = owi.read(6);
51  value = owi.read(1);
52  digitalWrite(pin, value);
53  break;
55  pin = owi.read(6);
56  value = analogRead(pin);
57  owi.alarm(value > 512);
58  owi.write(&value, sizeof(value));
59  break;
61  pin = owi.read(6);
62  duty = owi.read();
63  analogWrite(pin, duty);
64  break;
65  case Arduino::SRAM_READ:
66  owi.read(&bp, sizeof(bp));
67  count = owi.read();
68  owi.write(bp, count);
69  break;
71  owi.read(&bp, sizeof(bp));
72  count = owi.read();
73  owi.read(bp, count + 1);
74  break;
76  owi.read(&bp, sizeof(bp));
77  count = owi.read();
78  owi.crc(0);
79  while (count--) owi.write(eeprom_read_byte(bp++));
80  owi.write(owi.crc());
81  break;
83  owi.read(&bp, sizeof(bp));
84  count = owi.read();
85  res = 0b00;
86  if (count > BUF_MAX) {
87  while (count--) owi.read();
88  owi.read();
89  }
90  else if (owi.read(buf, count)) {
91  eeprom_write_block(buf, bp, count);
92  res = 0b10;
93  }
94  owi.write(res, 2);
95  break;
97  owi.write(NUM_DIGITAL_PINS, 6);
98  break;
100  owi.write(NUM_ANALOG_INPUTS, 6);
101  break;
102  }
103 }
Read digital pin: 6b pin, 1b return.
Definition: Arduino.h:222
Software::OWI< BOARD::D7 > owi
Definition: Arduino.ino:9
static const uint8_t FAMILY_CODE
Definition: Arduino.h:38
Definition: OWI.h:33
Get number of analog inputs: 6b return.
Definition: Arduino.h:231
Write analog pin: 6b pin, 8b duty.
Definition: Arduino.h:225
void setup()
Definition: Arduino.ino:12
Set pin mode: 6b pin, 2b mode.
Definition: Arduino.h:221
const int pin
Definition: DS18B20.ino:44
SRAM read.
Definition: Arduino.h:226
Write digital pin: 6b pin, 1b value.
Definition: Arduino.h:223
Get number of digital pins: 6b return.
Definition: Arduino.h:230
SRAM write.
Definition: Arduino.h:227
Read analog pin: 6b pin, 16b+8b return.
Definition: Arduino.h:224
EEPROM read.
Definition: Arduino.h:228
void loop()
Definition: Arduino.ino:63
EEPROM write.
Definition: Arduino.h:229