switched from qsettings to json added editng of actors
This commit is contained in:
parent
b04fbfb5bc
commit
df27b622a0
141 changed files with 4402 additions and 5068 deletions
77
src/sensors/sensor.h
Normal file
77
src/sensors/sensor.h
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include<QString>
|
||||
#include<QDateTime>
|
||||
#include<QObject>
|
||||
#include<vector>
|
||||
|
||||
class Sensor
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr uint8_t TYPE_DOOR = 0;
|
||||
static constexpr uint8_t TYPE_TEMPERATURE = 1;
|
||||
static constexpr uint8_t TYPE_HUMIDITY = 2;
|
||||
static constexpr uint8_t TYPE_PRESSURE = 3;
|
||||
static constexpr uint8_t TYPE_BRIGHTNESS = 4;
|
||||
static constexpr uint8_t TYPE_LOWBATTERY = 128;
|
||||
static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
|
||||
static constexpr uint8_t TYPE_OCUPANCY = 252;
|
||||
static constexpr uint8_t TYPE_SUN_ALTITUDE = 253;
|
||||
static constexpr uint8_t TYPE_AUDIO_OUTPUT = 254;
|
||||
static constexpr uint8_t TYPE_DUMMY = 255;
|
||||
|
||||
uint8_t type;
|
||||
uint8_t id;
|
||||
float field;
|
||||
QString name;
|
||||
QDateTime lastSeen;
|
||||
|
||||
Sensor(uint8_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = ""): type(typeIn), id(idIn), field(fieldIn), name(nameIn)
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
if(nameIn == "") generateName();
|
||||
}
|
||||
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn)
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
}
|
||||
inline bool operator==(const Sensor& in){ return type==in.type && id == in.id; }
|
||||
inline bool operator!=(const Sensor& in){ return !(*this==in); }
|
||||
inline void updateSeen(){lastSeen = QDateTime::currentDateTime();}
|
||||
inline void generateName()
|
||||
{
|
||||
if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
|
||||
else if(type == TYPE_DOOR) name = "Door " + QString::number(id);
|
||||
else if(type == TYPE_AUDIO_OUTPUT) name = "Speakers " + QString::number(id);
|
||||
else if(type == TYPE_HUMIDITY) name = "Humidity " + QString::number(id);
|
||||
else if(type == TYPE_SUN_ALTITUDE) name = "Solar Altitude";
|
||||
else if(type == TYPE_SHUTDOWN_IMMINENT) name = "Shutdown Imminent";
|
||||
else name = "Sensor Type " + QString::number(type) + " Id " + QString::number(id);
|
||||
}
|
||||
};
|
||||
|
||||
class SensorStore: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::vector<Sensor> sensors_;
|
||||
|
||||
public:
|
||||
|
||||
SensorStore(QObject *parent = nullptr);
|
||||
virtual ~SensorStore(){}
|
||||
|
||||
inline std::vector<Sensor>* getSensors(){ return &sensors_; }
|
||||
|
||||
public slots:
|
||||
|
||||
void sensorGotState(const Sensor& sensor);
|
||||
|
||||
signals:
|
||||
|
||||
void stateChenged(std::vector<Sensor> sensors);
|
||||
void sensorChangedState(Sensor sensor);
|
||||
void sensorDeleted(Sensor sensor);
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue