Files
EMS-ESP32/src/ds18.h
proddy d671e64c5f 1.6
2019-03-24 21:13:08 +01:00

55 lines
1.3 KiB
C++

/*
* Dallas support for external temperature sensors
* Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
*
* Paul Derbyshire - https://github.com/proddy/EMS-ESP
*
*/
#pragma once
#include <OneWire.h>
#include <vector>
#define DS18_CHIP_DS18S20 0x10
#define DS18_CHIP_DS1822 0x22
#define DS18_CHIP_DS18B20 0x28
#define DS18_CHIP_DS1825 0x3B
#define DS18_DATA_SIZE 9
#define DS18_DISCONNECTED -127
#define DS18_CRC_ERROR -126
#define GPIO_NONE 0x99
#define DS18_READ_INTERVAL 2000 // Force sensor read & cache every 2 seconds
#define DS18_CMD_START_CONVERSION 0x44
#define DS18_CMD_READ_SCRATCHPAD 0xBE
typedef struct {
uint8_t address[8];
uint8_t data[DS18_DATA_SIZE];
} ds_device_t;
class DS18 {
public:
DS18();
~DS18();
uint8_t setup(uint8_t gpio, bool parasite);
void loop();
char * getDeviceString(char * s, unsigned char index);
double getValue(unsigned char index);
int16_t getRawValue(unsigned char index); // raw values, needs / 16
protected:
bool validateID(unsigned char id);
unsigned char chip(unsigned char index);
uint8_t loadDevices();
OneWire * _wire;
uint8_t _count; // # devices
uint8_t _gpio; // the sensor pin
uint8_t _parasite; // parasite mode
};