Skip to content

Commit

Permalink
Refactoring hardware bus manager support
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelpatel committed Oct 10, 2017
1 parent 4d6cfe1 commit d710ca5
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 475 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ based software and DS2482 based hardware bus manager, and device
driver for DS18B20.

The examples directory contains device search, bus scanner,
thermometer alarm search, and example sketches for DS18B20, DS1990A
and DS2482.
thermometer alarm search, and example sketches for DS18B20 and
DS1990A.

Version: 1.6
Version: 1.7

## Classes

* [Abstract One-Wire Bus Manager and Device Interface, OWI](./src/OWI.h)
* [Software One-Wire Bus Manager, GPIO, Software::OWI](./src/Software/OWI.h)
* [Hardware One-Wire Bus Manager, DS2482, Hardware::OWI](./src/Hardware/OWI.h)
* [Programmable Resolution 1-Wire Digital Thermometer, DS18B20](./src/Driver/DS18B20.h)

## Example Sketches

* [DS18B20](./examples/DS18B20)
* [DS1990A](./examples/DS1990A)
* [DS2482](./examples/DS2482)
* [Alarm](./examples/Alarm)
* [Scanner](./examples/Scanner)
* [Search](./examples/Search)
Expand Down
21 changes: 17 additions & 4 deletions examples/Alarm/Alarm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
Software::OWI<BOARD::D7> owi;

#else
#include "TWI.h"
#include "Hardware/OWI.h"
// Configure: Software/Hardware TWI Bus Manager
// #define USE_SOFTWARE_TWI
#if defined(USE_SOFTWARE_TWI)
#include "Software/TWI.h"
#if defined(SAM)
Software::TWI<BOARD::D8,BOARD::D9> twi;
#else
Software::TWI<BOARD::D18,BOARD::D19> twi;
#endif
#else
#include "Hardware/TWI.h"
Hardware::TWI twi;
Expand All @@ -24,6 +29,16 @@ Hardware::OWI owi(twi);

DS18B20 sensor(owi);

#define ASSERT(expr) \
do { \
if (!(expr)) { \
Serial.print(__LINE__); \
Serial.println(F(":assert:" #expr)); \
Serial.flush(); \
exit(0); \
} \
} while (0)

void setup()
{
Serial.begin(57600);
Expand All @@ -38,7 +53,7 @@ void setup()
if (last == owi.ERROR) break;
sensor.resolution(10);
sensor.set_trigger(20, 25);
sensor.write_scratchpad();
ASSERT(sensor.write_scratchpad());
} while (last != owi.LAST);
}

Expand All @@ -50,16 +65,14 @@ void loop()

int8_t last = owi.FIRST;
uint8_t* rom = sensor.rom();
bool triggered = false;
static uint16_t timestamp = 0;
uint8_t id = 0;
if (!sensor.convert_request(true)) return;
delay(sensor.conversion_time());
do {
last = owi.alarm_search(rom, last);
if (last == owi.ERROR) break;
triggered = true;
sensor.read_scratchpad(false);
ASSERT(sensor.read_scratchpad(false));
Serial.print(timestamp);
Serial.print('.');
Serial.print(id++);
Expand Down
19 changes: 17 additions & 2 deletions examples/DS18B20/DS18B20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
Software::OWI<BOARD::D7> owi;

#else
#include "Hardware/OWI.h"
// Configure: Software/Hardware TWI Bus Manager
// #define USE_SOFTWARE_TWI
#include "TWI.h"
#include "Hardware/OWI.h"
#if defined(USE_SOFTWARE_TWI)
#include "Software/TWI.h"
#if defined(SAM)
Software::TWI<BOARD::D8,BOARD::D9> twi;
#else
Software::TWI<BOARD::D18,BOARD::D19> twi;
#endif
#else
#include "Hardware/TWI.h"
Hardware::TWI twi;
Expand All @@ -24,6 +29,16 @@ Hardware::OWI owi(twi);

DS18B20 sensor(owi);

#define ASSERT(expr) \
do { \
if (!(expr)) { \
Serial.print(__LINE__); \
Serial.println(F(":assert:" #expr)); \
Serial.flush(); \
exit(0); \
} \
} while (0)

void setup()
{
Serial.begin(57600);
Expand All @@ -47,7 +62,7 @@ void loop()
if (last == owi.ERROR) break;

// Read the scratchpad with current temperature, tiggers, etc
sensor.read_scratchpad(false);
ASSERT(sensor.read_scratchpad(false));
int8_t low, high;
sensor.get_trigger(low, high);

Expand Down
122 changes: 0 additions & 122 deletions examples/DS2482/DS2482.ino

This file was deleted.

7 changes: 6 additions & 1 deletion examples/Scanner/Scanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
Software::OWI<BOARD::D7> owi;

#else
#include "Hardware/OWI.h"
// Configure: Software/Hardware TWI Bus Manager
// #define USE_SOFTWARE_TWI
#include "TWI.h"
#include "Hardware/OWI.h"
#if defined(USE_SOFTWARE_TWI)
#include "Software/TWI.h"
#if defined(SAM)
Software::TWI<BOARD::D8,BOARD::D9> twi;
#else
Software::TWI<BOARD::D18,BOARD::D19> twi;
#endif
#else
#include "Hardware/TWI.h"
Hardware::TWI twi;
Expand Down
7 changes: 6 additions & 1 deletion examples/Search/Search.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
Software::OWI<BOARD::D7> owi;

#else
#include "Hardware/OWI.h"
// Configure: Software/Hardware TWI Bus Manager
// #define USE_SOFTWARE_TWI
#include "TWI.h"
#include "Hardware/OWI.h"
#if defined(USE_SOFTWARE_TWI)
#include "Software/TWI.h"
#if defined(SAM)
Software::TWI<BOARD::D8,BOARD::D9> twi;
#else
Software::TWI<BOARD::D18,BOARD::D19> twi;
#endif
#else
#include "Hardware/TWI.h"
Hardware::TWI twi;
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Arduino-OWI
version=1.6
version=1.7
author=Mikael Patel
maintainer=Mikael Patel <[email protected]>
sentence=One-Wire Interface (OWI) library for Arduino.
Expand Down
2 changes: 1 addition & 1 deletion mainpage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The OWI library has been developed to support the implementation of
based Software::OWI bus manager, DS2482 based Hardware::OWI bus
manager, and device driver for DS18B20.

Version: 1.6
Version: 1.7
*/

/** @page License
Expand Down
Loading

0 comments on commit d710ca5

Please sign in to comment.