LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
out_pid.h
Go to the documentation of this file.
1#pragma once
2#include "options.h"
3#ifndef PID_DISABLE
4#include <abstractout.h>
5#include <item.h>
6#include <PID_v1.h>
7#include "itemCmd.h"
8#include "aJson.h"
9
12#define OUTPUT_TRESHOLD 1.0
13
21class pidJson {
22 public:
24 pidJson(aJsonObject * _obj){obj=_obj;};
25
27 aJsonObject * getValObj(){return NULL;};
29 aJsonObject * getSetObj(){return NULL;};
31 aJsonObject * getPoObj(){return NULL;};
33 PID * getPID(){return (obj) ? (PID*) obj->valueint: NULL;};
34 aJsonObject * obj;
35};
36
45public:
46 PID * pid;
47 iotype output;
48 iotype input;
49 iotype setpoint;
50 float prevOut;
51 uint32_t alarmTimer;
53 uint16_t alarmTimeout; //in sec
54};
55
56
88class out_pid : public abstractOut {
89public:
90
91 //out_pid(Item * _item):abstractOut(_item){store = (pidPersistent *) item->getPersistent();};
93 out_pid():store(NULL){};
95 void link(Item * _item){abstractOut::link(_item); if (_item) {store = (pidPersistent *) item->getPersistent();} else store = NULL;};
96
98 int Setup() override;
100 int Poll(short cause) override;
102 int Stop() override;
104 int isActive() override;
106 int getChanType() override;
107 //int getDefaultStorageType(){return ST_FLOAT;};
109 int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
111 void alarm(bool);
112
113
114protected:
117 bool getConfig();
119 float getAlarmVal();
120};
121#endif
A single LightHub item (virtual channel).
Definition item.h:232
chPersistent * getPersistent()
Definition item.cpp:641
abstractOut()
Definition abstractout.h:22
virtual void link(Item *_item)
Definition abstractout.h:24
Item * item
Item currently linked to this driver.
Definition abstractout.h:55
Placeholder for driver-persistent data attached to an item (I_EXT field).
Definition abstractout.h:8
Command + value container passed between items, drivers and MQTT.
Definition itemCmd.h:306
void link(Item *_item)
Attach to an item and grab its persistent PID state.
Definition out_pid.h:95
void alarm(bool)
Enter (state=true) or leave (state=false) the input-failure alarm; forces the alarmVal output on entr...
Definition out_pid.cpp:250
bool getConfig()
Parse the item argument array, fill store and create the PID controller.
Definition out_pid.cpp:11
pidPersistent * store
Definition out_pid.h:115
float getAlarmVal()
Get the forced output value used on alarm (alarmVal, or 0/255 by control direction).
Definition out_pid.cpp:205
int Stop() override
De-initialize and free the PID controller and persistent state.
Definition out_pid.cpp:139
out_pid()
Default constructor.
Definition out_pid.h:93
int getChanType() override
Channel type of the driver.
Definition out_pid.cpp:273
int Poll(short cause) override
Run the PID loop: compute output, apply it to the output item, watch the input-failure timer.
Definition out_pid.cpp:157
int Ctrl(itemCmd cmd, char *subItem=NULL, bool toExecute=true, bool authorized=false) override
Handle /val (input), /set (setpoint) and /cmd|/ctrl (ON/OFF/ENABLE/DISABLE/RESET) commands.
Definition out_pid.cpp:284
int isActive() override
True when the item command is not CMD_OFF.
Definition out_pid.cpp:151
int Setup() override
Allocate persistent state, load JSON config, initialize the PID controller.
Definition out_pid.cpp:112
pidJson(aJsonObject *_obj)
Constructor, stores the JSON object pointer.
Definition out_pid.h:24
aJsonObject * obj
Definition out_pid.h:34
aJsonObject * getPoObj()
Get the JSON object holding the PID output (not used yet).
Definition out_pid.h:31
PID * getPID()
Get the PID controller pointer stored inside the JSON object value.
Definition out_pid.h:33
aJsonObject * getValObj()
Get the JSON object holding the PID input value (not used yet).
Definition out_pid.h:27
aJsonObject * getSetObj()
Get the JSON object holding the PID setpoint (not used yet).
Definition out_pid.h:29
Persistent (survives reboot) state of the PID driver.
Definition out_pid.h:44
iotype setpoint
Definition out_pid.h:49
uint16_t alarmTimeout
Definition out_pid.h:53
iotype input
Definition out_pid.h:48
PID * pid
Definition out_pid.h:46
bool alarmArmed
Definition out_pid.h:52
float prevOut
Definition out_pid.h:50
iotype output
Definition out_pid.h:47
uint32_t alarmTimer
Definition out_pid.h:51
Item (virtual channel) system of LightHub.