#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Encoder.h>
#include <EEPROM.h>
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
bool Zero;
bool Key;
bool Menu;
bool Short;
bool Long;
int PIN;
bool Plus;
bool Minus;
Encoder myEnc(2 , 3);
long newPosition;
long oldPosition= -999;
bool oldkey;
bool K_FL;
unsigned long oldtime;
unsigned long deltatime;
unsigned long keytime;
unsigned long detect;
struct _poligonInexes
{
int minIndex;
int maxIndex;
}
;
int _Poligon_InArray_2[158] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 56, 57, 58, 60, 62, 63, 65, 67, 68, 70, 72, 74, 76, 78, 80, 83, 85, 87, 90, 92, 95, 98, 100, 103, 106, 109, 112, 115, 119, 122, 125, 129, 133, 137, 141, 145, 149, 153, 158, 162, 167, 172, 177, 182, 187, 192, 198, 204, 210, 216, 222, 228, 235, 241, 248, 255, 263, 270, 278, 286, 294, 302, 310, 319, 327, 336, 345, 354, 364, 373, 383, 393, 403, 413, 424, 434, 445, 456, 467, 478, 489, 500, 512, 523, 534, 546, 557, 569, 581, 592, 604, 615, 627, 639, 650, 661, 673, 684, 695, 706, 728, 738, 749, 759, 769, 779, 788};
int _Poligon_OutArray_2[158] = {273, 249, 232, 219, 209, 201, 194, 188, 182, 178, 173, 169, 166, 163, 160, 157, 154, 152, 149, 147, 145, 143, 141, 140, 138, 136, 135, 133, 132, 130, 129, 128, 127, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 6, 5, 4, 3, 2, 1, 0};
const int _menuParametrsArray[] PROGMEM = {1, 3, 1, 0, 0, 0, 8, 8, 1, 8, 3, 0, 2, 4, 3, 0, 0, 0, 4, 6, 1, 4, 4, 0, 3, 4, 2, 0, 0, 0, 3, 6, 1, 4, 2, 0, 4, 4, 1, 0, 0, 0, 2, 6, 1, 4, 1, 0, 5, 4, 4, 0, 0, 0, 5, 6, 1, 4, 7, 0, 6, 3, 2, 0, 0, 0, 0, 0, 1, 2, 5, 0, 7, 3, 3, 0, 0, 0, 0, 0, 1, 2, 6, 0};
bool _menuValueArray_bool[3];
const bool _menuConstantValuesArray_bool[] PROGMEM = {1};
int _menuValueArray_int[4];
const int _menuConstantValuesArray_int[] PROGMEM = {1, 10, 23, 100, 59, 0};
const char _flprogMenuNameString1[] PROGMEM = "Gisteresis t";
const char _flprogMenuNameString2[] PROGMEM = "hour";
const char _flprogMenuNameString3[] PROGMEM = "Output";
const char _flprogMenuNameString4[] PROGMEM = "Temperatura";
const char _flprogMenuNameString5[] PROGMEM = "PUSK";
const char _flprogMenuNameString6[] PROGMEM = "STOP";
const char _flprogMenuNameString7[] PROGMEM = "minuty";
const char _flprogMenuNameString8[] PROGMEM = "";
const char* const _flprogMenuStringsArray[] PROGMEM = { _flprogMenuNameString1, _flprogMenuNameString2, _flprogMenuNameString3, _flprogMenuNameString4, _flprogMenuNameString5, _flprogMenuNameString6, _flprogMenuNameString7, _flprogMenuNameString8};
struct _menuItemStricture
{
int startInArrayIndex;
}
;
struct _menuMainStricture
{
int startIndex;
int stopIndex;
bool isSwitchMenuAroundRing;
_menuItemStricture currentItem;
}
;
_menuItemStricture _MenuItems[7];
_menuMainStricture _MainMenus[1];
bool _gtv1 = 0;
bool _gtv2 = 0;
long _gtv3;
bool _gtv4 = 0;
bool _gtv5 = 0;
bool _gtv6 = 0;
float _gtv7;
bool _gtv9 = 0;
bool _gtv10 = 0;
bool _gtv14;
long _gtv15;
long _gtv16 = 0;
String _gtv17;
bool _gtv18;
bool _gtv19;
bool _gtv20;
bool _gtv21;
bool _gtv22 = 0;
bool _gtv23 = 0;
int _disp9oldLength = 0;
bool _trgt2 = 0;
bool _trgt2I = 0;
int _disp8oldLength = 0;
bool _tim4I = 0;
bool _tim4O = 0;
unsigned long _tim4P = 0UL;
int _disp7oldLength = 0;
bool _tim2I = 0;
bool _tim2O = 0;
unsigned long _tim2P = 0UL;
bool _bounseInputD4S = 0;
bool _bounseInputD4O = 0;
unsigned long _bounseInputD4P = 0UL;
int _disp4oldLength = 0;
bool _trgrt1 = 0;
bool _trgrt1I = 0;
bool _trgs1 = 0;
bool _MenuBlock_351052363_AMO_7251826 = 0;
bool _MenuBlock_351052363_AMO_512291394 = 0;
bool _MenuBlock_351052363_AMO_481475938 = 0;
bool _MenuBlock_351052363_AMO_22207341 = 0;
bool _MenuBlock_351052363_AMO_417519080 = 0;
bool _MenuBlock_351052363_AMO_93720452 = 0;
bool _MenuBlock_351052363_AMO_47861012 = 0;
String _MenuBlock_351052363_MNO;
String _MenuBlock_351052363_VNO;
bool _MenuBlock_351052363_OEIS = 0;
bool _MenuBlock_351052363_OMUIS = 0;
bool _MenuBlock_351052363_OMDIS = 0;
bool _MenuBlock_351052363_OVUIS = 0;
bool _MenuBlock_351052363_OVDIS = 0;
bool _tim3I = 0;
bool _tim3O = 0;
unsigned long _tim3P = 0UL;
bool _trgrt2 = 0;
bool _trgrt2I = 0;
int _disp2oldLength = 0;
bool _bounseInputD10S = 0;
bool _bounseInputD10O = 0;
unsigned long _bounseInputD10P = 0UL;
bool _trgs2 = 0;
int _disp6oldLength = 0;
bool _tim6I = 0;
bool _tim6O = 0;
unsigned long _tim6P = 0UL;
int _disp3oldLength = 0;
bool _trgs4 = 0;
bool _trgrt3 = 0;
bool _trgrt3I = 0;
int _disp5oldLength = 0;
bool _trgrt4 = 0;
bool _trgrt4I = 0;
int _disp1oldLength = 0;
bool _gen2I = 0;
bool _gen2O = 0;
unsigned long _gen2P = 0UL;
bool _trgrt6 = 0;
bool _trgrt6I = 0;
bool _count2I = 0;
unsigned long _count2_Value = 0UL;
bool _tim1I = 0;
bool _tim1O = 0;
unsigned long _tim1P = 0UL;
bool _trgs3 = 0;
bool _bounseInputD9S = 0;
bool _bounseInputD9O = 0;
unsigned long _bounseInputD9P = 0UL;
bool _tempVariable_bool;
int _tempVariable_int;
void setup()
{
pinMode(4, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, OUTPUT);
digitalWrite(11, 0);
pinMode(8, OUTPUT);
digitalWrite(8, 0);
Wire.begin();
delay(10);
if(((readByteFromEEPROM(0, 0, 0x0))) != 236)
{
(updateByteToEEPROM(0, 0, 0x0, (236)));
(updateBooleanToEEPROM(1, 0, 0x0, (0)));
(updateBooleanToEEPROM(1, 1, 0x0, (0)));
(updateIntegerToEEPROM(2, 0, 0x0, (10)));
(updateIntegerToEEPROM(4, 0, 0x0, (0)));
(updateIntegerToEEPROM(6, 0, 0x0, (40)));
(updateIntegerToEEPROM(8, 0, 0x0, (0)));
}
_lcd1.init();
_lcd1.backlight();
_bounseInputD9O = digitalRead(9);
_bounseInputD4O = digitalRead(4);
_bounseInputD10O = digitalRead(10);
oldkey=false;
oldtime=0;
_MenuItems[0].startInArrayIndex = 0;
_MenuItems[1].startInArrayIndex = 12;
_MenuItems[2].startInArrayIndex = 24;
_MenuItems[3].startInArrayIndex = 36;
_MenuItems[4].startInArrayIndex = 48;
_MenuItems[5].startInArrayIndex = 60;
_MenuItems[6].startInArrayIndex = 72;
_MainMenus[0].startIndex = 1;
_MainMenus[0].isSwitchMenuAroundRing = 1;
_MainMenus[0].stopIndex = 7;
_MainMenus[0].currentItem = _MenuItems[0];
_menuValueArray_int[0] = (readIntegerFromEEPROM(2, 0, 0x0));
_menuValueArray_int[1] = (readIntegerFromEEPROM(4, 0, 0x0));
_menuValueArray_int[2] = (readIntegerFromEEPROM(6, 0, 0x0));
_menuValueArray_bool[1] = (readBooleanFromEEPROM(1, 0, 0x0));
_menuValueArray_bool[2] = (readBooleanFromEEPROM(1, 1, 0x0));
_menuValueArray_int[3] = (readIntegerFromEEPROM(8, 0, 0x0));
}
void loop()
{
if (_isNeedClearDisp1)
{
_lcd1.clear();
_isNeedClearDisp1= 0;
}
bool _bounceInputTmpD9 = (digitalRead (9));
if (_bounseInputD9S)
{
if (millis() >= (_bounseInputD9P + 40))
{
_bounseInputD9O= _bounceInputTmpD9;
_bounseInputD9S=0;
}
}
else
{
if (_bounceInputTmpD9 != _bounseInputD9O)
{
_bounseInputD9S=1;
_bounseInputD9P = millis();
}
}
bool _bounceInputTmpD10 = (digitalRead (10));
if (_bounseInputD10S)
{
if (millis() >= (_bounseInputD10P + 40))
{
_bounseInputD10O= _bounceInputTmpD10;
_bounseInputD10S=0;
}
}
else
{
if (_bounceInputTmpD10 != _bounseInputD10O)
{
_bounseInputD10S=1;
_bounseInputD10P = millis();
}
}
bool _bounceInputTmpD4 = (digitalRead (4));
if (_bounseInputD4S)
{
if (millis() >= (_bounseInputD4P + 40))
{
_bounseInputD4O= _bounceInputTmpD4;
_bounseInputD4S=0;
}
}
else
{
if (_bounceInputTmpD4 != _bounseInputD4O)
{
_bounseInputD4S=1;
_bounseInputD4P = millis();
}
}
//Плата:1
//Наименование:датчик
_gtv7 = (_poligon(((analogRead (0))), _Poligon_InArray_2, _Poligon_OutArray_2, 158));
//Плата:2
//Наименование:энкодер
Zero = _gtv1;
Key = 0;
Menu = 0;
newPosition = myEnc.read();
if (newPosition != oldPosition)
{
oldPosition = newPosition;
}
if (Zero == 1)
{
myEnc.write(0);
}
PIN= newPosition/4;
if (Key !=oldkey)
{
oldkey = Key;
if (Key)
{
Short = 0;
Long = 0;
K_FL=1;
oldtime=millis();
}
else
{
if (K_FL)
{
Short=1;
keytime=millis();
K_FL=0;
}
}
}
if ((Key)and (!Long) and (K_FL))
{
if ((millis()-oldtime)>= 600)
{
Long = 1;
keytime=millis();
K_FL=0;
}
}
if ((Short)or(Long))
{
deltatime=millis()-keytime;
if (deltatime> 100)
{
Short =0;
Long =0;
K_FL=0;
}
}
//Вычисление плюса и минуса
if(Menu)
{
if(newPosition>=4)
{
Plus=1;
myEnc.write(0);
}
if(newPosition<=-4)
{
Minus=1;
myEnc.write(0);
}
if(newPosition>-3&&newPosition<3)
{
Plus=0;
Minus=0;
}
}
_gtv3 = PIN;
if (((((!(_bounseInputD4O)) && (!(_gtv2)))) || (((!(_bounseInputD4O)) && (_gtv4)))))
{
if (_tim6I)
{
if (_isTimer(_tim6P, 3000))
{
_tim6O = 1;
}
}
else
{
_tim6I =1;
_tim6P = millis();
}
}
else
{
_tim6O = 0;
_tim6I = 0;
}
bool _tmp2 = _tim6O;
if (_tmp2)
{
if (! _trgt2I) _trgt2 = ! _trgt2;
}
_trgt2I = _tmp2;
_gtv2 = _trgt2;
//Плата:3
//Наименование:Меню
if (!(_bounseInputD4O))
{
if (_tim1I)
{
if (_isTimer(_tim1P, 3000))
{
_tim1O = 1;
}
}
else
{
_tim1I =1;
_tim1P = millis();
}
}
else
{
_tim1O = 0;
_tim1I = 0;
}
if (_tim1O)
{
if (_trgrt1I)
{
_trgrt1 = 0;
}
else
{
_trgrt1 = 1;
_trgrt1I = 1;
}
}
else
{
_trgrt1 = 0;
_trgrt1I = 0;
}
;
if(((_trgrt1) && (_gtv5)))
{
_menuValueArray_int[2] = _gtv3;
(updateIntegerToEEPROM(6, 0, 0x0, ((_menuValueArray_int[2]))));
}
if (_gtv5)
{
_dispTempLength1 = ((((String("ust ")) + ((String((_menuValueArray_int[2]), DEC)))))).length();
if (_disp4oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp4oldLength = _dispTempLength1;
_lcd1.setCursor(7, 1);
_lcd1.print((((String("ust ")) + ((String((_menuValueArray_int[2]), DEC))))));
}
else
{
if (_disp4oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp4oldLength = 0;
}
}
if (((_gtv5) || (_gtv6) || (_gtv9) || (_gtv10) || (_gtv22) || (_gtv23)))
{
_dispTempLength1 = ((((String("E ")) + ((String(_gtv3, DEC)))))).length();
if (_disp2oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp2oldLength = _dispTempLength1;
_lcd1.setCursor(0, 1);
_lcd1.print((((String("E ")) + ((String(_gtv3, DEC))))));
}
else
{
if (_disp2oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp2oldLength = 0;
}
}
if (!(!(_bounseInputD4O)))
{
if (_trgrt6I)
{
_trgrt6 = 0;
}
else
{
_trgrt6 = 1;
_trgrt6I = 1;
}
}
else
{
_trgrt6 = 0;
_trgrt6I = 0;
}
;
if (_gtv2)
{
_tempVariable_bool = 1;
if (! _MenuBlock_351052363_OEIS)
{
_MenuBlock_351052363_OEIS = 1;
}
_tempVariable_int = pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+10]);
_MenuBlock_351052363_MNO = _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[_tempVariable_int - 1])));
_MenuBlock_351052363_VNO = _menuOutputValueString (0);
_MenuBlock_351052363_AMO_7251826 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 1;
_MenuBlock_351052363_AMO_512291394 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 2;
_MenuBlock_351052363_AMO_481475938 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 3;
_MenuBlock_351052363_AMO_22207341 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 4;
_MenuBlock_351052363_AMO_417519080 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 5;
_MenuBlock_351052363_AMO_93720452 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 6;
_MenuBlock_351052363_AMO_47861012 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 7;
}
else
{
_tempVariable_bool = 0;
if (_MenuBlock_351052363_OEIS)
{
_MenuBlock_351052363_OEIS = 0;
_menuUpdateToEEpromItems();
}
_MenuBlock_351052363_AMO_7251826 = 0;
_MenuBlock_351052363_AMO_512291394 = 0;
_MenuBlock_351052363_AMO_481475938 = 0;
_MenuBlock_351052363_AMO_22207341 = 0;
_MenuBlock_351052363_AMO_417519080 = 0;
_MenuBlock_351052363_AMO_93720452 = 0;
_MenuBlock_351052363_AMO_47861012 = 0;
_MenuBlock_351052363_MNO = "";
_MenuBlock_351052363_VNO = "";
}
if(_trgrt6)
{
if (! _MenuBlock_351052363_OMUIS)
{
_MenuBlock_351052363_OMUIS = 1;
if(_tempVariable_bool)
{
_menuUpEvents(0);
_menuUpdateToEEpromItems();
}
}
}
else
{
_MenuBlock_351052363_OMUIS = 0;
}
if(0)
{
if (! _MenuBlock_351052363_OMDIS)
{
_MenuBlock_351052363_OMDIS = 1;
if(_tempVariable_bool)
{
_menuDownEvents(0);
_menuUpdateToEEpromItems();
}
}
}
else
{
_MenuBlock_351052363_OMDIS = 0;
}
if(0)
{
if (! _MenuBlock_351052363_OVUIS)
{
_MenuBlock_351052363_OVUIS = 1;
if(_tempVariable_bool)
{
_valueUpEvents(0);
}
}
}
else
{
_MenuBlock_351052363_OVUIS = 0;
}
if(0)
{
if (! _MenuBlock_351052363_OVDIS)
{
_MenuBlock_351052363_OVDIS = 1;
if(_tempVariable_bool)
{
_valueDownEvents(0);
}
}
}
else
{
_MenuBlock_351052363_OVDIS = 0;
}
_gtv23 = _MenuBlock_351052363_AMO_47861012;
_gtv22 = _MenuBlock_351052363_AMO_93720452;
_gtv10 = _MenuBlock_351052363_AMO_417519080;
_gtv9 = _MenuBlock_351052363_AMO_22207341;
_gtv6 = _MenuBlock_351052363_AMO_481475938;
_gtv5 = _MenuBlock_351052363_AMO_512291394;
_gtv4 = _MenuBlock_351052363_AMO_7251826;
if (_gtv2)
{
_dispTempLength1 = ((_MenuBlock_351052363_MNO)).length();
if (_disp8oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp8oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print((_MenuBlock_351052363_MNO));
}
else
{
if (_disp8oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp8oldLength = 0;
}
}
if (!(_bounseInputD4O))
{
if (_tim2I)
{
if (_isTimer(_tim2P, 3000))
{
_tim2O = 1;
}
}
else
{
_tim2I =1;
_tim2P = millis();
}
}
else
{
_tim2O = 0;
_tim2I = 0;
}
if (_tim2O)
{
if (_trgrt2I)
{
_trgrt2 = 0;
}
else
{
_trgrt2 = 1;
_trgrt2I = 1;
}
}
else
{
_trgrt2 = 0;
_trgrt2I = 0;
}
;
if(((_trgrt2) && (_gtv6)))
{
_menuValueArray_int[1] = _gtv3;
(updateIntegerToEEPROM(4, 0, 0x0, ((_menuValueArray_int[1]))));
}
if (_gtv6)
{
_dispTempLength1 = ((((String("uct ")) + ((String((_menuValueArray_int[1]), DEC)))))).length();
if (_disp3oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp3oldLength = _dispTempLength1;
_lcd1.setCursor(7, 1);
_lcd1.print((((String("uct ")) + ((String((_menuValueArray_int[1]), DEC))))));
}
else
{
if (_disp3oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp3oldLength = 0;
}
}
if (!(_bounseInputD4O))
{
if (_tim3I)
{
if (_isTimer(_tim3P, 3000))
{
_tim3O = 1;
}
}
else
{
_tim3I =1;
_tim3P = millis();
}
}
else
{
_tim3O = 0;
_tim3I = 0;
}
if (_tim3O)
{
if (_trgrt3I)
{
_trgrt3 = 0;
}
else
{
_trgrt3 = 1;
_trgrt3I = 1;
}
}
else
{
_trgrt3 = 0;
_trgrt3I = 0;
}
;
if(((_trgrt3) && (_gtv9)))
{
_menuValueArray_int[0] = _gtv3;
(updateIntegerToEEPROM(2, 0, 0x0, ((_menuValueArray_int[0]))));
}
if (_gtv9)
{
_dispTempLength1 = ((((String("uct ")) + ((String((_menuValueArray_int[0]), DEC)))))).length();
if (_disp5oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp5oldLength = _dispTempLength1;
_lcd1.setCursor(7, 1);
_lcd1.print((((String("uct ")) + ((String((_menuValueArray_int[0]), DEC))))));
}
else
{
if (_disp5oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp5oldLength = 0;
}
}
if (!(_bounseInputD4O))
{
if (_tim4I)
{
if (_isTimer(_tim4P, 3000))
{
_tim4O = 1;
}
}
else
{
_tim4I =1;
_tim4P = millis();
}
}
else
{
_tim4O = 0;
_tim4I = 0;
}
if (_tim4O)
{
if (_trgrt4I)
{
_trgrt4 = 0;
}
else
{
_trgrt4 = 1;
_trgrt4I = 1;
}
}
else
{
_trgrt4 = 0;
_trgrt4I = 0;
}
;
if(((_trgrt4) && (_gtv10)))
{
_menuValueArray_int[3] = _gtv3;
(updateIntegerToEEPROM(8, 0, 0x0, ((_menuValueArray_int[3]))));
}
if (_gtv10)
{
_dispTempLength1 = ((((String("uct ")) + ((String((_menuValueArray_int[3]), DEC)))))).length();
if (_disp6oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp6oldLength = _dispTempLength1;
_lcd1.setCursor(7, 1);
_lcd1.print((((String("uct ")) + ((String((_menuValueArray_int[3]), DEC))))));
}
else
{
if (_disp6oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp6oldLength = 0;
}
}
//Плата:4
//Наименование:Терморегулятор
if((_gtv7) <= (((_menuValueArray_int[2]))-((_menuValueArray_int[0])))) _trgs3 = 1;
if((_gtv7) >= ((_menuValueArray_int[2]))) _trgs3 = 0;
_gtv21 = ((!(_gtv2)) && (_trgs3));
if (!(_gtv2))
{
_dispTempLength1 = (((String((_menuValueArray_int[2]), DEC)))).length();
if (_disp1oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(13, 0);
_lcd1.print(((String((_menuValueArray_int[2]), DEC))));
}
else
{
if (_disp1oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp1oldLength = 0;
}
}
if (!(_gtv2))
{
_dispTempLength1 = ((((String("t ")) + ((_floatToStringWitRaz(_gtv7,2))) + (String(" C"))))).length();
if (_disp7oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp7oldLength = _dispTempLength1;
_lcd1.setCursor(0, 0);
_lcd1.print((((String("t ")) + ((_floatToStringWitRaz(_gtv7,2))) + (String(" C")))));
}
else
{
if (_disp7oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp7oldLength = 0;
}
}
//Плата:5
//Наименование:установка времени
if(_gtv18) _trgs1 = 1;
if(((_gtv14) || (_gtv19))) _trgs1 = 0;
if(_trgs1) _trgs2 = 1;
if(((_gtv14) || (((_gtv14) || (_gtv19))))) _trgs2 = 0;
_gtv20 = _trgs2;
if (_trgs1)
{
if (! _gen2I)
{
_gen2I = 1;
_gen2O = 1;
_gen2P = millis();
}
}
else
{
_gen2I = 0 ;
_gen2O= 0;
}
if (_gen2I)
{
if (_isTimer (_gen2P , 500))
{
_gen2P = millis();
_gen2O = ! _gen2O;
}
}
if (_gtv19)
{
_count2_Value = 0;
}
else
{
if (_gen2O)
{
if (! _count2I)
{
_count2I = 1;
_count2_Value = _count2_Value + 1;
}
}
else
{
_count2I = 0;
}
}
_gtv17 = (((String(((((_gtv16)*(3600))+((_gtv15)*(60)))-(_count2_Value))/(3600), DEC))) + (String(":")) + ((String(((((((_gtv16)*(3600))+((_gtv15)*(60)))-(_count2_Value)) % (3600)))/(60), DEC))) + (String(":")) + ((String((((((((_gtv16)*(3600))+((_gtv15)*(60)))-(_count2_Value)) % (3600))) % (60)), DEC))));
_gtv14 = ((((_gtv16)*(3600))+((_gtv15)*(60)))-(_count2_Value)) == (0);
//Плата:6
_gtv16 = (_menuValueArray_int[1]);
if (!(_gtv2))
{
_dispTempLength1 = ((_gtv17)).length();
if (_disp9oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp9oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print((_gtv17));
}
else
{
if (_disp9oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp9oldLength = 0;
}
}
_gtv15 = (_menuValueArray_int[3]);
//Плата:7
//Наименование:плата выходов
_gtv18 = ((!(_bounseInputD9O)) || ((_menuValueArray_bool[1])));
_gtv19 = (((_menuValueArray_bool[2])) || (!(_bounseInputD10O)));
digitalWrite(11, ((_gtv20) && (_gtv21)));
//Плата:8
//Наименование:плата уровня
if(((analogRead (1))) == (850)) _trgs4 = 1;
if(!(((analogRead (2))) == (850))) _trgs4 = 0;
digitalWrite(8, _trgs4);
}
String _floatToStringWitRaz(float value, int raz)
{
return String(value,raz);
}
bool _isTimer(unsigned long startTime, unsigned long period)
{
unsigned long currentTime;
currentTime = millis();
if (currentTime>= startTime)
{
return (currentTime>=(startTime + period));
}
else
{
return (currentTime >=(4294967295-startTime+period));
}
}
String _readStringFromProgmem (char *string)
{
String result = String("");
while (pgm_read_byte(string)!='\0')
{
result=result+ char(pgm_read_byte(string));
string++;
}
return result;
}
void _menuUpEvents (int menuIndex)
{
int tempIndex = pgm_read_byte(&_menuParametrsArray[((_MainMenus[menuIndex]).currentItem).startInArrayIndex]);
int parIndex = pgm_read_byte(&_menuParametrsArray[ (((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+5]);
int parentStartIndex;
int parentStopIndex;
if (parIndex == 0)
{
parentStartIndex = (_MainMenus[menuIndex]).startIndex;
parentStopIndex =(_MainMenus[menuIndex]).stopIndex;
}
else
{
parentStartIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex - 1]).startInArrayIndex)+3]);
parentStopIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+4]);
}
if (tempIndex == parentStartIndex)
{
if((_MainMenus[menuIndex]).isSwitchMenuAroundRing)
{
(_MainMenus[menuIndex]).currentItem = _MenuItems[parentStopIndex -1];
return;
}
else
{
return;
}
}
(_MainMenus[menuIndex]).currentItem = _MenuItems[tempIndex - 2];
return;
}
void _menuDownEvents (int menuIndex)
{
int tempIndex = pgm_read_byte(&_menuParametrsArray[((_MainMenus[menuIndex]).currentItem).startInArrayIndex]);
int parIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+5]);
int parentStartIndex;
int parentStopIndex;
if (parIndex == 0)
{
parentStartIndex = (_MainMenus[menuIndex]).startIndex;
parentStopIndex =(_MainMenus[menuIndex]).stopIndex;
}
else
{
parentStartIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+3]);
parentStopIndex = pgm_read_byte(&_menuParametrsArray[((_MenuItems[parIndex-1]).startInArrayIndex)+4]);
}
if (tempIndex == parentStopIndex)
{
if((_MainMenus[menuIndex]).isSwitchMenuAroundRing)
{
(_MainMenus[menuIndex]).currentItem = _MenuItems[parentStartIndex -1];
return;
}
else
{
return;
}
}
(_MainMenus[menuIndex]).currentItem = _MenuItems[tempIndex];
return;
}
void _valueUpEvents (int menuIndex)
{
int valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
int itemType = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
int indexMax = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+6]);
int indexStep = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+8]);
if(itemType ==3)
{
_menuValueArray_bool[valIndex - 1 ] = 1;
return;
}
if (itemType == 4)
{
if (! indexMax == 0)
{
if (! (int(pgm_read_word(&_menuConstantValuesArray_int[indexMax -1])) > int(_menuValueArray_int[valIndex -1])))
{
return;
}
}
_menuValueArray_int[valIndex -1] = _menuValueArray_int[valIndex -1] + (pgm_read_word(&_menuConstantValuesArray_int[indexStep -1]));
}
}
void _valueDownEvents (int menuIndex)
{
int valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
int itemType = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
int indexMin = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+7]);
int indexStep = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+8]);
if(itemType ==3)
{
_menuValueArray_bool[valIndex -1] = 0;
return;
}
if (itemType == 4)
{
if (! indexMin == 0)
{
if (! ((int(pgm_read_word(&_menuConstantValuesArray_int[indexMin - 1]))) < int(_menuValueArray_int[valIndex - 1])))
{
return;
}
}
_menuValueArray_int[valIndex - 1] = _menuValueArray_int[valIndex - 1] - (pgm_read_word(&_menuConstantValuesArray_int[indexStep - 1]));
}
}
String _menuOutputValueString (int menuIndex)
{
int itemType = pgm_read_byte(&_menuParametrsArray[ (((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+1]);
int valIndex = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+2]);
int indexMin = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+7]);
int indexMax = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+6]);
if(valIndex == 0)
{
return "";
}
int convFormat = pgm_read_byte(&_menuParametrsArray[(((_MainMenus[menuIndex]).currentItem).startInArrayIndex)+9]);
if(itemType == 3)
{
return _convertBoolean(itemType, convFormat, valIndex, indexMax, indexMin);
}
if(itemType == 4)
{
return _convertNamber(itemType, convFormat, valIndex, indexMax, indexMin);
}
return "";
}
void _menuUpdateToEEpromItems()
{
(updateIntegerToEEPROM(2, 0, 0x0, ((_menuValueArray_int[0]))));
(updateIntegerToEEPROM(4, 0, 0x0, ((_menuValueArray_int[1]))));
(updateIntegerToEEPROM(6, 0, 0x0, ((_menuValueArray_int[2]))));
(updateBooleanToEEPROM(1, 0, 0x0, ((_menuValueArray_bool[1]))));
(updateBooleanToEEPROM(1, 1, 0x0, ((_menuValueArray_bool[2]))));
(updateIntegerToEEPROM(8, 0, 0x0, ((_menuValueArray_int[3]))));
}
String _convertNamber(int itemType, int convFormat, int valIndex, int indexMax, int indexMin)
{
if (itemType== 4)
{
if (convFormat == 4)
{
return String((_menuValueArray_int[valIndex - 1 ]),DEC);
}
if (convFormat == 5)
{
return String((_menuValueArray_int[valIndex - 1]),HEX);
}
if (convFormat == 6)
{
return String((_menuValueArray_int[valIndex -1]),BIN);
}
}
}
String _convertBoolean(int itemType, int convFormat, int valIndex, int indexMax, int indexMin)
{
if (convFormat == 1)
{
if(_menuValueArray_bool[valIndex -1])
{
return "1";
}
else
{
return "0";
}
}
if (convFormat == 2)
{
if(_menuValueArray_bool[valIndex -1])
{
return "True";
}
else
{
return "False";
}
}
if (convFormat == 3)
{
if(_menuValueArray_bool[valIndex -1 ])
{
return "Да";
}
else
{
return "Нет";
}
}
if(_menuValueArray_bool[valIndex -1])
{
return _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[indexMax - 1])));
}
else
{
return _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[indexMin - 1])));
}
}
int _poligon(int value, int intArray[], int outArray[], int arraySize)
{
struct _poligonInexes indexes;
indexes = _getPoligonIndexes(value, intArray, arraySize);
return map(value, intArray[indexes.minIndex], intArray[indexes.maxIndex], outArray[indexes.minIndex], outArray[indexes.maxIndex]);
}
struct _poligonInexes _getPoligonIndexes(int value, int array[], int arraySize)
{
struct _poligonInexes result;
int i;
result.minIndex = 0;
result.maxIndex = 0;
for (i = 0; i < arraySize; i++)
{
if (array [result.minIndex] > array[i])
{
result.minIndex = i;
}
if (array [result.maxIndex] < array[i])
{
result.maxIndex = i;
}
}
for (i = 0; i < arraySize; i++)
{
if ((array [i] >= value) && (array [result.maxIndex] > array[i]))
{
result.maxIndex = i;
}
}
if (result.maxIndex==0)
{
result.minIndex = 0;
result.maxIndex=1;
}
else
{
result.minIndex = result.maxIndex -1;
}
return result;
return result;
}
byte readByteFromEEPROM(int addres, byte bitAddres, byte chipAddres)
{
return EEPROM.read(addres);
}
void updateByteToEEPROM(int addres, byte bitAddres, byte chipAddres, byte value)
{
return EEPROM.update(addres, value);
}
bool readBooleanFromEEPROM(int addres, byte bitAddres, byte chipAddres)
{
byte temp = readByteFromEEPROM(addres, bitAddres, chipAddres);
return bitRead(temp, bitAddres);
}
void updateBooleanToEEPROM(int addres, byte bitAddres, byte chipAddres, bool value)
{
byte temp = readByteFromEEPROM(addres, bitAddres, chipAddres);
bitWrite(temp, bitAddres, value);
updateByteToEEPROM(addres, bitAddres, chipAddres, temp);
}
int readIntegerFromEEPROM(int addres, byte bitAddres, byte chipAddres)
{
byte hight = readByteFromEEPROM(addres, bitAddres, chipAddres);
byte low = readByteFromEEPROM((addres+1), bitAddres, chipAddres);
return word(hight, low);
}
void updateIntegerToEEPROM(int addres, byte bitAddres, byte chipAddres, int value)
{
updateByteToEEPROM(addres, bitAddres, chipAddres, highByte(value));
updateByteToEEPROM((addres+1), bitAddres, chipAddres, lowByte(value));
}