#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "TimerOne.h"
#include <SFE_BMP180.h>
#include <OneWire.h>
#include <EEPROM.h>
#include "TM74HC595Display.h"
SFE_BMP180 _bmp085;
long _bmp085P = 0;
int _bmp085T = 0;
long _bmp085A = 0;
double BMP085_ALTITUDE;
double BMP085_SeaPressure;
byte _d18x2x2Addr[8]={0x28, 0x7B, 0xD7, 0x79, 0x97, 0x8, 0x3, 0x8C};
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
struct _sVFUPD
{
int mode=0;
int port=0;
int index=0;
String data="";
}
;
_sVFUPD _sVFUPDPort0;
OneWire _ow12(12);
float InputFloatValues_244381022_2;
int positionNumberFloat_244381022_2;
bool enableOutputFloat_244381022_2;
byte numberCodeSymbols_244381022_2;
int positionNumberSingleChar_244381022_2;
bool enableOutputSingleChar_244381022_2;
int inputIntValues2digits_244381022_2;
int positionNumber2digits_244381022_2;
bool enableOutput2digits_244381022_2;
long inputIntValues4digitsShowZero_244381022_2;
bool enableOutput4digitsShowZero_244381022_2;
int inputIntValues4digitsHideZero_244381022_2;
bool enableOutput4digitsHideZero_244381022_2;
bool ClearDisplay_244381022_2;
TM74HC595Display disp_244381022_2(7, 6, 5);
unsigned char LED_0F_244381022_2[29];
boolean flag_244381022_2;
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;
float temper = 0.0;
}
;
_I2CRealRimeClockTime _RTC1;
bool _gtv2 = 1;
float _gtv3;
float _gtv4;
bool _gtv8;
bool _gtv9;
String _gtv10;
float _gtv20;
String _gtv23;
bool _gtv1;
String _swi11;
long _convertStringToNamberOutput_10 = 0L;
bool _RV2CP0 = 0;
int _RV5CP0 = 0;
int _disp2oldLength = 0;
String _SV1CP0 = "0";
bool _SV1CP0needSend = 0;
unsigned long _SV1CP0Time = 0UL;
bool _RV1CP0 = 0;
bool _SEEPR2OSN = 0;
String _SV4CP0 = "0";
bool _SV4CP0needSend = 0;
int _swi4;
bool _RV6CP0 = 0;
String _swi1;
bool _SV2CP0 = 0;
bool _SV2CP0needSend = 0;
unsigned long _SV2CP0Time = 0UL;
String _SV6CP0 = "0";
bool _SV6CP0needSend = 0;
long _convertStringToNamberOutput_6 = 0L;
String _RTC1_GetTime1_StrOut;
byte _RTC1_GetTime1_HourOut = 0;
byte _RTC1_GetTime1_DayOut = 0;
unsigned long _bmp0851Tti = 0UL;
String _SV7CP0 = "0";
bool _SV7CP0needSend = 0;
int _RV4CP0 = 0;
int _disp1oldLength = 0;
int _disp3oldLength = 0;
int _swi5;
String _swi8;
int _disp5oldLength = 0;
bool _BitChange_2_OldSt = 0;
bool _BitChange_2_Out = 0;
String _SV8CP0 = "0";
bool _SV8CP0needSend = 0;
int _disp4oldLength = 0;
bool _bounseInputD8S = 0;
bool _bounseInputD8O = 0;
unsigned long _bounseInputD8P = 0UL;
float _RTCTempO1 = 0.00;
String _SV5CP0 = "0";
bool _SV5CP0needSend = 0;
unsigned long _d18x2x2Tti = 0UL;
float _d18x2x2O = 0.00;
String _swi7;
String _swi10;
long _swi9;
bool _trgrt4 = 0;
bool _trgrt4I = 0;
int _RV3CP0 = 0;
String _SV9CP0 = "0";
bool _SV9CP0needSend = 0;
unsigned long _SV9CP0Time = 0UL;
bool _bounseInputD4S = 0;
bool _bounseInputD4O = 0;
unsigned long _bounseInputD4P = 0UL;
bool _gen1I = 0;
bool _gen1O = 0;
unsigned long _gen1P = 0UL;
bool _trgs1 = 0;
String _SV3CP0 = "0";
bool _SV3CP0needSend = 0;
unsigned long _SV3CP0Time = 0UL;
String _tempVariable_String;
byte _tempVariable_byte;
float _tempVariable_float;
void setup()
{
pinMode(16, INPUT);
pinMode(8, INPUT);
pinMode(4, INPUT);
pinMode(10, INPUT);
pinMode(15, OUTPUT);
digitalWrite(15, 0);
Wire.begin();
delay(10);
if(((readByteFromEEPROM(0, 0, 0x0))) != 60)
{
(updateByteToEEPROM(0, 0, 0x0, (60)));
(updateBooleanToEEPROM(1, 0, 0x0, (0)));
}
_bmp085.begin();
BMP085_ALTITUDE = (243000UL) /100 ;
Wire.beginTransmission(68);
Wire.write(0x0E);
Wire.write(B00000000);
Wire.write(B10001000);
Wire.endTransmission();
_RTC1.startTime = millis() - 1000;
_startUart0();
_lcd1.init();
_lcd1.backlight();
_bounseInputD4O = digitalRead(4);
_bounseInputD8O = digitalRead(8);
_SV1CP0Time = millis();
_SV2CP0Time = millis();
_SV3CP0Time = millis();
_SV9CP0Time = millis();
_sVFUPDPort0.port = 0;
LED_0F_244381022_2[0] = 0xC0; //0
LED_0F_244381022_2[1] = 0xF9; //1
LED_0F_244381022_2[2] = 0xA4; //2
LED_0F_244381022_2[3] = 0xB0; //3
LED_0F_244381022_2[4] = 0x99; //4
LED_0F_244381022_2[5] = 0x92; //5
LED_0F_244381022_2[6] = 0x82; //6
LED_0F_244381022_2[7] = 0xF8; //7
LED_0F_244381022_2[8] = 0x80; //8
LED_0F_244381022_2[9] = 0x90; //9
LED_0F_244381022_2[10] = 0x88; //A
LED_0F_244381022_2[11] = 0x83; //b
LED_0F_244381022_2[12] = 0xC6; //C
LED_0F_244381022_2[13] = 0xA1; //d
LED_0F_244381022_2[14] = 0x86; //E
LED_0F_244381022_2[15] = 0x8E; //F
LED_0F_244381022_2[16] = 0xC2; //G
LED_0F_244381022_2[17] = 0x89; //H
LED_0F_244381022_2[18] = 0xF9; //I
LED_0F_244381022_2[19] = 0xF1; //J
LED_0F_244381022_2[20] = 0xC3; //L
LED_0F_244381022_2[21] = 0xA9; //n
LED_0F_244381022_2[22] = 0xC0; //O
LED_0F_244381022_2[23] = 0x8C; //P
LED_0F_244381022_2[24] = 0x98; //q
LED_0F_244381022_2[25] = 0x92; //S
LED_0F_244381022_2[26] = 0xC1; //U
LED_0F_244381022_2[27] = 0x91; //Y
LED_0F_244381022_2[28] = 0xFE; //hight -
Timer1.initialize(1500); // set a timer of length 1500
Timer1.attachInterrupt(timerIsr_244381022_2);
}
void loop()
{
if (_isNeedClearDisp1)
{
_lcd1.clear();
_isNeedClearDisp1= 0;
}
if (Serial.available())
{
_readByteFromUART((Serial.read()),0);
}
if(_isTimer(_bmp0851Tti, 3000))
{
_bmp0851Tti = millis();
double _tempBMP085TData;
_tempVariable_byte = _bmp085.startTemperature();
if (_tempVariable_byte != 0)
{
delay(_tempVariable_byte);
_tempVariable_byte = _bmp085.getTemperature(_tempBMP085TData);
if (_tempVariable_byte != 0)
{
_bmp085T = _tempBMP085TData*10;
double _tempBMP085PData;
_tempVariable_byte = _bmp085.startPressure(3);
if (_tempVariable_byte != 0)
{
delay(_tempVariable_byte);
_tempVariable_byte = _bmp085.getPressure(_tempBMP085PData, _tempBMP085TData);
if (_tempVariable_byte != 0)
{
_bmp085P = _tempBMP085PData*100;
BMP085_SeaPressure = _bmp085.sealevel(_tempBMP085PData,BMP085_ALTITUDE);
_bmp085A = _bmp085.altitude(_tempBMP085PData,BMP085_SeaPressure);
}
}
}
}
}
bool _bounceInputTmpD4 = (digitalRead (4));
if (_bounseInputD4S)
{
if (millis() >= (_bounseInputD4P + 40))
{
_bounseInputD4O= _bounceInputTmpD4;
_bounseInputD4S=0;
}
}
else
{
if (_bounceInputTmpD4 != _bounseInputD4O)
{
_bounseInputD4S=1;
_bounseInputD4P = millis();
}
}
bool _bounceInputTmpD8 = (digitalRead (8));
if (_bounseInputD8S)
{
if (millis() >= (_bounseInputD8P + 40))
{
_bounseInputD8O= _bounceInputTmpD8;
_bounseInputD8S=0;
}
}
else
{
if (_bounceInputTmpD8 != _bounseInputD8O)
{
_bounseInputD8S=1;
_bounseInputD8P = millis();
}
}
//Плата:1
//Наименование:часы
get3231Date(0x68, &_RTC1);
_RTCTempO1 = _RTC1.temper;
if (_isTimer(_SV1CP0Time, 1000))
{
_SV1CP0 = (_floatToStringWitRaz((_RTCTempO1)-(3.00),1));
_SV1CP0needSend = 1;
_SV1CP0Time = millis();
}
_tempVariable_String = (_floatToStringWitRaz((_RTCTempO1)-(3.00),1));
_convertStringToNamberOutput_10 = strtol(_tempVariable_String.c_str(),NULL,10);
_tempVariable_String = _gtv10;
_convertStringToNamberOutput_6 = strtol(_tempVariable_String.c_str(),NULL,10);
if (_gtv2)
{
if (! _gen1I)
{
_gen1I = 1;
_gen1O = 1;
_gen1P = millis();
}
}
else
{
_gen1I = 0 ;
_gen1O= 0;
}
if (_gen1I)
{
if (_gen1O)
{
if (_isTimer(_gen1P , 5000))
{
_gen1P = millis();
_gen1O = 0;
}
}
else
{
if (_isTimer(_gen1P , 3000))
{
_gen1P = millis();
_gen1O = 1;
}
}
}
if(_gen1O)
{
_swi9=_convertStringToNamberOutput_10;
}
else
{
_swi9=_convertStringToNamberOutput_6;
}
InputFloatValues_244381022_2 = 0;
positionNumberFloat_244381022_2 = 0;
enableOutputFloat_244381022_2 = 0;
numberCodeSymbols_244381022_2 = 0;
positionNumberSingleChar_244381022_2 = 0;
enableOutputSingleChar_244381022_2 = 0;
inputIntValues2digits_244381022_2 = 0;
positionNumber2digits_244381022_2 = 0;
enableOutput2digits_244381022_2 = 0;
inputIntValues4digitsShowZero_244381022_2 = _swi9;
enableOutput4digitsShowZero_244381022_2 = !(0);
inputIntValues4digitsHideZero_244381022_2 = 0;
enableOutput4digitsHideZero_244381022_2 = 0;
ClearDisplay_244381022_2 = 0;
if (enableOutputFloat_244381022_2 & !(enableOutput2digits_244381022_2) & !(enableOutput4digitsShowZero_244381022_2) & !(enableOutput4digitsHideZero_244381022_2)) disp_244381022_2.dispFloat(InputFloatValues_244381022_2, positionNumberFloat_244381022_2);
if (enableOutputSingleChar_244381022_2) disp_244381022_2.set(LED_0F_244381022_2[ numberCodeSymbols_244381022_2 ], positionNumberSingleChar_244381022_2);
if (enableOutput2digits_244381022_2 & !(enableOutputFloat_244381022_2) & !(enableOutput4digitsShowZero_244381022_2) & !(enableOutput4digitsHideZero_244381022_2)) disp_244381022_2.digit2(inputIntValues2digits_244381022_2, positionNumber2digits_244381022_2);
if (enableOutput4digitsShowZero_244381022_2 & !(enableOutput2digits_244381022_2) & !(enableOutputFloat_244381022_2) & !(enableOutput4digitsHideZero_244381022_2)) disp_244381022_2.digit4showZero(inputIntValues4digitsShowZero_244381022_2);
if (enableOutput4digitsHideZero_244381022_2 & !(enableOutput2digits_244381022_2) & !(enableOutputFloat_244381022_2) & !(enableOutput4digitsShowZero_244381022_2)) disp_244381022_2.digit4(inputIntValues4digitsHideZero_244381022_2);
if (ClearDisplay_244381022_2) disp_244381022_2.clear();
//Плата:2
//Наименование:датчик протечки
if (_isTimer(_SV3CP0Time, 1000))
{
_SV3CP0 = (String((byte(!((digitalRead (16))))), DEC));
_SV3CP0needSend = 1;
_SV3CP0Time = millis();
}
_gtv1 = _RV1CP0;
if(((((((!((digitalRead (16)))) || ((((((_gtv3) == (6.00)) && ((_gtv4) == (9.00)))) || (_bounseInputD8O))))) || (_gtv9))) || (_RV2CP0))) _trgs1 = 1;
if(((_bounseInputD4O) || (_RV1CP0))) _trgs1 = 0;
_gtv8 = _trgs1;
if (_isTimer(_SV2CP0Time, 1000))
{
_SV2CP0 = _trgs1;
_SV2CP0needSend = 1;
_SV2CP0Time = millis();
}
digitalWrite(15, !(_trgs1));
//Плата:3
if(_BitChange_2_Out)
{
_BitChange_2_Out = 0;
}
else
{
if(!(_BitChange_2_OldSt == _gtv8))
{
_BitChange_2_OldSt = _gtv8;
_BitChange_2_Out= 1;
}
}
if (_BitChange_2_Out)
{
if (_trgrt4I)
{
_trgrt4 = 0;
}
else
{
_trgrt4 = 1;
_trgrt4I = 1;
}
}
else
{
_trgrt4 = 0;
_trgrt4I = 0;
}
;
if(_trgrt4)
{
if(!_SEEPR2OSN)
{
(updateBooleanToEEPROM(1, 0, 0x0, (_gtv8)));
_SEEPR2OSN=1;
}
}
else
{
if(_SEEPR2OSN)
{
_SEEPR2OSN=0;
}
}
_gtv9 = (readBooleanFromEEPROM(1, 0, 0x0));
if(!(((String(_bmp085A, DEC)))==(_SV6CP0)))
{
_SV6CP0needSend = 1;
}
_SV6CP0 = (String(_bmp085A, DEC));
if(!(((_floatToStringWitRaz((_bmp085P)*(0.00750062),2)))==(_SV5CP0)))
{
_SV5CP0needSend = 1;
}
_SV5CP0 = (_floatToStringWitRaz((_bmp085P)*(0.00750062),2));
_gtv23 = (_floatToStringWitRaz((_bmp085T)/(10.00),1));
if(!(((_floatToStringWitRaz((_bmp085T)/(10.00),1)))==(_SV4CP0)))
{
_SV4CP0needSend = 1;
}
_SV4CP0 = (_floatToStringWitRaz((_bmp085T)/(10.00),1));
if(!(((String((analogRead (3)), DEC)))==(_SV7CP0)))
{
_SV7CP0needSend = 1;
}
_SV7CP0 = (String((analogRead (3)), DEC));
if(!(((String((byte(!((digitalRead (10))))), DEC)))==(_SV8CP0)))
{
_SV8CP0needSend = 1;
}
_SV8CP0 = (String((byte(!((digitalRead (10))))), DEC));
if(_isTimer(_d18x2x2Tti, 3000))
{
_d18x2x2Tti = millis();
_tempVariable_float = _readDS18_ow12(_d18x2x2Addr, 0);
if (_tempVariable_float < 500)
{
_d18x2x2O = _tempVariable_float;
}
}
_gtv20 = (_d18x2x2O);
//Плата:4
get3231Date(0x68, &_RTC1);
_RTC1_GetTime1_StrOut = (_convertRealTimeClockNumberToString(_RTC1.Hours))+
(_convertRealTimeClockNumberToString(_RTC1.minutes));
_RTC1_GetTime1_HourOut = _RTC1.Hours;
_RTC1_GetTime1_DayOut = _RTC1.day;
if((_RV3CP0) >= (10))
{
_swi10=(String(_RV3CP0, DEC));
}
else
{
_swi10=((String("0")) + ((String(_RV3CP0, DEC))));
}
if((_RV4CP0) >= (10))
{
_swi8=(String(_RV4CP0, DEC));
}
else
{
_swi8=((String("0")) + ((String(_RV4CP0, DEC))));
}
if(_RV6CP0)
{
_swi7=_RTC1_GetTime1_StrOut;
}
else
{
_swi7=((_swi8) + (_swi10));
}
_gtv10 = _swi7;
if(_RV6CP0)
{
_swi4=_RTC1_GetTime1_DayOut;
}
else
{
_swi4=_RV5CP0;
}
_gtv3 = _swi4;
if(_RV6CP0)
{
_swi5=_RTC1_GetTime1_HourOut;
}
else
{
_swi5=_RV4CP0;
}
_gtv4 = _swi5;
if (!(0))
{
_dispTempLength1 = ((_gtv10)).length();
if (_disp1oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(0, 0);
_lcd1.print((_gtv10));
}
else
{
if (_disp1oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp1oldLength = 0;
}
}
if (!(0))
{
_dispTempLength1 = ((((String("T")) + (_gtv23) + (String(" D")) + ((_floatToStringWitRaz(_gtv3,0)))))).length();
if (_disp4oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp4oldLength = _dispTempLength1;
_lcd1.setCursor(5, 0);
_lcd1.print((((String("T")) + (_gtv23) + (String(" D")) + ((_floatToStringWitRaz(_gtv3,0))))));
}
else
{
if (_disp4oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp4oldLength = 0;
}
}
if (_isTimer(_SV9CP0Time, 3000))
{
_SV9CP0 = (_floatToStringWitRaz(_gtv20,2));
_SV9CP0needSend = 1;
_SV9CP0Time = millis();
}
if(_gtv8)
{
_swi11=String("CLOS");
}
else
{
_swi11=String("OPEN");
}
if (!(0))
{
[I]dispTempLength1 = ((((String("Kr[/I]")) + (_swi11)))).length();
if (_disp2oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp2oldLength = _dispTempLength1;
_lcd1.setCursor(0, 1);
[I]lcd1.print((((String("Kr[/I]")) + (_swi11))));
}
else
{
if (_disp2oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp2oldLength = 0;
}
}
if (!(0))
{
_dispTempLength1 = ((((String("Gz=")) + ((String((analogRead (3)), DEC)))))).length();
if (_disp5oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp5oldLength = _dispTempLength1;
_lcd1.setCursor(9, 1);
_lcd1.print((((String("Gz=")) + ((String((analogRead (3)), DEC))))));
}
else
{
if (_disp5oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp5oldLength = 0;
}
}
if(_gtv1)
{
_swi1=String("0");
}
else
{
_swi1=String("1");
}
if (!(0))
{
_dispTempLength1 = ((_swi1)).length();
if (_disp3oldLength > _dispTempLength1)
{
_isNeedClearDisp1 = 1;
}
_disp3oldLength = _dispTempLength1;
_lcd1.setCursor(15, 1);
_lcd1.print((_swi1));
}
else
{
if (_disp3oldLength > 0)
{
_isNeedClearDisp1 = 1;
_disp3oldLength = 0;
}
}
if(_SV1CP0needSend)
{
_SV1CP0needSend = 0;
Serial.write (1);
Serial.print (1);
Serial.write (2);
Serial.print (_SV1CP0);
Serial.write (3);
}
if(_SV2CP0needSend)
{
_SV2CP0needSend = 0;
Serial.write (1);
Serial.print (2);
Serial.write (2);
Serial.print (_SV2CP0);
Serial.write (3);
}
if(_SV3CP0needSend)
{
_SV3CP0needSend = 0;
Serial.write (1);
Serial.print (3);
Serial.write (2);
Serial.print (_SV3CP0);
Serial.write (3);
}
if(_SV4CP0needSend)
{
_SV4CP0needSend = 0;
Serial.write (1);
Serial.print (4);
Serial.write (2);
Serial.print (_SV4CP0);
Serial.write (3);
}
if(_SV5CP0needSend)
{
_SV5CP0needSend = 0;
Serial.write (1);
Serial.print (5);
Serial.write (2);
Serial.print (_SV5CP0);
Serial.write (3);
}
if(_SV6CP0needSend)
{
_SV6CP0needSend = 0;
Serial.write (1);
Serial.print (6);
Serial.write (2);
Serial.print (_SV6CP0);
Serial.write (3);
}
if(_SV7CP0needSend)
{
_SV7CP0needSend = 0;
Serial.write (1);
Serial.print (7);
Serial.write (2);
Serial.print (_SV7CP0);
Serial.write (3);
}
if(_SV8CP0needSend)
{
_SV8CP0needSend = 0;
Serial.write (1);
Serial.print (8);
Serial.write (2);
Serial.print (_SV8CP0);
Serial.write (3);
}
if(_SV9CP0needSend)
{
_SV9CP0needSend = 0;
Serial.write (1);
Serial.print (9);
Serial.write (2);
Serial.print (_SV9CP0);
Serial.write (3);
}
}
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));
}
}
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());
}
data.mode=0;
data.data=String("");
return data;
}
float _convertDS18x2xData(byte type_s, byte data[12])
{
int16_t raw = (data[1] << 8) | data[0];
if (type_s)
{
raw = raw << 3;
if (data[7] == 0x10)
{
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else
{
byte cfg = (data[4] & 0x60);
if (cfg == 0x00)raw = raw & ~7;
else if(cfg == 0x20)raw = raw & ~3;
else if(cfg == 0x40) raw = raw & ~1;
}
return (float)raw / 16.0;
}
float _readDS18_ow12(byte addr[8], byte type_s)
{
byte data[12];
byte i;
_ow12.reset();
_ow12.select(addr);
_ow12.write(0xBE);
for (i = 0; i < 9; i++)
{
data[I] = _ow12.read();
}
_ow12.reset();
_ow12.select(addr);
_ow12.write(0x44);
if (_ow12.crc8(data, 8) != data[8])
{
return 501;
}
return _convertDS18x2xData(type_s, data);
}
void timerIsr_244381022_2()
{
disp_244381022_2.timerIsr();
}
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);
}
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));
}
byte tMSB, tLSB;
float result;
Wire.beginTransmission(addres);
Wire.write(0x11);
Wire.endTransmission();
Wire.requestFrom(addres, 2);
if (Wire.available())
{
tMSB = Wire.read();
tLSB = Wire.read();
result = (tMSB & B01111111);
result += ((tLSB >> 6) * 0.25);
timeStruct -> temper = result;
}
timeStruct ->startTime = millis();
}
String _convertRealTimeClockNumberToString(byte value)
{
if (value > 9)
{
return String(value, DEC);
}
return (String("0") + String(value, DEC));
}
void _startUart0()
{
int code= 6;
Serial.begin(9600, (_serialModeFromInt(code)));
}
int _serialModeFromInt(int code)
{
switch (code)
{
case 0x00: return SERIAL_5N1;
break;
case 0x02: return SERIAL_6N1;
break;
case 0x04: return SERIAL_7N1;
break;
case 0x06: return SERIAL_8N1;
break;
case 0x08: return SERIAL_5N2;
break;
case 0x0A: return SERIAL_6N2;
break;
case 0x0C: return SERIAL_7N2 ;
break;
case 0x0E: return SERIAL_8N2;
break;
case 0x20: return SERIAL_5E1;
break;
case 0x22: return SERIAL_6E1;
break;
case 0x24: return SERIAL_7E1 ;
break;
case 0x26: return SERIAL_8E1;
break;
case 0x28: return SERIAL_5E2 ;
break;
case 0x2A: return SERIAL_6E2;
break;
case 0x2C: return SERIAL_7E2;
break;
case 0x2E: return SERIAL_8E2;
break;
case 0x30: return SERIAL_5O1;
break;
case 0x32: return SERIAL_6O1;
break;
case 0x34: return SERIAL_7O1;
break;
case 0x36: return SERIAL_8O1;
break;
case 0x38: return SERIAL_5O2;
break;
case 0x3A: return SERIAL_6O2 ;
break;
case 0x3C: return SERIAL_7O2;
break;
case 0x3E: return SERIAL_8O2;
break;
}
return SERIAL_8N1;
}
[/I]