Skip to content

Commit

Permalink
Rename type enum to avoid name conflict on Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
monkbroc committed Jan 23, 2017
1 parent 7f70a0a commit 320eb2e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
# git config --global core.excludesfile '~/.gitignore_global'

.DS_Store

*.bin
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ See the datasheet for your device to decode this.

`DS18Type type = sensor.type();`

The type of the last read device. One of `TYPE_DS1820`, `TYPE_DS18B20`, `TYPE_DS1822`, `TYPE_DS2438` or `TYPE_UNKNOWN` if the device is not a temperature sensor, no device was found or the search is done.
The type of the last read device. One of `WIRE_DS1820`, `WIRE_DS18B20`, `WIRE_DS1822`, `WIRE_DS2438` or `WIRE_UNKNOWN` if the device is not a temperature sensor, no device was found or the search is done.

## `raw()`

Expand Down
8 changes: 4 additions & 4 deletions examples/DS18x20_Temperature/DS18x20_Temperature.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void printDebugInfo() {
// Print the sensor type
const char *type;
switch(sensor.type()) {
case TYPE_DS1820: type = "DS1820"; break;
case TYPE_DS18B20: type = "DS18B20"; break;
case TYPE_DS1822: type = "DS1822"; break;
case TYPE_DS2438: type = "DS2438"; break;
case WIRE_DS1820: type = "DS1820"; break;
case WIRE_DS18B20: type = "DS18B20"; break;
case WIRE_DS1822: type = "DS1822"; break;
case WIRE_DS2438: type = "DS2438"; break;
default: type = "UNKNOWN"; break;
}
Serial.print(type);
Expand Down
24 changes: 12 additions & 12 deletions src/DS18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void DS18::init() {
_celsius = 0;
memset(_addr, 0, sizeof(_addr));
memset(_data, 0, sizeof(_data));
_type = TYPE_UNKNOWN;
_type = WIRE_UNKNOWN;
_searchDone = false;
_crcError = false;
}
Expand Down Expand Up @@ -50,11 +50,11 @@ bool DS18::read(uint8_t addr[8]) {
// the first ROM byte indicates which chip
// Return if this is an unknown chip
switch (addr[0]) {
case 0x10: _type = TYPE_DS1820; break;
case 0x28: _type = TYPE_DS18B20; break;
case 0x22: _type = TYPE_DS1822; break;
case 0x26: _type = TYPE_DS2438; break;
default: _type = TYPE_UNKNOWN; return false;
case 0x10: _type = WIRE_DS1820; break;
case 0x28: _type = WIRE_DS18B20; break;
case 0x22: _type = WIRE_DS1822; break;
case 0x26: _type = WIRE_DS2438; break;
default: _type = WIRE_UNKNOWN; return false;
}

// Read the actual temperature!!!
Expand Down Expand Up @@ -85,7 +85,7 @@ bool DS18::read(uint8_t addr[8]) {
_wire.reset();
_wire.select(_addr);
_wire.write(0xBE,0); // Read Scratchpad
if (_type == TYPE_DS2438) {
if (_type == WIRE_DS2438) {
_wire.write(0x00,0); // The DS2438 needs a page# to read
}

Expand All @@ -105,22 +105,22 @@ bool DS18::read(uint8_t addr[8]) {
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
_raw = (_data[1] << 8) | _data[0];
if (_type == TYPE_DS2438) {
if (_type == WIRE_DS2438) {
_raw = (_data[2] << 8) | _data[1];
}
byte cfg = (_data[4] & 0x60);

switch (_type) {
case TYPE_DS1820:
case WIRE_DS1820:
_raw = _raw << 3; // 9 bit resolution default
if (_data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
_raw = (_raw & 0xFFF0) + 12 - _data[6];
}
_celsius = (float)_raw * 0.0625;
break;
case TYPE_DS18B20:
case TYPE_DS1822:
case WIRE_DS18B20:
case WIRE_DS1822:
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) _raw = _raw & ~7; // 9 bit resolution, 93.75 ms
if (cfg == 0x20) _raw = _raw & ~3; // 10 bit res, 187.5 ms
Expand All @@ -129,7 +129,7 @@ bool DS18::read(uint8_t addr[8]) {
_celsius = (float)_raw * 0.0625;
break;

case TYPE_DS2438:
case WIRE_DS2438:
_data[1] = (_data[1] >> 3) & 0x1f;
if (_data[2] > 127) {
_celsius = (float)_data[2] - ((float)_data[1] * .03125);
Expand Down
12 changes: 6 additions & 6 deletions src/DS18.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include "OneWire.h"

enum DS18Type {
TYPE_UNKNOWN,
TYPE_DS1820,
TYPE_DS18B20,
TYPE_DS1822,
TYPE_DS2438
WIRE_UNKNOWN,
WIRE_DS1820,
WIRE_DS18B20,
WIRE_DS1822,
WIRE_DS2438
};

class DS18 {
Expand All @@ -31,7 +31,7 @@ class DS18 {

private:
void init();

OneWire _wire;
bool _parasitic;
uint16_t _conversionTime;
Expand Down
17 changes: 17 additions & 0 deletions verification.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Test powered sensor

Connect a DS18B20 temperature sensor to a Photon on a breadboard.
Connect pin 1 to D3, pin 2 to D4, pin 3 to D5, 10 k ohm resistor between pin 2 and 3.
Flash DS18x20_Temperature.ino example.
Open serial conenction and check that the temperature is read.

Repeat for Core and Electron

# Test parasitic sensor

Connect a DS18B20-PAR temperature sensor to a Photon on a breadboard.
Connect pin 1 to GND, pin 2 to D4, pin 3 to VIN, 1.5 k ohm resistor between pin 2 and VIN.
Flash DS18x20_Temperature.ino example.
Open serial conenction and check that the temperature is read.

Repeat for Core and Electron

0 comments on commit 320eb2e

Please sign in to comment.