#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
LiquidCrystal_I2C _lcd1(0x27, 20, 4);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
const int _menuParametrsArray[] PROGMEM = {1, 4, 2, 0, 0, 0, 3, 1, 1, 4, 2, 0, 2, 4, 1, 0, 0, 0, 2, 1, 1, 4, 1, 0, 3, 4, 5, 0, 0, 0, 6, 8, 1, 4, 5, 0, 4, 4, 3, 0, 0, 0, 4, 7, 1, 4, 3, 0, 5, 4, 4, 0, 0, 0, 5, 7, 1, 4, 4, 0};
int _menuValueArray_int[5];
const int _menuConstantValuesArray_int[] PROGMEM = {1, 12, 31, 23, 59, 200, 0, 22};
const char _flprogMenuNameString1[] PROGMEM = "Месяц";
const char _flprogMenuNameString2[] PROGMEM = "День";
const char _flprogMenuNameString3[] PROGMEM = "Часы";
const char _flprogMenuNameString4[] PROGMEM = "Минуты";
const char _flprogMenuNameString5[] PROGMEM = "Год";
const char* const _flprogMenuStringsArray[] PROGMEM = { _flprogMenuNameString1, _flprogMenuNameString2, _flprogMenuNameString3, _flprogMenuNameString4, _flprogMenuNameString5};
struct _menuItemStricture
{
int startInArrayIndex;
}
;
struct _menuMainStricture
{
int startIndex;
int stopIndex;
bool isSwitchMenuAroundRing;
_menuItemStricture currentItem;
}
;
_menuItemStricture _MenuItems[5];
_menuMainStricture _MainMenus[1];
struct _I2CRealRimeClockTime
{
byte seconds = 0;
byte minutes = 0;
byte Hours = 0;
byte weekday = 0;
byte day = 0;
byte month = 0;
byte year = 0;
unsigned long startTime = 0;
}
;
_I2CRealRimeClockTime _RTC1;
bool _gtv1;
bool _bounseInputD6S = 0;
bool _bounseInputD6O = 0;
unsigned long _bounseInputD6P = 0UL;
int _disp13oldLength = 0;
int _disp8oldLength = 0;
int _disp3oldLength = 0;
int _disp12oldLength = 0;
bool _bounseInputD5S = 0;
bool _bounseInputD5O = 0;
unsigned long _bounseInputD5P = 0UL;
bool _tim1I = 0;
bool _tim1O = 0;
unsigned long _tim1P = 0UL;
int _disp4oldLength = 0;
bool _bounseInputD2S = 0;
bool _bounseInputD2O = 0;
unsigned long _bounseInputD2P = 0UL;
int _disp14oldLength = 0;
bool _RTCST_Ost1 = 0;
int _disp7oldLength = 0;
int _disp15oldLength = 0;
bool _trgt1 = 0;
bool _trgt1I = 0;
bool _MenuBlock_266282152_AMO_129756299 = 0;
bool _MenuBlock_266282152_AMO_244972213 = 0;
bool _MenuBlock_266282152_AMO_63283922 = 0;
bool _MenuBlock_266282152_AMO_146221971 = 0;
bool _MenuBlock_266282152_AMO_12615383 = 0;
String _MenuBlock_266282152_MNO;
String _MenuBlock_266282152_VNO;
bool _MenuBlock_266282152_OEIS = 0;
bool _MenuBlock_266282152_OMUIS = 0;
bool _MenuBlock_266282152_OMDIS = 0;
bool _MenuBlock_266282152_OVUIS = 0;
bool _MenuBlock_266282152_OVDIS = 0;
bool _MenuBlock_266282152_AMMO = 0;
int _disp5oldLength = 0;
int _disp11oldLength = 0;
int _disp10oldLength = 0;
int _disp6oldLength = 0;
bool _bounseInputD3S = 0;
bool _bounseInputD3O = 0;
unsigned long _bounseInputD3P = 0UL;
bool _bounseInputD4S = 0;
bool _bounseInputD4O = 0;
unsigned long _bounseInputD4P = 0UL;
int _disp9oldLength = 0;
int _disp1oldLength = 0;
String _RTC1_GetTime1_StrOut;
int _disp2oldLength = 0;
bool _tempVariable_bool;
int _tempVariable_int;
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
Wire.begin();
delay(10);
if(((readByteFromEEPROM(0, 0, 0x0))) != 169)
{
(updateByteToEEPROM(0, 0, 0x0, (169)));
(updateIntegerToEEPROM(1, 0, 0x0, (1)));
(updateIntegerToEEPROM(3, 0, 0x0, (1)));
(updateIntegerToEEPROM(5, 0, 0x0, (0)));
(updateIntegerToEEPROM(7, 0, 0x0, (0)));
(updateIntegerToEEPROM(9, 0, 0x0, (23)));
}
Wire.beginTransmission(68);
Wire.write(0x0E);
Wire.write(B00000000);
Wire.write(B10001000);
Wire.endTransmission();
_RTC1.startTime = millis() - 1000;
_lcd1.init();
_lcd1.backlight();
_bounseInputD2O = digitalRead(2);
_bounseInputD3O = digitalRead(3);
_bounseInputD5O = digitalRead(5);
_bounseInputD6O = digitalRead(6);
_bounseInputD4O = digitalRead(4);
_MenuItems[0].startInArrayIndex = 0;
_MenuItems[1].startInArrayIndex = 12;
_MenuItems[2].startInArrayIndex = 24;
_MenuItems[3].startInArrayIndex = 36;
_MenuItems[4].startInArrayIndex = 48;
_MainMenus[0].startIndex = 1;
_MainMenus[0].isSwitchMenuAroundRing = 1;
_MainMenus[0].stopIndex = 5;
_MainMenus[0].currentItem = _MenuItems[0];
_menuValueArray_int[0] = (readIntegerFromEEPROM(1, 0, 0x0));
_menuValueArray_int[1] = (readIntegerFromEEPROM(3, 0, 0x0));
_menuValueArray_int[2] = (readIntegerFromEEPROM(5, 0, 0x0));
_menuValueArray_int[3] = (readIntegerFromEEPROM(7, 0, 0x0));
_menuValueArray_int[4] = (readIntegerFromEEPROM(9, 0, 0x0));
}
void loop()
{
if (_isNeedClearDisp1)
{
_lcd1.clear();
_isNeedClearDisp1= 0;
}
bool _bounceInputTmpD2 = (digitalRead (2));
if (_bounseInputD2S)
{
if (millis() >= (_bounseInputD2P + 40))
{
_bounseInputD2O= _bounceInputTmpD2;
_bounseInputD2S=0;
}
}
else
{
if (_bounceInputTmpD2 != _bounseInputD2O)
{
_bounseInputD2S=1;
_bounseInputD2P = millis();
}
}
bool _bounceInputTmpD3 = (digitalRead (3));
if (_bounseInputD3S)
{
if (millis() >= (_bounseInputD3P + 40))
{
_bounseInputD3O= _bounceInputTmpD3;
_bounseInputD3S=0;
}
}
else
{
if (_bounceInputTmpD3 != _bounseInputD3O)
{
_bounseInputD3S=1;
_bounseInputD3P = millis();
}
}
bool _bounceInputTmpD5 = (digitalRead (5));
if (_bounseInputD5S)
{
if (millis() >= (_bounseInputD5P + 40))
{
_bounseInputD5O= _bounceInputTmpD5;
_bounseInputD5S=0;
}
}
else
{
if (_bounceInputTmpD5 != _bounseInputD5O)
{
_bounseInputD5S=1;
_bounseInputD5P = millis();
}
}
bool _bounceInputTmpD6 = (digitalRead (6));
if (_bounseInputD6S)
{
if (millis() >= (_bounseInputD6P + 40))
{
_bounseInputD6O= _bounceInputTmpD6;
_bounseInputD6S=0;
}
}
else
{
if (_bounceInputTmpD6 != _bounseInputD6O)
{
_bounseInputD6S=1;
_bounseInputD6P = millis();
}
}
bool _bounceInputTmpD4 = (digitalRead (4));
if (_bounseInputD4S)
{
if (millis() >= (_bounseInputD4P + 40))
{
_bounseInputD4O= _bounceInputTmpD4;
_bounseInputD4S=0;
}
}
else
{
if (_bounceInputTmpD4 != _bounseInputD4O)
{
_bounseInputD4S=1;
_bounseInputD4P = millis();
}
}
//Плата:1
bool _tmp1 = _bounseInputD2O;
if (_tmp1)
{
if (! _trgt1I) _trgt1 = ! _trgt1;
}
_trgt1I = _tmp1;
get3231Date(0x68, &_RTC1);
_RTC1_GetTime1_StrOut = (_convertRealTimeClockNumberToString(_RTC1.day))+
String("-")+
(_convertRealTimeClockNumberToString(_RTC1.month))+
String("-")+
(String("20") +(_convertRealTimeClockNumberToString (_RTC1.year)))+
String(", ")+
(_convertRealTimeClockNumberToString(_RTC1.Hours))+
String(":")+
(_convertRealTimeClockNumberToString(_RTC1.minutes))+
String(":")+
(_convertRealTimeClockNumberToString(_RTC1.seconds))+
String(", ")+
(_dayNameFromRealTimeClockNumber(_RTC1.weekday));
if (!(_trgt1))
{
_dispTempLength1 = ((_RTC1_GetTime1_StrOut)).length();
if (_disp1oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(int((20 - _dispTempLength1)/2), 0);
_lcd1.print((_RTC1_GetTime1_StrOut));
}
else
{
if (_disp1oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp1oldLength = 0;
}
}
if (_trgt1)
{
_dispTempLength1 = (((_convertNumbeToTime((_menuValueArray_int[3]))))).length();
if (_disp11oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp11oldLength = _dispTempLength1;
_lcd1.setCursor(15, 1);
_lcd1.print(((_convertNumbeToTime((_menuValueArray_int[3])))));
}
else
{
if (_disp11oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp11oldLength = 0;
}
}
if (_trgt1)
{
_dispTempLength1 = (((_convertNumbeToTime((_menuValueArray_int[2]))))).length();
if (_disp9oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp9oldLength = _dispTempLength1;
_lcd1.setCursor(12, 1);
_lcd1.print(((_convertNumbeToTime((_menuValueArray_int[2])))));
}
else
{
if (_disp9oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp9oldLength = 0;
}
}
if (_trgt1)
{
_dispTempLength1 = (((_convertNumbeToTime((_menuValueArray_int[4]))))).length();
if (_disp7oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp7oldLength = _dispTempLength1;
_lcd1.setCursor(8, 1);
_lcd1.print(((_convertNumbeToTime((_menuValueArray_int[4])))));
}
else
{
if (_disp7oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp7oldLength = 0;
}
}
if (_trgt1)
{
_dispTempLength1 = (((_convertNumbeToTime((_menuValueArray_int[0]))))).length();
if (_disp5oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp5oldLength = _dispTempLength1;
_lcd1.setCursor(5, 1);
_lcd1.print(((_convertNumbeToTime((_menuValueArray_int[0])))));
}
else
{
if (_disp5oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp5oldLength = 0;
}
}
if (_trgt1)
{
_dispTempLength1 = (((_convertNumbeToTime((_menuValueArray_int[1]))))).length();
if (_disp3oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp3oldLength = _dispTempLength1;
_lcd1.setCursor(2, 1);
_lcd1.print(((_convertNumbeToTime((_menuValueArray_int[1])))));
}
else
{
if (_disp3oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp3oldLength = 0;
}
}
if (_trgt1)
{
_dispTempLength1 = ((String("DATA&TIME"))).length();
if (_disp2oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp2oldLength = _dispTempLength1;
_lcd1.setCursor(int((20 - _dispTempLength1)/2), 0);
_lcd1.print((String("DATA&TIME")));
}
else
{
if (_disp2oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp2oldLength = 0;
}
}
if (_trgt1)
{
if (!(_RTCST_Ost1))
{
set3231Date(0x68, &_RTC1, -1, ((_menuValueArray_int[3])), ((_menuValueArray_int[2])), ((_menuValueArray_int[1])), ((_menuValueArray_int[0])), ((_menuValueArray_int[4])), -1);
get3231Date(0x68, &_RTC1);
_RTCST_Ost1 = 1;
}
}
else
{
_RTCST_Ost1 = 0;
}
if (_trgt1)
{
_tempVariable_bool = 1;
if (! _MenuBlock_266282152_OEIS)
{
_MenuBlock_266282152_OEIS = 1;
}
_tempVariable_int = pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+10]);
_MenuBlock_266282152_MNO = _readStringFromProgmem ((char*)pgm_read_word(&(_flprogMenuStringsArray[_tempVariable_int - 1])));
_MenuBlock_266282152_VNO = _menuOutputValueString (0);
_MenuBlock_266282152_AMO_129756299 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 1;
_MenuBlock_266282152_AMO_244972213 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 2;
_MenuBlock_266282152_AMO_63283922 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 3;
_MenuBlock_266282152_AMO_146221971 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 4;
_MenuBlock_266282152_AMO_12615383 = pgm_read_byte(&_menuParametrsArray[(_MainMenus[0].currentItem).startInArrayIndex]) == 5;
_MenuBlock_266282152_AMMO = (pgm_read_byte(&_menuParametrsArray[((_MainMenus[0].currentItem).startInArrayIndex)+5])) == 0;
}
else
{
_tempVariable_bool = 0;
if (_MenuBlock_266282152_OEIS)
{
_MenuBlock_266282152_OEIS = 0;
}
_MenuBlock_266282152_AMO_129756299 = 0;
_MenuBlock_266282152_AMO_244972213 = 0;
_MenuBlock_266282152_AMO_63283922 = 0;
_MenuBlock_266282152_AMO_146221971 = 0;
_MenuBlock_266282152_AMO_12615383 = 0;
_MenuBlock_266282152_AMMO = 0;
_MenuBlock_266282152_MNO = "";
_MenuBlock_266282152_VNO = "";
}
if(_bounseInputD5O)
{
if (! _MenuBlock_266282152_OMUIS)
{
_MenuBlock_266282152_OMUIS = 1;
if(_tempVariable_bool)
{
_menuUpEvents(0);
}
}
}
else
{
_MenuBlock_266282152_OMUIS = 0;
}
if(_bounseInputD6O)
{
if (! _MenuBlock_266282152_OMDIS)
{
_MenuBlock_266282152_OMDIS = 1;
if(_tempVariable_bool)
{
_menuDownEvents(0);
}
}
}
else
{
_MenuBlock_266282152_OMDIS = 0;
}
if(_bounseInputD3O)
{
if (! _MenuBlock_266282152_OVUIS)
{
_MenuBlock_266282152_OVUIS = 1;
if(_tempVariable_bool)
{
_valueUpEvents(0);
_menuUpdateToEEpromItems();
}
}
}
else
{
_MenuBlock_266282152_OVUIS = 0;
}
if(_bounseInputD4O)
{
if (! _MenuBlock_266282152_OVDIS)
{
_MenuBlock_266282152_OVDIS = 1;
if(_tempVariable_bool)
{
_valueDownEvents(0);
_menuUpdateToEEpromItems();
}
}
}
else
{
_MenuBlock_266282152_OVDIS = 0;
}
if (_MenuBlock_266282152_AMMO)
{
if (_tim1I)
{
if (_isTimer(_tim1P, 200))
{
_tim1O = 1;
}
}
else
{
_tim1I =1;
_tim1P = millis();
}
}
else
{
_tim1O = 0;
_tim1I = 0;
}
_gtv1 = _tim1O;
//Плата:2
if (((_gtv1) && (_MenuBlock_266282152_AMO_129756299)))
{
_dispTempLength1 = (String("^")).length();
if (_disp10oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp10oldLength = _dispTempLength1;
_lcd1.setCursor(2, 2);
_lcd1.print(String("^"));
}
else
{
if (_disp10oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp10oldLength = 0;
}
}
if (((_gtv1) && (_MenuBlock_266282152_AMO_244972213)))
{
_dispTempLength1 = (String("^")).length();
if (_disp12oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp12oldLength = _dispTempLength1;
_lcd1.setCursor(5, 2);
_lcd1.print(String("^"));
}
else
{
if (_disp12oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp12oldLength = 0;
}
}
if (_gtv1)
{
_dispTempLength1 = (String("-")).length();
if (_disp4oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp4oldLength = _dispTempLength1;
_lcd1.setCursor(4, 1);
_lcd1.print(String("-"));
}
else
{
if (_disp4oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp4oldLength = 0;
}
}
if (_gtv1)
{
_dispTempLength1 = (String("-")).length();
if (_disp6oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp6oldLength = _dispTempLength1;
_lcd1.setCursor(7, 1);
_lcd1.print(String("-"));
}
else
{
if (_disp6oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp6oldLength = 0;
}
}
if (_gtv1)
{
_dispTempLength1 = (String(":")).length();
if (_disp8oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp8oldLength = _dispTempLength1;
_lcd1.setCursor(14, 1);
_lcd1.print(String(":"));
}
else
{
if (_disp8oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp8oldLength = 0;
}
}
if (((_gtv1) && (_MenuBlock_266282152_AMO_63283922)))
{
_dispTempLength1 = (String("^")).length();
if (_disp13oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp13oldLength = _dispTempLength1;
_lcd1.setCursor(8, 2);
_lcd1.print(String("^"));
}
else
{
if (_disp13oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp13oldLength = 0;
}
}
if (((_gtv1) && (_MenuBlock_266282152_AMO_146221971)))
{
_dispTempLength1 = (String("^")).length();
if (_disp14oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp14oldLength = _dispTempLength1;
_lcd1.setCursor(12, 2);
_lcd1.print(String("^"));
}
else
{
if (_disp14oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp14oldLength = 0;
}
}
if (((_gtv1) && (_MenuBlock_266282152_AMO_12615383)))
{
_dispTempLength1 = (String("^")).length();
if (_disp15oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp15oldLength = _dispTempLength1;
_lcd1.setCursor(15, 2);
_lcd1.print(String("^"));
}
else
{
if (_disp15oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp15oldLength = 0;
}
}
}
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 == 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 == 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 == 4)
{
return _convertNamber(itemType, convFormat, valIndex, indexMax, indexMin);
}
return "";
}
void _menuUpdateToEEpromItems()
{
(updateIntegerToEEPROM(1, 0, 0x0, ((_menuValueArray_int[0]))));
(updateIntegerToEEPROM(3, 0, 0x0, ((_menuValueArray_int[1]))));
(updateIntegerToEEPROM(5, 0, 0x0, ((_menuValueArray_int[2]))));
(updateIntegerToEEPROM(7, 0, 0x0, ((_menuValueArray_int[3]))));
(updateIntegerToEEPROM(9, 0, 0x0, ((_menuValueArray_int[4]))));
}
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);
}
}
return "";
}
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);
}
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));
}
byte decToBcd(byte val)
{
return ((val/10*16) + (val%10));
}
void set3231Date(int addres, struct _I2CRealRimeClockTime *timeStruct, int sec, int minut, int hou, int dat, int mo, int ye, int daW)
{
byte temp;
Wire.beginTransmission(addres);
Wire.write(0x00);
if (sec < 0)
{
temp = timeStruct -> seconds;
}
else
{
temp = sec;
}
Wire.write(decToBcd(temp));
if (minut < 0)
{
temp = timeStruct -> minutes;
}
else
{
temp = minut;
}
Wire.write(decToBcd(temp));
if (hou < 0)
{
temp = timeStruct -> Hours;
}
else
{
temp = hou;
}
Wire.write(decToBcd(temp));
if (daW < 0)
{
temp = timeStruct -> weekday;
}
else
{
temp = daW;
}
Wire.write(decToBcd(temp));
if (dat < 0)
{
temp = timeStruct -> day;
}
else
{
temp = dat;
}
Wire.write(decToBcd(temp));
if (mo < 0)
{
temp = timeStruct -> month;
}
else
{
temp = mo;
}
Wire.write(decToBcd(temp));
if (ye < 0)
{
temp = timeStruct -> year;
}
else
{
temp = ye;
}
Wire.write(decToBcd(temp));
Wire.endTransmission();
timeStruct ->startTime = millis() - 1000;
}
void get3231Date(int addres, struct _I2CRealRimeClockTime *timeStruct)
{
if (!(_isTimer ((timeStruct ->startTime), 250)))
{
return;
}
Wire.beginTransmission(addres);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(addres, 7);
if (Wire.available())
{
byte seconds = Wire.read();
byte minutes = Wire.read();
byte hours = Wire.read();
byte day = Wire.read();
byte date = Wire.read();
byte month = Wire.read();
byte year = Wire.read();
timeStruct -> seconds = (((seconds & B11110000) >> 4) * 10 + (seconds & B00001111));
timeStruct -> minutes = (((minutes & B11110000) >> 4) * 10 + (minutes & B00001111));
timeStruct -> Hours = (((hours & B00110000) >> 4) * 10 + (hours & B00001111));
timeStruct -> weekday = (day & B00000111);
timeStruct -> day = (((date & B00110000) >> 4) * 10 + (date & B00001111));
timeStruct -> month = (((month & B00010000) >> 4) * 10 + (month & B00001111));
timeStruct -> year = (((year & B11110000) >> 4) * 10 + (year & B00001111));
}
timeStruct ->startTime = millis();
}
String _convertRealTimeClockNumberToString(byte value)
{
if (value > 9)
{
return String(value, DEC);
}
return (String("0") + String(value, DEC));
}
String _dayNameFromRealTimeClockNumber(byte value)
{
switch (value)
{
case 1:
return String("Mon");
break;
case 2:
return String("Tue");
break;
case 3:
return String("Wed");
break;
case 4:
return String("Thu");
break;
case 5:
return String("Fri");
break;
case 6:
return String("Sat");
break;
case 7:
return String("Sun");
break;
}
return String("");
}
String _convertNumbeToTime(long value)
{
if (value > 9)
{
return String(value, DEC);
}
return (String("0") + String(value, DEC));
}