#include "flprogUtilites.h"
struct _sVFUPD
{
    int mode=0;
    int port=0;
    int index=0;
    String data="";
}
;
_sVFUPD _sVFUPDPort0;
bool _RV4CP0 = 0;
bool _gen8I = 0;
bool _gen8O = 0;
unsigned long _gen8P = 0UL;
bool _gen11I = 0;
bool _gen11O = 0;
unsigned long _gen11P = 0UL;
bool _trgr8 = 0;
bool _RV7CP0 = 0;
bool _gen10I = 0;
bool _gen10O = 0;
unsigned long _gen10P = 0UL;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _gen4I = 0;
bool _gen4O = 0;
unsigned long _gen4P = 0UL;
bool _gen5I = 0;
bool _gen5O = 0;
unsigned long _gen5P = 0UL;
bool _trgr4 = 0;
bool _trgr5 = 0;
bool _gen12I = 0;
bool _gen12O = 0;
unsigned long _gen12P = 0UL;
bool _gen13I = 0;
bool _gen13O = 0;
unsigned long _gen13P = 0UL;
bool _gen15I = 0;
bool _gen15O = 0;
unsigned long _gen15P = 0UL;
bool _RV5CP0 = 0;
bool _RV8CP0 = 0;
bool _RV1CP0 = 0;
bool _trgr2 = 0;
bool _RV3CP0 = 0;
bool _trgr6 = 0;
bool _gen14I = 0;
bool _gen14O = 0;
unsigned long _gen14P = 0UL;
bool _RV6CP0 = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _gen3I = 0;
bool _gen3O = 0;
unsigned long _gen3P = 0UL;
bool _gen6I = 0;
bool _gen6O = 0;
unsigned long _gen6P = 0UL;
bool _gen7I = 0;
bool _gen7O = 0;
unsigned long _gen7P = 0UL;
bool _gen9I = 0;
bool _gen9O = 0;
unsigned long _gen9P = 0UL;
bool _trgr7 = 0;
bool _gen16I = 0;
bool _gen16O = 0;
unsigned long _gen16P = 0UL;
bool _trgr3 = 0;
bool _trgr1 = 0;
bool _RV2CP0 = 0;
void setup()
{
    pinMode(2, OUTPUT);
    digitalWrite(2, 0);
    pinMode(3, OUTPUT);
    digitalWrite(3, 0);
    pinMode(4, OUTPUT);
    digitalWrite(4, 0);
    pinMode(5, OUTPUT);
    digitalWrite(5, 0);
    pinMode(6, OUTPUT);
    digitalWrite(6, 0);
    pinMode(7, OUTPUT);
    digitalWrite(7, 0);
    pinMode(8, OUTPUT);
    digitalWrite(8, 0);
    pinMode(9, OUTPUT);
    digitalWrite(9, 0);
    _startUart0();
    _sVFUPDPort0.port = 0;
}
void loop()
{
    if (Serial.available()) 
    {
         _readByteFromUART((Serial.read()),0);
    }
    //Плата:1
    if (!(_RV5CP0)) 
    {
        if (! _gen10I)
        {
            _gen10I = 1;
            _gen10O = 1;
            _gen10P = millis();
        }
    }
     else 
    {
        _gen10I = 0 ;
        _gen10O= 0;
    }
     if (_gen10I &&  _gen10O)   _gen10O = !(flprog::isTimer(_gen10P , 500));
    if (_RV5CP0) 
    {
        if (! _gen9I)
        {
            _gen9I = 1;
            _gen9O = 1;
            _gen9P = millis();
        }
    }
     else 
    {
        _gen9I = 0 ;
        _gen9O= 0;
    }
     if (_gen9I &&  _gen9O)   _gen9O = !(flprog::isTimer(_gen9P , 500));
    if(_gen10O) _trgr5 = 0;
    if(_gen9O) _trgr5 = 1;
    digitalWrite(6, _trgr5);
    if (!(_RV1CP0)) 
    {
        if (! _gen2I)
        {
            _gen2I = 1;
            _gen2O = 1;
            _gen2P = millis();
        }
    }
     else 
    {
        _gen2I = 0 ;
        _gen2O= 0;
    }
     if (_gen2I &&  _gen2O)   _gen2O = !(flprog::isTimer(_gen2P , 500));
    if (_RV1CP0) 
    {
        if (! _gen1I)
        {
            _gen1I = 1;
            _gen1O = 1;
            _gen1P = millis();
        }
    }
     else 
    {
        _gen1I = 0 ;
        _gen1O= 0;
    }
     if (_gen1I &&  _gen1O)   _gen1O = !(flprog::isTimer(_gen1P , 500));
    if(_gen2O) _trgr1 = 0;
    if(_gen1O) _trgr1 = 1;
    digitalWrite(2, _trgr1);
    if (!(_RV6CP0)) 
    {
        if (! _gen12I)
        {
            _gen12I = 1;
            _gen12O = 1;
            _gen12P = millis();
        }
    }
     else 
    {
        _gen12I = 0 ;
        _gen12O= 0;
    }
     if (_gen12I &&  _gen12O)   _gen12O = !(flprog::isTimer(_gen12P , 500));
    if (_RV6CP0) 
    {
        if (! _gen11I)
        {
            _gen11I = 1;
            _gen11O = 1;
            _gen11P = millis();
        }
    }
     else 
    {
        _gen11I = 0 ;
        _gen11O= 0;
    }
     if (_gen11I &&  _gen11O)   _gen11O = !(flprog::isTimer(_gen11P , 500));
    if(_gen12O) _trgr6 = 0;
    if(_gen11O) _trgr6 = 1;
    digitalWrite(7, _trgr6);
    if (!(_RV2CP0)) 
    {
        if (! _gen4I)
        {
            _gen4I = 1;
            _gen4O = 1;
            _gen4P = millis();
        }
    }
     else 
    {
        _gen4I = 0 ;
        _gen4O= 0;
    }
     if (_gen4I &&  _gen4O)   _gen4O = !(flprog::isTimer(_gen4P , 500));
    if (_RV2CP0) 
    {
        if (! _gen3I)
        {
            _gen3I = 1;
            _gen3O = 1;
            _gen3P = millis();
        }
    }
     else 
    {
        _gen3I = 0 ;
        _gen3O= 0;
    }
     if (_gen3I &&  _gen3O)   _gen3O = !(flprog::isTimer(_gen3P , 500));
    if(_gen4O) _trgr2 = 0;
    if(_gen3O) _trgr2 = 1;
    digitalWrite(3, _trgr2);
    if (!(_RV7CP0)) 
    {
        if (! _gen14I)
        {
            _gen14I = 1;
            _gen14O = 1;
            _gen14P = millis();
        }
    }
     else 
    {
        _gen14I = 0 ;
        _gen14O= 0;
    }
     if (_gen14I &&  _gen14O)   _gen14O = !(flprog::isTimer(_gen14P , 500));
    if (_RV7CP0) 
    {
        if (! _gen13I)
        {
            _gen13I = 1;
            _gen13O = 1;
            _gen13P = millis();
        }
    }
     else 
    {
        _gen13I = 0 ;
        _gen13O= 0;
    }
     if (_gen13I &&  _gen13O)   _gen13O = !(flprog::isTimer(_gen13P , 500));
    if(_gen14O) _trgr7 = 0;
    if(_gen13O) _trgr7 = 1;
    digitalWrite(8, _trgr7);
    if (!(_RV3CP0)) 
    {
        if (! _gen6I)
        {
            _gen6I = 1;
            _gen6O = 1;
            _gen6P = millis();
        }
    }
     else 
    {
        _gen6I = 0 ;
        _gen6O= 0;
    }
     if (_gen6I &&  _gen6O)   _gen6O = !(flprog::isTimer(_gen6P , 500));
    if (_RV3CP0) 
    {
        if (! _gen5I)
        {
            _gen5I = 1;
            _gen5O = 1;
            _gen5P = millis();
        }
    }
     else 
    {
        _gen5I = 0 ;
        _gen5O= 0;
    }
     if (_gen5I &&  _gen5O)   _gen5O = !(flprog::isTimer(_gen5P , 500));
    if(_gen6O) _trgr3 = 0;
    if(_gen5O) _trgr3 = 1;
    digitalWrite(4, _trgr3);
    if (!(_RV8CP0)) 
    {
        if (! _gen16I)
        {
            _gen16I = 1;
            _gen16O = 1;
            _gen16P = millis();
        }
    }
     else 
    {
        _gen16I = 0 ;
        _gen16O= 0;
    }
     if (_gen16I &&  _gen16O)   _gen16O = !(flprog::isTimer(_gen16P , 500));
    if (_RV8CP0) 
    {
        if (! _gen15I)
        {
            _gen15I = 1;
            _gen15O = 1;
            _gen15P = millis();
        }
    }
     else 
    {
        _gen15I = 0 ;
        _gen15O= 0;
    }
     if (_gen15I &&  _gen15O)   _gen15O = !(flprog::isTimer(_gen15P , 500));
    if(_gen16O) _trgr8 = 0;
    if(_gen15O) _trgr8 = 1;
    digitalWrite(9, _trgr8);
    if (!(_RV4CP0)) 
    {
        if (! _gen8I)
        {
            _gen8I = 1;
            _gen8O = 1;
            _gen8P = millis();
        }
    }
     else 
    {
        _gen8I = 0 ;
        _gen8O= 0;
    }
     if (_gen8I &&  _gen8O)   _gen8O = !(flprog::isTimer(_gen8P , 500));
    if (_RV4CP0) 
    {
        if (! _gen7I)
        {
            _gen7I = 1;
            _gen7O = 1;
            _gen7P = millis();
        }
    }
     else 
    {
        _gen7I = 0 ;
        _gen7O= 0;
    }
     if (_gen7I &&  _gen7O)   _gen7O = !(flprog::isTimer(_gen7P , 500));
    if(_gen8O) _trgr4 = 0;
    if(_gen7O) _trgr4 = 1;
    digitalWrite(5, _trgr4);
}
void _readByteFromUART(byte data,int port)
{
    if (port==0)
    {
         _sVFUPDPort0 = _ressiveByteFromUartForVariable(data, _sVFUPDPort0);
    }
}
struct  _sVFUPD _ressiveByteFromUartForVariable(byte resData, struct _sVFUPD data)
{
    if(_ressiveFromUartByteIsCommand(resData))
    {
        data = _nextStepRessiveVariableFromUart(resData, data);
        return data;
    }
    data.data = data.data + char(resData);
    return data;
}
bool _ressiveFromUartByteIsCommand(byte data)
{
    if(data==1)
    {
        return 1;
    }
    if(data==2)
    {
        return 1;
    }
    if(data==3)
    {
        return 1;
    }
    return 0;
}
struct  _sVFUPD _nextStepRessiveVariableFromUart(byte resData, struct _sVFUPD data)
{
    if((resData==1)&&(data.mode==0))
    {
        data.mode=1;
        return data;
    }
    if((resData==2)&&(data.mode==1))
    {
        data.mode=2;
        data.index=data.data.toInt();
        data.data=String("");
        return data;
    }
    if((resData==3)&&(data.mode==2))
    {
        data=_saveToVariableResiveFromUartVariable(data);
        return data;
    }
    data.mode=0;
    data.data=String("");
    return data;
}
struct _sVFUPD _saveToVariableResiveFromUartVariable(struct _sVFUPD data)
{
    if((data.index==1)&&(data.port==0))
    {
        _RV1CP0 = ((data.data).toInt());
    }
    if((data.index==2)&&(data.port==0))
    {
        _RV2CP0 = ((data.data).toInt());
    }
    if((data.index==3)&&(data.port==0))
    {
        _RV3CP0 = ((data.data).toInt());
    }
    if((data.index==4)&&(data.port==0))
    {
        _RV4CP0 = ((data.data).toInt());
    }
    if((data.index==5)&&(data.port==0))
    {
        _RV5CP0 = ((data.data).toInt());
    }
    if((data.index==6)&&(data.port==0))
    {
        _RV6CP0 = ((data.data).toInt());
    }
    if((data.index==7)&&(data.port==0))
    {
        _RV7CP0 = ((data.data).toInt());
    }
    if((data.index==8)&&(data.port==0))
    {
        _RV8CP0 = ((data.data).toInt());
    }
    data.mode=0;
    data.data=String("");
    return data;
}
void _startUart0()
{
    int code= 6;
    Serial.begin(9600, (flprog::serialModeFromInt(code)));
}
