Skip to content

Commit

Permalink
renaming DS18B20 sensor class to reflect the fact that it is now hard…
Browse files Browse the repository at this point in the history
…coded for that specific model
  • Loading branch information
simonrupf committed Aug 6, 2017
1 parent 9bcd576 commit 79213d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@
* a "parasitic" mode over the serial pin, allowing 3 or 2 wire setups.
*/

#include <MonSens_DallasTemperature.h>
#include <MonSens_DS18B20.h>

/**
* Inject the one-wire bus.
*/
void MonSens_DallasTemperature::setWire(OneWire* oneWire) {
void MonSens_DS18B20::setWire(OneWire* oneWire) {
wire = oneWire;
}

/**
* Set the index of the current sensor (optional), if more then one.
*/
void MonSens_DallasTemperature::setIndex(uint8_t index) {
void MonSens_DS18B20::setIndex(uint8_t index) {
sensorIndex = index;
}

/**
* After it is registered in the communicator, the sensor gets initialized.
*/
void MonSens_DallasTemperature::init() {
void MonSens_DS18B20::init() {
}

/**
* Take a sensor reading, to be returned by the communicator.
*/
bool MonSens_DallasTemperature::measure(const char* input) {
bool MonSens_DS18B20::measure(const char* input) {
if (strstr(input, "C") != NULL) {
DeviceAddress deviceAddress;
ScratchPad scratchPad;
Expand All @@ -68,7 +68,7 @@ bool MonSens_DallasTemperature::measure(const char* input) {
}
wire->reset();
wire->select(deviceAddress);
wire->write(STARTCONVO, MONSENS_DALLASTEMPERATURE_PARASITE);
wire->write(STARTCONVO, MonSens_DS18B20_PARASITE);
delay(94);

wire->reset();
Expand Down Expand Up @@ -102,7 +102,7 @@ bool MonSens_DallasTemperature::measure(const char* input) {
/**
* If no sensor supports the input value, usage instructions are collected.
*/
const char* MonSens_DallasTemperature::getUsage() {
return MonSens_DallasTemperature_Usage;
const char* MonSens_DS18B20::getUsage() {
return MonSens_DS18B20_Usage;
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
* a "parasitic" mode over the serial pin, allowing 3 or 2 wire setups.
*/

#ifndef MONSENS_DALLASTEMPERATURE_H
#define MONSENS_DALLASTEMPERATURE_H
#ifndef MonSens_DS18B20_H
#define MonSens_DS18B20_H

#include <MonSens.h>
#include <OneWire.h>

/**
* Is parasite power mode used
*/
#define MONSENS_DALLASTEMPERATURE_PARASITE false
#define MonSens_DS18B20_PARASITE false

// OneWire commands
#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad
Expand All @@ -54,14 +54,14 @@
#define COUNT_PER_C 7
#define SCRATCHPAD_CRC 8

const char MonSens_DallasTemperature_Usage[] PROGMEM = {
const char MonSens_DS18B20_Usage[] PROGMEM = {
"C - temperature in Celsius\r\n"
};

/**
* MonSens implementation of the Dallas 18B20 temperature sensor.
*/
class MonSens_DallasTemperature: public IMonSens_Sensor {
class MonSens_DS18B20: public IMonSens_Sensor {
public:
/**
* Inject the one-wire bus.
Expand Down
4 changes: 2 additions & 2 deletions sensors/ds18b20/monsens-ds18b20-digispark-example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include <MonSens_DigiSpark.h>
MonSens_DigiSpark mcu;

#include <MonSens_DallasTemperature.h>
#include <MonSens_DS18B20.h>

// Digital pin connected to the serial pin of the Dallas temperature sensor
OneWire oneWire(2);
MonSens_DallasTemperature temp;
MonSens_DS18B20 temp;

/**
* initialize DigiSpark and sensors
Expand Down
8 changes: 3 additions & 5 deletions sensors/ds18b20/monsens-ds18b20-esp8266-example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ const int port = 30303;
#include <MonSens_ESP8266.h>
MonSens_ESP8266 mcu;

#include <MonSens_DallasTemperature.h>
#include <MonSens_DS18B20.h>

// Digital pin connected to the serial pin of the Dallas temperature sensor
OneWire oneWire(D4);
DallasTemperature dallas(&oneWire);

MonSens_DallasTemperature temp;
MonSens_DS18B20 temp;

/**
* initialize ESP8266 and sensors
Expand All @@ -40,7 +38,7 @@ void setup() {
mcu.setPort(port);
mcu.init();

temp.setDallas(dallas);
temp.setWire(&oneWire);
mcu.addSensor(temp);
}

Expand Down

0 comments on commit 79213d7

Please sign in to comment.