2019-05-18 21:04:49 +02:00
|
|
|
#include "knx_facade.h"
|
2019-05-15 21:25:04 +02:00
|
|
|
#include "knx/bau57B0.h"
|
|
|
|
#include "knx/group_object_table_object.h"
|
2019-05-29 22:43:21 +02:00
|
|
|
#include "knx/bits.h"
|
2019-05-15 21:25:04 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2019-08-22 22:57:35 +02:00
|
|
|
KnxFacade<LinuxPlatform, Bau57B0> knx;
|
2019-05-15 21:25:04 +02:00
|
|
|
|
|
|
|
long lastsend = 0;
|
|
|
|
|
2019-08-22 22:57:35 +02:00
|
|
|
#define CURR knx.getGroupObject(1)
|
|
|
|
#define MAX knx.getGroupObject(2)
|
|
|
|
#define MIN knx.getGroupObject(3)
|
|
|
|
#define RESET knx.getGroupObject(4)
|
2019-05-15 21:25:04 +02:00
|
|
|
|
|
|
|
void measureTemp()
|
|
|
|
{
|
2019-08-22 21:31:02 +02:00
|
|
|
long now = millis();
|
2019-05-29 22:43:21 +02:00
|
|
|
if ((now - lastsend) < 10000)
|
2019-05-15 21:25:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
lastsend = now;
|
|
|
|
int r = rand();
|
2019-06-12 00:01:21 +02:00
|
|
|
double currentValue = (r * 1.0) / (RAND_MAX * 1.0);
|
2019-07-15 21:32:00 +02:00
|
|
|
currentValue *= 100;
|
|
|
|
currentValue -= 50;
|
|
|
|
// currentValue *= (670433.28 + 273);
|
|
|
|
// currentValue -= 273;
|
2019-05-29 22:43:21 +02:00
|
|
|
println(currentValue);
|
|
|
|
CURR.value(currentValue);
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2019-05-29 22:43:21 +02:00
|
|
|
double max = MAX.value();
|
|
|
|
if (currentValue > max)
|
|
|
|
MAX.value(currentValue);
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2019-05-29 22:43:21 +02:00
|
|
|
double min = MIN.value();
|
2019-06-12 00:01:21 +02:00
|
|
|
if (currentValue < (double)MIN.value())
|
2019-05-29 22:43:21 +02:00
|
|
|
MIN.value(currentValue);
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void resetCallback(GroupObject& go)
|
|
|
|
{
|
2019-06-12 00:01:21 +02:00
|
|
|
if (go.value())
|
2019-05-15 21:25:04 +02:00
|
|
|
{
|
2019-05-29 22:43:21 +02:00
|
|
|
MAX.valueNoSend(-273.0);
|
|
|
|
MIN.valueNoSend(670433.28);
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void appLoop()
|
|
|
|
{
|
2019-08-22 22:57:35 +02:00
|
|
|
if (!knx.configured())
|
2019-05-15 21:25:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
measureTemp();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
srand((unsigned int)time(NULL));
|
2019-08-22 22:57:35 +02:00
|
|
|
knx.readMemory();
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2019-08-22 22:57:35 +02:00
|
|
|
if (knx.induvidualAddress() == 0)
|
|
|
|
knx.progMode(true);
|
2019-05-15 21:25:04 +02:00
|
|
|
|
2019-08-22 22:57:35 +02:00
|
|
|
if (knx.configured())
|
2019-05-15 21:25:04 +02:00
|
|
|
{
|
2019-05-29 22:43:21 +02:00
|
|
|
CURR.dataPointType(Dpt(9, 1));
|
|
|
|
MIN.dataPointType(Dpt(9, 1));
|
|
|
|
MIN.value(670433.28);
|
|
|
|
MAX.dataPointType(Dpt(9, 1));
|
|
|
|
MAX.valueNoSend(-273.0);
|
|
|
|
RESET.dataPointType(Dpt(1, 15));
|
2019-05-18 21:04:49 +02:00
|
|
|
RESET.callback(resetCallback);
|
2019-08-22 22:57:35 +02:00
|
|
|
printf("Timeout: %d\n", knx.paramWord(0));
|
|
|
|
printf("Zykl. senden: %d\n", knx.paramByte(2));
|
|
|
|
printf("Min/Max senden: %d\n", knx.paramByte(3));
|
|
|
|
printf("Aenderung senden: %d\n", knx.paramByte(4));
|
|
|
|
printf("Abgleich %d\n", knx.paramByte(5));
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
2019-08-22 22:57:35 +02:00
|
|
|
knx.start();
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2019-08-22 22:57:35 +02:00
|
|
|
knx.platform().cmdLineArgs(argc, argv);
|
|
|
|
|
2019-05-15 21:25:04 +02:00
|
|
|
setup();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2019-08-22 22:57:35 +02:00
|
|
|
knx.loop();
|
|
|
|
if(knx.configured())
|
2019-05-18 21:04:49 +02:00
|
|
|
appLoop();
|
2019-08-22 21:31:02 +02:00
|
|
|
delay(100);
|
2019-05-15 21:25:04 +02:00
|
|
|
}
|
|
|
|
}
|