Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions devices/example-ds18s20/Impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../features/DS18S20.h"
#include "Device.h"


constexpr const char DS18S20_NAME[] = "ds18s20";
const uint8_t DS18S20_GPIO = 0;

class DS18S20Device : public Device {
public:
DS18S20Device() :
ds18s20(this)
{
this->add(&(this->ds18s20));
}

private:
DS18S20Sensor<DS18S20_NAME, DS18S20_GPIO> ds18s20;
};


Device* createDevice() {
return new DS18S20Device();
}


50 changes: 50 additions & 0 deletions framework/features/DS18S20.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef DS1820SENSOR_H
#define DS1820SENSOR_H

#include "Feature.h"

#include <Libraries/OneWire/OneWire.h>
#include <Libraries/DS18S20/ds18s20.h>


template<const char* const name, int gpio>
class DS18S20Sensor : public Feature<name> {

protected:
DS18S20 ds18s20;

public:
DS18S20Sensor(Device* device) : Feature<name>(device) {
this->ds18s20.Init(gpio);
this->ds18s20.RegisterEndCallback(DS18S20CompletedDelegate(&DS18S20Sensor::measureCompleted, this));

for (int i = 0; i < this->ds18s20.GetSensorsCount(); i++) {
const uint64_t id = this->ds18s20.GetSensorID(i);
sprintf(this->topics[i], "%08X-%08X/temperature", (uint32_t)(id>>32), (uint32_t)(id>>0));
}

this->updateTimer.initializeMs(15000, TimerDelegate(&DS18S20::StartMeasure, &this->ds18s20));
this->updateTimer.start(true);
}

protected:
void publishCurrentState() {
}

private:
void measureCompleted() {
for(int i = 0; i < this->ds18s20.GetSensorsCount(); i++) {
if (this->ds18s20.IsValidTemperature(i)) {
const float temperature = this->ds18s20.GetCelsius(i);
this->publish(this->topics[i], String(temperature), true);
}
}
}

char topics[MAX_SENSORS][42];

Timer updateTimer;
};


#endif