Sensors now work over broadcast pipe
Added Polynomal actor Added Item adding dialog Added Factor Actor
This commit is contained in:
parent
f6aaebafc6
commit
772d21a982
63 changed files with 1450 additions and 225 deletions
|
|
@ -6,40 +6,35 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
|||
masterIODevice(ioDevice),
|
||||
ioMultiplexer(masterIODevice),
|
||||
micro(ioMultiplexer.getIoDevice()),
|
||||
broadCast(ioMultiplexer.getIoDevice()),
|
||||
broadCast(ioMultiplexer.getIoDevice(), masterIn),
|
||||
settingsPath(settingsPathIn),
|
||||
sunSensorSource(49.884450, 8.650536),
|
||||
items(&sensors),
|
||||
powerItem(&sensors),
|
||||
rgbItem(new RgbItem(&sensors, µ, 5487422, "Rgb Lights")),
|
||||
auxItem(new AuxItem(&sensors, µ, 5487421, "Desk Light"))
|
||||
rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
|
||||
auxItem(new AuxItem(µ, 5487421, "Desk Light"))
|
||||
|
||||
{
|
||||
qDebug()<<"Is master:"<<master;
|
||||
//connect sensors subsystem
|
||||
QObject::connect(µ, &Microcontroller::gotSensorState, &sensors, &SensorStore::sensorGotState);
|
||||
QObject::connect(&livingroomSpeakerSensorSource, &SpeakerSensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
|
||||
QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
|
||||
QObject::connect(&sensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
|
||||
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &sensors, &SensorStore::sensorGotState);
|
||||
|
||||
QMetaObject::invokeMethod(&livingroomSpeakerSensorSource, "run", Qt::QueuedConnection);
|
||||
sunSensorSource.run();
|
||||
QObject::connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
||||
QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||
QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
|
||||
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||
|
||||
//connect item store
|
||||
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
||||
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
||||
|
||||
//special items
|
||||
QObject::connect(&powerItem, &PowerItem::stateChanged, &sensors, &SensorStore::sensorGotState);
|
||||
QObject::connect(&powerItem, &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||
powerItem.emmitSensor();
|
||||
items.addItem(rgbItem);
|
||||
items.addItem(auxItem);
|
||||
|
||||
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
|
||||
connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
||||
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
||||
if(master)connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
||||
|
||||
if(master) load(getJsonObjectFromDisk(settingsPath));
|
||||
if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
|
||||
else
|
||||
{
|
||||
broadCast.requestJson();
|
||||
|
|
@ -56,7 +51,7 @@ MainObject::~MainObject()
|
|||
{
|
||||
QJsonObject json;
|
||||
store(json);
|
||||
storeJsonObjectToDisk(json, settingsPath);
|
||||
if(!noSave)storeJsonObjectToDisk(json, settingsPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,6 +68,7 @@ void MainObject::load(const QJsonObject& json)
|
|||
items.clear();
|
||||
rgbItem->removeAllActors();
|
||||
auxItem->removeAllActors();
|
||||
powerItem.removeAllActors();
|
||||
items.addItem(rgbItem);
|
||||
items.addItem(auxItem);
|
||||
items.load(json, µ);
|
||||
|
|
@ -99,7 +95,7 @@ void MainObject::sendJson()
|
|||
broadCast.sendJson(json);
|
||||
}
|
||||
|
||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath)
|
||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* error)
|
||||
{
|
||||
QFile file;
|
||||
|
||||
|
|
@ -115,25 +111,30 @@ QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath)
|
|||
if(!file.isOpen()) std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
|
||||
else
|
||||
{
|
||||
QJsonDocument document(QJsonDocument::fromJson(file.readAll()));
|
||||
QJsonParseError qerror;
|
||||
QJsonDocument document(QJsonDocument::fromJson(file.readAll(), &qerror));
|
||||
file.close();
|
||||
if(qerror.error != QJsonParseError::NoError)
|
||||
{
|
||||
qDebug()<<filePath<<" "<<qerror.errorString();
|
||||
if(error) (*error) = true;
|
||||
}
|
||||
return document.object();
|
||||
}
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, const QString& filePath)
|
||||
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath)
|
||||
{
|
||||
QFile file;
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
if(filePath.size() > 0) file.setFileName(filePath);
|
||||
else
|
||||
if(filePath.size() == 0)
|
||||
#endif
|
||||
{
|
||||
file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
|
||||
filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json";
|
||||
}
|
||||
std::cout<<"config file: "<<file.fileName().toLatin1().data()<<std::endl;
|
||||
QFile file(filePath + ".out");
|
||||
|
||||
qDebug()<<"config file: "<<filePath;
|
||||
file.open(QIODevice::WriteOnly);
|
||||
if(!file.isOpen())
|
||||
{
|
||||
|
|
@ -145,6 +146,8 @@ bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, const QString& f
|
|||
QJsonDocument document(json);
|
||||
file.write(document.toJson());
|
||||
file.close();
|
||||
QFile::remove(filePath);
|
||||
file.rename(filePath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue