mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
add example to correct folder
This commit is contained in:
parent
809de53cc8
commit
ff5dabad3b
@ -1,57 +1,62 @@
|
|||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "knx_esp.h"
|
#include "knx_esp.h"
|
||||||
|
|
||||||
float currentValue = 0;
|
// declare array of all groupobjects with their sizes in byte
|
||||||
float maxValue = 0;
|
GroupObject groupObjects[]
|
||||||
float minValue = RAND_MAX;
|
{
|
||||||
long lastsend = 0;
|
GroupObject(2),
|
||||||
|
GroupObject(2),
|
||||||
GroupObject groupObjects[]
|
GroupObject(2),
|
||||||
{
|
GroupObject(1)
|
||||||
GroupObject(2),
|
};
|
||||||
GroupObject(2),
|
|
||||||
GroupObject(2),
|
|
||||||
GroupObject(1)
|
|
||||||
};
|
|
||||||
|
|
||||||
GroupObject& goCurrent = groupObjects[0];
|
|
||||||
GroupObject& goMax = groupObjects[1];
|
|
||||||
GroupObject& goMin = groupObjects[2];
|
|
||||||
GroupObject& goReset = groupObjects[3];
|
|
||||||
|
|
||||||
void measureTemp()
|
|
||||||
{
|
|
||||||
long now = millis();
|
|
||||||
if ((now - lastsend) < 2000)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lastsend = now;
|
|
||||||
int r = rand();
|
|
||||||
currentValue = (r * 1.0) / (RAND_MAX * 1.0);
|
|
||||||
currentValue *= 100 * 100;
|
|
||||||
|
|
||||||
goCurrent.objectWriteFloat(currentValue);
|
|
||||||
|
|
||||||
if (currentValue > maxValue)
|
|
||||||
{
|
|
||||||
maxValue = currentValue;
|
|
||||||
goMax.objectWriteFloat(maxValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentValue < minValue)
|
|
||||||
{
|
|
||||||
minValue = currentValue;
|
|
||||||
goMin.objectWriteFloat(minValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetCallback(GroupObject& go)
|
// create named references for easy access to group objects
|
||||||
{
|
GroupObject& goCurrent = groupObjects[0];
|
||||||
if (go.objectReadBool())
|
GroupObject& goMax = groupObjects[1];
|
||||||
{
|
GroupObject& goMin = groupObjects[2];
|
||||||
maxValue = 0;
|
GroupObject& goReset = groupObjects[3];
|
||||||
minValue = 10000;
|
|
||||||
}
|
float currentValue = 0;
|
||||||
|
float maxValue = 0;
|
||||||
|
float minValue = RAND_MAX;
|
||||||
|
long lastsend = 0;
|
||||||
|
|
||||||
|
void measureTemp()
|
||||||
|
{
|
||||||
|
|
||||||
|
long now = millis();
|
||||||
|
if ((now - lastsend) < 2000)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastsend = now;
|
||||||
|
int r = rand();
|
||||||
|
currentValue = (r * 1.0) / (RAND_MAX * 1.0);
|
||||||
|
currentValue *= 100 * 100;
|
||||||
|
|
||||||
|
// write new value to groupobject
|
||||||
|
goCurrent.objectWriteFloat(currentValue);
|
||||||
|
|
||||||
|
if (currentValue > maxValue)
|
||||||
|
{
|
||||||
|
maxValue = currentValue;
|
||||||
|
goMax.objectWriteFloat(maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentValue < minValue)
|
||||||
|
{
|
||||||
|
minValue = currentValue;
|
||||||
|
goMin.objectWriteFloat(minValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// callback from reset-GO
|
||||||
|
void resetCallback(GroupObject& go)
|
||||||
|
{
|
||||||
|
if (go.objectReadBool())
|
||||||
|
{
|
||||||
|
maxValue = 0;
|
||||||
|
minValue = 10000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
@ -59,30 +64,38 @@ void setup()
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.setDebugOutput(true);
|
Serial.setDebugOutput(true);
|
||||||
|
|
||||||
randomSeed(millis());
|
randomSeed(millis());
|
||||||
|
|
||||||
knx.registerGroupObjects(groupObjects, 4);
|
// register group objects
|
||||||
knx.readMemory();
|
knx.registerGroupObjects(groupObjects, 4);
|
||||||
|
// read adress table, association table, groupobject table and parameters from eeprom
|
||||||
goReset.updateHandler = resetCallback;
|
knx.readMemory();
|
||||||
|
|
||||||
if (knx.configured())
|
// register callback for reset GO
|
||||||
{
|
goReset.updateHandler = resetCallback;
|
||||||
Serial.printf("Timeout: %d\n", knx.paramByte(0));
|
|
||||||
Serial.printf("Zykl. senden: %d\n", knx.paramByte(1));
|
// print values of parameters if device is already configured
|
||||||
Serial.printf("Min/Max senden: %d\n", knx.paramByte(2));
|
if (knx.configured())
|
||||||
Serial.printf("Aenderung senden: %d\n", knx.paramByte(3));
|
{
|
||||||
Serial.printf("Abgleich %d\n", knx.paramByte(4));
|
Serial.printf("Timeout: %d\n", knx.paramByte(0));
|
||||||
|
Serial.printf("Zykl. senden: %d\n", knx.paramByte(1));
|
||||||
|
Serial.printf("Min/Max senden: %d\n", knx.paramByte(2));
|
||||||
|
Serial.printf("Aenderung senden: %d\n", knx.paramByte(3));
|
||||||
|
Serial.printf("Abgleich %d\n", knx.paramByte(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start the framework. Will get wifi first.
|
||||||
knx.start();
|
knx.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
knx.loop();
|
// don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS
|
||||||
if (!knx.configured())
|
knx.loop();
|
||||||
return;
|
|
||||||
|
// only run the application code if the device was configured with ETS
|
||||||
|
if (!knx.configured())
|
||||||
|
return;
|
||||||
|
|
||||||
measureTemp();
|
measureTemp();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user