Relay dialog hooked up

This commit is contained in:
IMback
2017-11-07 20:26:16 +01:00
parent 08dc57d385
commit 2c46e6ffb6
6 changed files with 102 additions and 13 deletions

View File

@ -2,6 +2,7 @@
Microcontroller::Microcontroller(QIODevice* port): _port(port)
{
getState();
}
Microcontroller::Microcontroller()
@ -16,6 +17,7 @@ Microcontroller::~Microcontroller()
void Microcontroller::setIODevice(QIODevice *port)
{
_port = port;
getState();
}
void Microcontroller::relayToggle(int state, int relay)
@ -84,6 +86,11 @@ void Microcontroller::run()
loop->exec();
}
void Microcontroller::getState()
{
if(_port != nullptr) _port->write("relay state\n", sizeof("relay state\n"));
}
void Microcontroller::abort()
{
@ -93,6 +100,29 @@ void Microcontroller::abort()
}
}
void Microcontroller::processMicroReturn()
{
QString workbuff = _buffer;
workbuff.remove(0, 2);
QStringList workbufList = workbuff.split(',');
int numberOfRelays = workbufList[0].toInt();
if(workbufList.size() >= numberOfRelays+1)
{
bool hasChanged = false;
_relayStates.resize(numberOfRelays, false);
for(int i = 0; i < numberOfRelays; i++)
{
if(_relayStates[i] != (bool)workbufList[i+1].toInt())
{
_relayStates[i] = (bool)workbufList[i+1].toInt();
hasChanged = true;
}
}
if(hasChanged)relayStateChanged(_relayStates);
}
}
void Microcontroller::doTick()
{
if(_port != nullptr)
@ -101,10 +131,12 @@ void Microcontroller::doTick()
while(_port->getChar(&charBuf))
{
_buffer.push_back(charBuf);
std::cout<<charBuf<<std::endl;
if( _buffer.endsWith('\n') )
{
if(_buffer.size() > 2 && _buffer[0] == "S" && _buffer[1] == "T")
{
processMicroReturn();
}
textRecived(_buffer);
_buffer.clear();
}