mirror of
https://github.com/thelsing/knx.git
synced 2026-02-23 13:50:35 +01:00
move main.cpp, document SaveRestore
This commit is contained in:
@@ -1,10 +1,28 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/**
|
||||
*@brief Interface for classes that can save and restore data from a buffer.
|
||||
*/
|
||||
class SaveRestore
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief This method is called when the object should save its state to the buffer.
|
||||
*
|
||||
* @param buffer The buffer the object should save its state to.
|
||||
*
|
||||
* @return The buffer plus the size of the object state. The next object will use this value as
|
||||
* the start of its buffer.
|
||||
*/
|
||||
virtual uint8_t* save(uint8_t* buffer) = 0;
|
||||
/**
|
||||
* @brief This method is called when the object should restore its state from the buffer.
|
||||
*
|
||||
* @param buffer The buffer the object should restore its state from.
|
||||
*
|
||||
* @return The buffer plus the size of the object state. The next object will use this value as
|
||||
* the start of its buffer.
|
||||
*/
|
||||
virtual uint8_t* restore(uint8_t* buffer) = 0;
|
||||
};
|
||||
100
src/main.cpp
100
src/main.cpp
@@ -1,100 +0,0 @@
|
||||
#ifdef __linux__
|
||||
|
||||
#include "linux_platform.h"
|
||||
#include "knx/bau57B0.h"
|
||||
#include "knx/group_object_table_object.h"
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
LinuxPlatform platfrom;
|
||||
Bau57B0 bau(platfrom);
|
||||
|
||||
float currentValue = 0;
|
||||
float maxValue = 0;
|
||||
float minValue = RAND_MAX;
|
||||
long lastsend = 0;
|
||||
|
||||
#define CURR bau.groupObjectTable().get(1)
|
||||
#define MAX bau.groupObjectTable().get(2)
|
||||
#define MIN bau.groupObjectTable().get(3)
|
||||
#define RESET bau.groupObjectTable().get(4)
|
||||
|
||||
void measureTemp()
|
||||
{
|
||||
long now = platfrom.millis();
|
||||
if ((now - lastsend) < 2000)
|
||||
return;
|
||||
|
||||
lastsend = now;
|
||||
int r = rand();
|
||||
currentValue = (r * 1.0) / (RAND_MAX * 1.0);
|
||||
currentValue *= 100 * 100;
|
||||
|
||||
|
||||
CURR.objectWrite(currentValue);
|
||||
|
||||
if (currentValue > maxValue)
|
||||
{
|
||||
maxValue = currentValue;
|
||||
MAX.objectWrite(maxValue);
|
||||
}
|
||||
|
||||
if (currentValue < minValue)
|
||||
{
|
||||
minValue = currentValue;
|
||||
MIN.objectWrite(minValue);
|
||||
}
|
||||
}
|
||||
|
||||
void resetCallback(GroupObject& go)
|
||||
{
|
||||
if (go.objectReadBool())
|
||||
{
|
||||
maxValue = 0;
|
||||
minValue = 10000;
|
||||
}
|
||||
}
|
||||
|
||||
void appLoop()
|
||||
{
|
||||
if (!bau.configured())
|
||||
return;
|
||||
|
||||
measureTemp();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
srand((unsigned int)time(NULL));
|
||||
bau.readMemory();
|
||||
|
||||
if (bau.configured())
|
||||
RESET.callback(resetCallback);
|
||||
|
||||
if (bau.deviceObject().induvidualAddress() == 0)
|
||||
bau.deviceObject().progMode(true);
|
||||
|
||||
if (bau.parameters().loadState() == LS_LOADED)
|
||||
{
|
||||
printf("Timeout: %d\n", bau.parameters().getWord(0));
|
||||
printf("Zykl. senden: %d\n", bau.parameters().getByte(2));
|
||||
printf("Min/Max senden: %d\n", bau.parameters().getByte(3));
|
||||
printf("Aenderung senden: %d\n", bau.parameters().getByte(4));
|
||||
printf("Abgleich %d\n", bau.parameters().getByte(5));
|
||||
}
|
||||
bau.enabled(true);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
setup();
|
||||
|
||||
while (1)
|
||||
{
|
||||
bau.loop();
|
||||
appLoop();
|
||||
platfrom.mdelay(100);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user