source
no way to compare when less than two revisions
Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Předchozí verzeNásledující verze | |||
— | source [2016/04/22 15:30] – [Info] mypower_cz | ||
---|---|---|---|
Řádek 1: | Řádek 1: | ||
+ | ====== Microlog2 Source ====== | ||
+ | ===== Info ===== | ||
+ | |||
+ | Verze 2.04 | ||
+ | |||
+ | ===== Kompilace projektu ===== | ||
+ | |||
+ | **Pozor: Pro kompilaci je potřeba použít [[https:// | ||
+ | |||
+ | V nových verzích se můžete setkat s chybou | ||
+ | |||
+ | microlog2: | ||
+ | ===== Notes ===== | ||
+ | |||
+ | * přidána podpora pro datum a čas, synchronizováno při přenosu na mypower.cz | ||
+ | * čítač sekund byl změněn na uint32_t | ||
+ | * mapa eprom byla přesunuta z kódu na [[mod: | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | ===== Download ===== | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | ===== Source ===== | ||
+ | |||
+ | <file c microlog2.ino> | ||
+ | |||
+ | // ---[ INFO ]---------------------------------------- | ||
+ | |||
+ | // Program: MyPower.CZ Microlog2 | ||
+ | // License: free for non-commercial use | ||
+ | // Details: info@mypower.cz | ||
+ | |||
+ | // ---[ VERSION ]------------------------------------- | ||
+ | |||
+ | #define MPWMicroLogVersion | ||
+ | |||
+ | // ---[ INCLUDE ]------------------------------------- | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // ---[ BUILT-IN CONFIG ]----------------------------- | ||
+ | |||
+ | int sendInterval | ||
+ | int sendRetry | ||
+ | byte maxErrors | ||
+ | |||
+ | byte NETmac[6] | ||
+ | //byte NETip[4] | ||
+ | byte NETip[4] | ||
+ | byte NETgw[4] | ||
+ | byte NETmask[4] | ||
+ | byte NETdns[4] | ||
+ | |||
+ | // ---[ DPIN 22..49 map ]-------------------------- | ||
+ | // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 | ||
+ | // [....... LED .....][.not used.][........... RELE .............] | ||
+ | byte DPINmap[16] | ||
+ | uint16_t DPINstatus | ||
+ | // < | ||
+ | uint16_t DPINlogicmask = (B00000000 << 8) | B00000011; | ||
+ | |||
+ | // ---[ MODS ]---------------------------------------- | ||
+ | |||
+ | // mod MyPowerLog | ||
+ | #define modMyPowerLog | ||
+ | #define modMyPowerHost | ||
+ | #define modMyPowerFVEID | ||
+ | |||
+ | // mod StausLed | ||
+ | #define modStatusLed | ||
+ | #define modStatusLedPin | ||
+ | |||
+ | // mod SerialLog | ||
+ | #define modSerialLog | ||
+ | #define modSerialForce | ||
+ | #define modSerialBaudRate | ||
+ | |||
+ | // mod WebServer | ||
+ | #define modWebServer | ||
+ | #define modWebServerPort | ||
+ | |||
+ | // mod Display | ||
+ | #define modDisplay | ||
+ | #define modDisplayType | ||
+ | |||
+ | // mod DisplayEmulation | ||
+ | #define modDisplayEmulation | ||
+ | // 0=display pripojen - zobrazeni na fyzickem displayi i na www rozhrani | ||
+ | |||
+ | // --------------------------------------------------- | ||
+ | |||
+ | byte lxLed=0; | ||
+ | byte lxTime=0; | ||
+ | uint32_t lxSeconds=0; | ||
+ | uint32_t lxSendIndex=0; | ||
+ | byte lxHttpOk=0; | ||
+ | byte lxHttpErrors=0; | ||
+ | |||
+ | // --------------------------------------------------- | ||
+ | |||
+ | #define dLCDKeyPad1602 | ||
+ | |||
+ | // --------------------------------------------------- | ||
+ | |||
+ | // TTT GG E | ||
+ | // 0000 0000 | ||
+ | |||
+ | #define xpinOPTdefault | ||
+ | #define xpinOPTenabled | ||
+ | |||
+ | #define xpinOPTtypeMask | ||
+ | |||
+ | #define xpinOPTsample | ||
+ | #define xpinOPTavg | ||
+ | #define xpinOPTeffective B00100000 | ||
+ | #define xpinOPTmin | ||
+ | #define xpinOPTmax | ||
+ | #define xpinOPTres1 | ||
+ | #define xpinOPTres2 | ||
+ | #define xpinOPTdefault | ||
+ | |||
+ | #define xpinOPTgroupMask B00001100 | ||
+ | |||
+ | #define xpinOPTsampleG0 | ||
+ | #define xpinOPTsampleG1 | ||
+ | #define xpinOPTsampleG2 | ||
+ | #define xpinOPTsampleG3 | ||
+ | |||
+ | struct tPinConf { | ||
+ | char xname[21]; | ||
+ | signed long xmin, | ||
+ | byte chsum; | ||
+ | }; | ||
+ | |||
+ | struct tDPinConf { | ||
+ | char xname[20]; | ||
+ | }; | ||
+ | |||
+ | #define xComStatusNop | ||
+ | #define xComStatusASchanged | ||
+ | #define xComStatusDSchanged | ||
+ | #define xComStatusIsLastDayInMonth | ||
+ | #define xComStatusIsDST | ||
+ | |||
+ | #define xComStatusXXDaysMonthMask | ||
+ | #define xComStatus28DaysMonth | ||
+ | #define xComStatus29DaysMonth | ||
+ | #define xComStatus30DaysMonth | ||
+ | #define xComStatus31DaysMonth | ||
+ | |||
+ | struct tMpwAccess { | ||
+ | byte xComStatus; | ||
+ | uint16_t mpwremoteDateYear; | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | signed long mpwremoteTimeS; | ||
+ | uint32_t mpwremoteCheckedAtS; | ||
+ | uint32_t mpwlogintimeS; | ||
+ | uint32_t mpwDeviceId; | ||
+ | uint32_t mpwAccessId; | ||
+ | } xMpwAccess; | ||
+ | |||
+ | struct tMpwDateTime { | ||
+ | int xyear, xmonth, xday, xhour, xminute, xsecond; | ||
+ | }; | ||
+ | |||
+ | #define xdcOptBuiltIn | ||
+ | #define xdcOptActive | ||
+ | |||
+ | struct tSampledPin { int pin; byte smpHi8[128]; | ||
+ | struct tPinValue { int smpVal, | ||
+ | struct tSamplerStruct { tPinValue tPinValues[NUM_ANALOG_INPUTS]; | ||
+ | byte tPinTimes[128]; | ||
+ | |||
+ | struct tDeviceConf { | ||
+ | char xfveid[21]; | ||
+ | int xsendInterval; | ||
+ | int xsendRetry; | ||
+ | byte xmaxErrors; | ||
+ | byte xdcOpt; | ||
+ | byte chsum; | ||
+ | }; | ||
+ | |||
+ | struct int64 { word hh, | ||
+ | |||
+ | // --------------------------------------------------- | ||
+ | |||
+ | #if modWebServer == 1 | ||
+ | EthernetServer server(modWebServerPort); | ||
+ | #endif | ||
+ | |||
+ | #if (modDisplay == 1) | ||
+ | byte lcdCurrentPage=0xFF; | ||
+ | byte lcdMaxPage=0; | ||
+ | |||
+ | #if (modDisplayType == dLCDKeyPad1602) | ||
+ | struct tDispStats { int xvarscount; int xvarram; }; | ||
+ | char _lcdlbuf[17]; | ||
+ | char * _lcdweblbuf0=NULL; | ||
+ | char * _lcdweblbuf1=NULL; | ||
+ | tDispStats * _lcdwebdispstats=NULL; | ||
+ | |||
+ | #if (modDisplayEmulation == 0) | ||
+ | #include < | ||
+ | LiquidCrystal lcd(8, 9, 14, 5, 6, 7); | ||
+ | void lcdClear() { lcd.clear(); | ||
+ | void lcdInit() { lcd.begin(16, | ||
+ | #else | ||
+ | void lcdClear() { } | ||
+ | void lcdInit() { lcdClear(); } | ||
+ | #endif | ||
+ | |||
+ | void lcdPrintRight(char * str) { int x=16-strlen(str); | ||
+ | void lcdPrintCenter(char * str) { int x=8-(strlen(str)/ | ||
+ | void lcdPrintLeft(char * str) { lcdPrintAt(str, | ||
+ | void lcdPrintAt(char * str,int x) { | ||
+ | int ix=strlen(str); | ||
+ | // int ix=strlen(str); | ||
+ | void lcdClearLine() { int i; for (i=0; | ||
+ | void lcdPrintLine(int y) { | ||
+ | if ((_lcdweblbuf0!=NULL) && (_lcdweblbuf1!=NULL)) | ||
+ | { char * p=_lcdweblbuf0; | ||
+ | else { | ||
+ | #if (modDisplayEmulation == 0) | ||
+ | lcd.setCursor(0, | ||
+ | #endif | ||
+ | } } | ||
+ | |||
+ | #endif | ||
+ | |||
+ | #endif | ||
+ | |||
+ | |||
+ | // -- [SETUP] ---------------------------------------------- | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | #if modStatusLed == 1 | ||
+ | pinMode(modStatusLedPin, | ||
+ | #endif | ||
+ | |||
+ | |||
+ | #if ((modSerialLog == 1) || (modSerialForce == 1)) | ||
+ | Serial.begin(modSerialBaudRate); | ||
+ | #endif | ||
+ | |||
+ | |||
+ | #if ((modSerialLog == 1) || (modDisplay == 1)) | ||
+ | char sn1[]=" | ||
+ | char sn2[]=" | ||
+ | |||
+ | #if (modSerialLog == 1) | ||
+ | XLog(sn1); | ||
+ | |||
+ | #if (modMyPowerLog == 1) | ||
+ | xMpwAccess.mpwremoteDateYear=0; | ||
+ | xMpwAccess.mpwremoteDateMonth=0; | ||
+ | xMpwAccess.mpwremoteDateDay=0; | ||
+ | xMpwAccess.mpwremoteDateWeek=0; | ||
+ | xMpwAccess.mpwremoteDateDayOfWeek=0; | ||
+ | xMpwAccess.mpwremoteTimeS=-1; | ||
+ | xMpwAccess.mpwremoteCheckedAtS=0; | ||
+ | xMpwAccess.mpwlogintimeS=0; | ||
+ | xMpwAccess.mpwDeviceId=0; | ||
+ | xMpwAccess.mpwAccessId=0; | ||
+ | xMpwAccess.xComStatus=xComStatusNop; | ||
+ | char cx[50]=" | ||
+ | #endif | ||
+ | |||
+ | #if (modDisplay == 1) | ||
+ | char ccx[50]=""; | ||
+ | #if (modDisplayEmulation == 1 ) | ||
+ | sprintf(ccx," | ||
+ | #else | ||
+ | sprintf(ccx," | ||
+ | #endif | ||
+ | XLog(ccx); | ||
+ | #endif | ||
+ | |||
+ | #endif | ||
+ | |||
+ | #if (modDisplay == 1) | ||
+ | lcdInit(); | ||
+ | lcdClearLine(); | ||
+ | lcdClearLine(); | ||
+ | #endif | ||
+ | |||
+ | #endif | ||
+ | |||
+ | DPINResetHW(); | ||
+ | pinMode(53, OUTPUT); | ||
+ | |||
+ | int xret=0; | ||
+ | |||
+ | boolean isdhcp=((NETip[0]& | ||
+ | |||
+ | if (isdhcp) | ||
+ | { | ||
+ | #if (modSerialLog == 1) | ||
+ | XLog(" | ||
+ | #endif | ||
+ | xret=Ethernet.begin(NETmac); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | Ethernet.begin(NETmac, | ||
+ | xret=1; | ||
+ | delay(1000); | ||
+ | } | ||
+ | |||
+ | W5100.setRetransmissionTime(0x07FF); | ||
+ | W5100.setRetransmissionCount(2); | ||
+ | |||
+ | if ( (xret == 0) && (isdhcp) ) { | ||
+ | #if modSerialLog == 1 | ||
+ | XLog(" | ||
+ | #endif | ||
+ | FlashError(4); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | #if modSerialLog == 1 | ||
+ | char xtext[100]; | ||
+ | char cf[]=" | ||
+ | IPAddress xaddr; | ||
+ | XLog(" | ||
+ | xaddr=Ethernet.localIP(); | ||
+ | for (byte i=0; | ||
+ | if (i==1) xaddr=Ethernet.subnetMask(); | ||
+ | if (i==2) xaddr=Ethernet.gatewayIP(); | ||
+ | if (i==3) xaddr=Ethernet.dnsServerIP(); | ||
+ | sprintf(xtext, | ||
+ | XLog(xtext); | ||
+ | } | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | #if modWebServer == 1 | ||
+ | server.begin(); | ||
+ | #if modSerialLog == 1 | ||
+ | char c[30]=""; | ||
+ | #endif | ||
+ | #endif | ||
+ | |||
+ | SamplerReset(); | ||
+ | |||
+ | #if modSerialLog == 1 | ||
+ | XLog(" | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | // -- [LOOP] ---------------------------------------------- | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | FlashLiveLed(); | ||
+ | CalculateSeconds(); | ||
+ | #if modMyPowerLog == 1 | ||
+ | SendDataToMyPower(); | ||
+ | #endif | ||
+ | #if modWebServer == 1 | ||
+ | WebServer(); | ||
+ | #endif | ||
+ | #if (modDisplay == 1) | ||
+ | #if (modDisplayType == dLCDKeyPad1602) | ||
+ | DisplayDetectButton(); | ||
+ | #endif | ||
+ | #endif | ||
+ | SamplerRun(); | ||
+ | } | ||
+ | |||
+ | void softReset() { asm volatile (" | ||
+ | |||
+ | #if modSerialLog == 1 | ||
+ | void XLog(char * xmsg) { Serial.println(xmsg); | ||
+ | void XLogRam() { Serial.print("> | ||
+ | void XLog2(char * xmsg,char * xpre) { Serial.print(xpre); | ||
+ | #endif | ||
+ | |||
+ | #if (modDisplay == 1) | ||
+ | void CalcDisplayConfEpromSpace(int * xa,int * la) { | ||
+ | * xa=(sizeof(tPinConf)*NUM_ANALOG_INPUTS)+sizeof(tDeviceConf); | ||
+ | * la=2047; } | ||
+ | #endif | ||
+ | |||
+ | |||
+ | void SetLiveLed(byte xs) { | ||
+ | #if modStatusLed==1 | ||
+ | digitalWrite(modStatusLedPin, | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | void FlashLiveLed() { | ||
+ | unsigned long i=((millis()/ | ||
+ | byte qlxLed=( ((i==1)) || ((lxHttpOk==2) && ( (i==3) || (i==5) )) )?HIGH:LOW; | ||
+ | if (qlxLed!=lxLed) { SetLiveLed(qlxLed); | ||
+ | } | ||
+ | |||
+ | void CalculateSeconds() { | ||
+ | byte smx=0x7F; int qlxTime=((millis()/ | ||
+ | if (qlxTime!=lxTime) { OneSecondActions(); | ||
+ | lxSeconds+=(lxTime> | ||
+ | } | ||
+ | |||
+ | void OneSecondActions() { | ||
+ | #if (modDisplay == 1) | ||
+ | DrawDisplayPage(); | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | #if modMyPowerLog==1 | ||
+ | void SendDataToMyPower() | ||
+ | { | ||
+ | boolean canrun=true; | ||
+ | for (int xp=0; | ||
+ | if (xSamplerStruct.tPinValues[xp].smpTime==0) | ||
+ | { canrun=false; | ||
+ | if (canrun) SendDataToMyPower_int(); | ||
+ | } | ||
+ | |||
+ | void SendDataToMyPower_int() | ||
+ | { | ||
+ | char xtext[200]; | ||
+ | int xsi=sendInterval; | ||
+ | int xsiorig=xsi; | ||
+ | int xsr=sendRetry; | ||
+ | if (lxHttpOk==2) xsi=xsr; | ||
+ | if (xsi<30) xsi=30; | ||
+ | uint32_t qlxSendIndex=lxSeconds; | ||
+ | if ((lxSendIndex+xsi< | ||
+ | { | ||
+ | lxHttpOk=2; | ||
+ | lxSendIndex=lxSeconds; | ||
+ | EthernetClient client; | ||
+ | SetLiveLed(HIGH); | ||
+ | #if modSerialLog == 1 | ||
+ | XLogRam(); | ||
+ | #endif | ||
+ | if ( (client.connect(modMyPowerHost, | ||
+ | { | ||
+ | #if modSerialLog == 1 | ||
+ | XLog("> | ||
+ | #endif | ||
+ | sprintf(xtext," | ||
+ | modMyPowerHost, | ||
+ | client.write((byte*)xtext, | ||
+ | |||
+ | boolean islogin=(xMpwAccess.mpwlogintimeS==0); | ||
+ | |||
+ | if (islogin) | ||
+ | { | ||
+ | strcpy(xtext," | ||
+ | for (int i=0; | ||
+ | if (xtext[i]==' | ||
+ | strcat(xtext," | ||
+ | client.write((byte*)xtext, | ||
+ | client.write(" | ||
+ | } | ||
+ | |||
+ | sprintf(xtext," | ||
+ | client.write((byte*)xtext, | ||
+ | sprintf(xtext," | ||
+ | client.write((byte*)xtext, | ||
+ | |||
+ | for (int xp=0; | ||
+ | { | ||
+ | |||
+ | tPinValue * qPinValue; | ||
+ | qPinValue=& | ||
+ | sprintf(xtext," | ||
+ | qPinValue-> | ||
+ | client.write((byte*)xtext, | ||
+ | |||
+ | if ( (islogin) || ((xMpwAccess.xComStatus& | ||
+ | { | ||
+ | tPinConf pconf; | ||
+ | boolean isvalid=ReadPinConf(& | ||
+ | if (isvalid) | ||
+ | { | ||
+ | char smin10k[30]=""; | ||
+ | char smax10k[30]=""; | ||
+ | // sprintf(xtext," | ||
+ | sprintf(xtext," | ||
+ | client.write((byte*)xtext, | ||
+ | xtext[0]=0; | ||
+ | char xf[]=" | ||
+ | char xh[3]; | ||
+ | byte * p; | ||
+ | p=(byte*)pconf.xname; | ||
+ | for (int i=0; | ||
+ | client.write((byte*)xtext, | ||
+ | strcpy(xtext,"/" | ||
+ | p=(byte*)pconf.xunit; | ||
+ | for (int i=0; | ||
+ | client.write((byte*)xtext, | ||
+ | client.write("; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | xMpwAccess.xComStatus& | ||
+ | | ||
+ | client.write(" | ||
+ | | ||
+ | int lbufpos=0; | ||
+ | boolean ishead=true; | ||
+ | xtext[0]=0; | ||
+ | unsigned long xmstart=millis(); | ||
+ | while (client.connected()) | ||
+ | { | ||
+ | if (millis()-xmstart> | ||
+ | if (client.available()) | ||
+ | { | ||
+ | byte qbuf[200]; | ||
+ | int qlen=client.readBytes((char*)qbuf, | ||
+ | for (int i=0; | ||
+ | char c = qbuf[i]; | ||
+ | if (c==' | ||
+ | if (xtext[0]==' | ||
+ | if (!ishead) ParseHTTPResult(xtext); | ||
+ | lbufpos=0; | ||
+ | xtext[0]=0; | ||
+ | } | ||
+ | else { | ||
+ | if (lbufpos< | ||
+ | xtext[lbufpos]=c; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | if (lbufpos> | ||
+ | client.stop(); | ||
+ | } | ||
+ | if (lxHttpOk==1) | ||
+ | { | ||
+ | #if modSerialLog == 1 | ||
+ | XLog("> | ||
+ | sprintf(xtext,"> | ||
+ | XLog(xtext); | ||
+ | #endif | ||
+ | lxHttpErrors=0; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | lxHttpErrors++; | ||
+ | #if modSerialLog == 1 | ||
+ | sprintf(xtext,"> | ||
+ | XLog(xtext); | ||
+ | #endif | ||
+ | if (lxHttpErrors> | ||
+ | #if modSerialLog == 1 | ||
+ | else | ||
+ | sprintf(xtext,"> | ||
+ | XLog(xtext); | ||
+ | #endif | ||
+ | } | ||
+ | SetLiveLed(LOW); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void ParseHTTPResult(char * xtext) { | ||
+ | #if modSerialLog == 1 | ||
+ | XLog2(xtext,"# | ||
+ | #endif | ||
+ | if (strcmp(xtext," | ||
+ | if (strncmp(xtext," | ||
+ | } | ||
+ | |||
+ | void ParseQID(char * xtext) { | ||
+ | if (xMpwAccess.mpwlogintimeS==0) xMpwAccess.mpwlogintimeS=lxSeconds; | ||
+ | char * p=strchr(xtext,' | ||
+ | if (p!=NULL) | ||
+ | { | ||
+ | p[0]=0; | ||
+ | xMpwAccess.mpwDeviceId=atol(xtext); | ||
+ | p++; | ||
+ | char * px=strchr(p,' | ||
+ | if (px!=NULL) | ||
+ | { | ||
+ | px[0]=0; | ||
+ | px++; | ||
+ | xMpwAccess.mpwAccessId=atol(p); | ||
+ | if (strlen(px)==20) | ||
+ | { | ||
+ | char c[30]=""; | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | strncpy(c, | ||
+ | |||
+ | if (xisdst==1) | ||
+ | xMpwAccess.xComStatus|=xComStatusIsDST; | ||
+ | else | ||
+ | xMpwAccess.xComStatus& | ||
+ | |||
+ | if (xdaysinmonth==xMpwAccess.mpwremoteDateDay) | ||
+ | xMpwAccess.xComStatus|=xComStatusIsLastDayInMonth; | ||
+ | else | ||
+ | xMpwAccess.xComStatus& | ||
+ | | ||
+ | xMpwAccess.xComStatus& | ||
+ | if (xdaysinmonth==28) xMpwAccess.xComStatus|=xComStatus28DaysMonth; | ||
+ | if (xdaysinmonth==29) xMpwAccess.xComStatus|=xComStatus29DaysMonth; | ||
+ | if (xdaysinmonth==30) xMpwAccess.xComStatus|=xComStatus30DaysMonth; | ||
+ | if (xdaysinmonth==31) xMpwAccess.xComStatus|=xComStatus31DaysMonth; | ||
+ | | ||
+ | xMpwAccess.mpwremoteTimeS=(xhour*3600)+(xminute*60)+(xsecond); | ||
+ | xMpwAccess.mpwremoteCheckedAtS=lxSeconds; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | / | ||
+ | char xstr[50]=""; | ||
+ | tMpwDateTime xMpwDateTime; | ||
+ | GetCurrentDateTime(& | ||
+ | FormatDateTimeStr(xstr, | ||
+ | Serial.println(xstr); | ||
+ | */ | ||
+ | } | ||
+ | #endif | ||
+ | |||
+ | |||
+ | |||
+ | void FormatDateTimeStr(char * xstr, char * xfmt, struct tMpwDateTime * xMpwDateTime, | ||
+ | { | ||
+ | xstr[0]=0; | ||
+ | while (strlen(xfmt)> | ||
+ | { | ||
+ | char ch=xfmt[0]; | ||
+ | char cout[20]=""; | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | if (ch==' | ||
+ | { cout[0]=ch; | ||
+ | | ||
+ | xfmt++; | ||
+ | if (strlen(xstr)+strlen(cout)< | ||
+ | } | ||
+ | } | ||
+ | |||
+ | int GetCurrentDateTime_DaysInMonth() | ||
+ | { | ||
+ | int xret=28; | ||
+ | int xst=xMpwAccess.xComStatus& | ||
+ | if (xst==xComStatus28DaysMonth) xret=28; else | ||
+ | if (xst==xComStatus29DaysMonth) xret=29; else | ||
+ | if (xst==xComStatus30DaysMonth) xret=30; else | ||
+ | if (xst==xComStatus31DaysMonth) xret=31; | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | void GetCurrentDateTime(struct tMpwDateTime * xMpwDateTime) | ||
+ | { | ||
+ | if (xMpwAccess.mpwremoteCheckedAtS> | ||
+ | { | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | uint32_t xtime=lxSeconds-xMpwAccess.mpwremoteCheckedAtS+xMpwAccess.mpwremoteTimeS; | ||
+ | if (xtime> | ||
+ | { | ||
+ | int xdaysover=xtime/ | ||
+ | int xtimeover=xtime%86400UL; | ||
+ | |||
+ | if (xdaysover> | ||
+ | { | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | int xdaysinmonth=GetCurrentDateTime_DaysInMonth(); | ||
+ | for (int i=0; | ||
+ | { | ||
+ | if (xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | else | ||
+ | { | ||
+ | xMpwDateTime-> | ||
+ | if (xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | else | ||
+ | { | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | xtime=xtimeover; | ||
+ | } | ||
+ | xMpwDateTime-> | ||
+ | int xmod=(xtime%3600); | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | uint32_t xtime=lxSeconds; | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | signed long xmod=((xtime%86400L)%3600); | ||
+ | xMpwDateTime-> | ||
+ | xMpwDateTime-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | void FlashError(byte xcount) | ||
+ | { | ||
+ | #if modSerialLog == 1 | ||
+ | char xtext[50]; | ||
+ | sprintf(xtext," | ||
+ | XLog(xtext); | ||
+ | XLog(" | ||
+ | #endif | ||
+ | xcount*=2; | ||
+ | for (int i=0; | ||
+ | byte x=0; | ||
+ | for (int i=0; | ||
+ | SetLiveLed((!((x++)& | ||
+ | delay(250); | ||
+ | } | ||
+ | delay(1000); | ||
+ | } | ||
+ | #if modSerialLog == 1 | ||
+ | XLog(" | ||
+ | XLog(" | ||
+ | #endif | ||
+ | delay(1000); | ||
+ | softReset(); | ||
+ | } | ||
+ | |||
+ | int freeRam() { | ||
+ | extern unsigned int __heap_start; | ||
+ | extern void *__brkval; | ||
+ | int free_memory; | ||
+ | if (__brkval == 0) free_memory = (int) & | ||
+ | else free_memory = (int) & | ||
+ | return (free_memory); | ||
+ | } | ||
+ | |||
+ | |||
+ | byte calcPchsum(byte xpin, struct tPinConf * pconf) { | ||
+ | byte*xconf=(byte*)pconf; | ||
+ | pconf-> | ||
+ | pconf-> | ||
+ | |||
+ | boolean ReadPinConf(struct tPinConf * pconf,int xpin) | ||
+ | { | ||
+ | boolean xret=false; | ||
+ | if (xpin< | ||
+ | { | ||
+ | byte * pcx=(byte*)pconf; | ||
+ | int sp=sizeof(tPinConf); | ||
+ | // int xs=(xpin*sp); | ||
+ | int xs=GetEpromPinAddr(xpin); | ||
+ | if (xs>=0) | ||
+ | { | ||
+ | for (int ax=0; | ||
+ | xret=(calcPchsum(xpin, | ||
+ | } | ||
+ | } | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | int GetEpromPinAddr(int xpin) | ||
+ | { | ||
+ | int xret=-1; | ||
+ | if (xpin< | ||
+ | xret=(xpin*sizeof(tPinConf)); | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | |||
+ | // -- [WEB SERVER] ---------------------------------------------- | ||
+ | |||
+ | |||
+ | #if modWebServer == 1 | ||
+ | |||
+ | #define xWEBhome | ||
+ | #define xWEBcfgp | ||
+ | #define xWEBcfg | ||
+ | #define xWEBmpw | ||
+ | #define xWEBpins | ||
+ | |||
+ | #define xCFGnone | ||
+ | #define xCFGk 0x10 | ||
+ | #define xCFGv 0x20 | ||
+ | #define xCFGs 0x30 | ||
+ | |||
+ | // w = write | ||
+ | // [w]as = analog settings | ||
+ | // [w]ds = digital settings | ||
+ | // [w]dp = display | ||
+ | // [w]ep = eprom | ||
+ | // hw = hwinfo | ||
+ | // dd = display dump | ||
+ | // db = display button press emulation | ||
+ | |||
+ | #define xACTnone | ||
+ | #define xACThw | ||
+ | #define xACTas | ||
+ | #define xACTdp | ||
+ | #define xACTdd | ||
+ | #define xACTdb | ||
+ | #define xACTsp | ||
+ | #define xACTds | ||
+ | #define xACTep | ||
+ | |||
+ | #define xACTwds | ||
+ | #define xACTwep | ||
+ | #define xACTwas | ||
+ | #define xACTwdp | ||
+ | |||
+ | #define xKEYnone | ||
+ | #define xKEYcmd | ||
+ | #define xKEYpin | ||
+ | #define xKEYDispButt | ||
+ | #define xKEYDpin | ||
+ | |||
+ | #define xPinOptNone | ||
+ | #define xPinOptEnabled | ||
+ | #define xPinOptName | ||
+ | #define xPinOptMin | ||
+ | #define xPinOptMax | ||
+ | #define xPinOptUnit | ||
+ | #define xPinOptType | ||
+ | #define xPinOptGroup | ||
+ | #define xPinCmdWrite | ||
+ | |||
+ | #define xDPinOptNone | ||
+ | #define xDPinOptName | ||
+ | |||
+ | #define xDPinOptSetStatus 0xA0 | ||
+ | |||
+ | #define xDPinSetStatus | ||
+ | |||
+ | void WebServer_pf(char * xstr,signed long * xsl,int * xsl10k) { | ||
+ | int im; *xsl=0; | ||
+ | for (int i=0; | ||
+ | boolean hm=(p[0]==' | ||
+ | for (int i=0; | ||
+ | im=strlen(p10k); | ||
+ | for (int i=0; | ||
+ | *xsl10k+=(p10k[i]-' | ||
+ | if (hm) *xsl=0-*xsl; | ||
+ | if (hm) *xsl10k=0-*xsl10k; | ||
+ | } | ||
+ | |||
+ | void WebServer_wp(byte xpin, struct tPinConf * pconf) { | ||
+ | if (xpin< | ||
+ | xMpwAccess.xComStatus|=xComStatusASchanged; | ||
+ | byte*xconf=(byte*)pconf; | ||
+ | int ax=GetEpromPinAddr(xpin); | ||
+ | if (ax>=0) | ||
+ | for (int ii=0; | ||
+ | if (EEPROM.read(ax+ii) != xconf[ii]) | ||
+ | EEPROM.write(ax+ii, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void WebServer_wdp(byte xdpin, struct tDPinConf * pconf) { | ||
+ | if (xdpin< | ||
+ | xMpwAccess.xComStatus|=xComStatusDSchanged; | ||
+ | DPIN_epWriteConfName(xdpin, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | byte WebServer_pb(char * xstr) { | ||
+ | byte cb=0; for (int i=0; | ||
+ | if ((c> | ||
+ | return cb; | ||
+ | } | ||
+ | |||
+ | word WebServer_c(char * lbuf,char c,word xmode, byte * datastruct, unsigned long * xparam) { | ||
+ | byte qmode=xmode& | ||
+ | if (qmode==xWEBhome) { | ||
+ | if (strncmp(lbuf," | ||
+ | char * p=lbuf+5; | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (qmode!=xWEBhome) lbuf[0]=0; | ||
+ | } | ||
+ | } | ||
+ | else if (qmode==xWEBcfgp) { | ||
+ | if (c=='?' | ||
+ | { qsubmode=xCFGk; | ||
+ | else if ((c=='&' | ||
+ | { WebServer_p(lbuf,& | ||
+ | else if (c==' | ||
+ | { WebServer_p(lbuf,& | ||
+ | if (qsubmode!=xCFGs) { qsubmode=xCFGv; | ||
+ | if (c==' ') { qmode=xWEBcfg; | ||
+ | if (qsubmode==xCFGv) WebServer_h(lbuf); | ||
+ | if (qsubmode==xCFGs) WebServer_s(lbuf,& | ||
+ | } | ||
+ | return ((qmode|qsubmode)|((qsaction|wkey)<< | ||
+ | } | ||
+ | |||
+ | void WebServer_e(byte * qsaction, unsigned long * xparam) | ||
+ | { | ||
+ | #if modDisplay == 1 | ||
+ | if (*qsaction==xACTwdp) | ||
+ | { | ||
+ | byte chsum=((*xparam)& | ||
+ | int xaddr=((*xparam>> | ||
+ | int xa, | ||
+ | int raddr=xaddr+xa+1; | ||
+ | if (raddr< | ||
+ | if (EEPROM.read(la)!=0) EEPROM.write(la, | ||
+ | if (EEPROM.read(xa)!=chsum) EEPROM.write(xa, | ||
+ | } | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | unsigned long WebServer_ph(char * lbuf) | ||
+ | { | ||
+ | unsigned long d=0; | ||
+ | for (byte ii=0; | ||
+ | char c=lbuf[ii]; | ||
+ | if (c=' | ||
+ | d=(d<< | ||
+ | } | ||
+ | return d; | ||
+ | } | ||
+ | |||
+ | void WebServer_s(char * lbuf,byte * qsaction, | ||
+ | { | ||
+ | #if modDisplay == 1 | ||
+ | if (*qsaction==xACTwdp) | ||
+ | { | ||
+ | if (strlen(lbuf)==2) | ||
+ | { | ||
+ | byte d=0; | ||
+ | for (byte ii=0; | ||
+ | char c=lbuf[ii]; | ||
+ | d=(d<< | ||
+ | } | ||
+ | lbuf[0]=0; | ||
+ | if (d==0) d=32; | ||
+ | byte chsum=((*xparam)& | ||
+ | int xaddr=((*xparam>> | ||
+ | int xa, | ||
+ | int raddr=xaddr+xa+1; | ||
+ | if (raddr< | ||
+ | { | ||
+ | if (EEPROM.read(raddr)!=d) EEPROM.write(raddr, | ||
+ | chsum+=((d& | ||
+ | xaddr++; | ||
+ | } | ||
+ | *xparam=(chsum|((unsigned long)xaddr<< | ||
+ | } | ||
+ | } | ||
+ | #endif | ||
+ | } | ||
+ | |||
+ | void WebServer_h(char * lbuf) | ||
+ | { | ||
+ | int cx=strlen(lbuf); | ||
+ | char * p=lbuf+cx; | ||
+ | while ((p> | ||
+ | if ((p> | ||
+ | byte d=0; | ||
+ | for (byte ii=1; | ||
+ | d=d<< | ||
+ | if ((c> | ||
+ | if ((c> | ||
+ | } | ||
+ | byte pr=' | ||
+ | if (d==pr) { p[0]=pr; | ||
+ | if (d==0) { p[0]=pr; | ||
+ | else p[0]=d; | ||
+ | p++; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void WebServer_p(char * xstr,byte * qsubmode, | ||
+ | unsigned long * xparam) | ||
+ | { | ||
+ | int ix=strlen(xstr); | ||
+ | if (ix>0){ ix--; | ||
+ | if (* qsubmode==xCFGk) | ||
+ | { | ||
+ | | ||
+ | #if modDisplay == 1 | ||
+ | if (*qsaction==xACTdb) | ||
+ | { | ||
+ | if (strcmp(xstr," | ||
+ | } | ||
+ | else | ||
+ | if (*qsaction==xACTwdp) | ||
+ | { | ||
+ | if (strcmp(xstr," | ||
+ | } | ||
+ | else | ||
+ | #endif | ||
+ | if (*qsaction==xACTwds) | ||
+ | { | ||
+ | char * p=xstr; | ||
+ | if (strcmp(xstr," | ||
+ | { | ||
+ | byte xpinopt=xDPinSetStatus; | ||
+ | *xparam& | ||
+ | *xparam|=xpinopt; | ||
+ | } | ||
+ | else | ||
+ | if (p[0]==' | ||
+ | { | ||
+ | p++; | ||
+ | int xpinindex=atoi(p)& | ||
+ | byte xpinopt=xDPinOptSetStatus; | ||
+ | *xparam& | ||
+ | *xparam|=xpinopt|(xpinindex<< | ||
+ | } | ||
+ | else | ||
+ | if (p[0]==' | ||
+ | { | ||
+ | p++; | ||
+ | char * px=p; | ||
+ | for (int ii=1; | ||
+ | if (p[0]==' | ||
+ | int xpinindex=atoi(px); | ||
+ | byte xpinopt=xDPinOptNone; | ||
+ | if (strcmp(p," | ||
+ | *xparam& | ||
+ | *xparam|=xpinopt|(xpinindex<< | ||
+ | } | ||
+ | *wkey=xKEYDpin; | ||
+ | } | ||
+ | else | ||
+ | if (*qsaction==xACTwas) | ||
+ | { | ||
+ | char * p=xstr; | ||
+ | if (p[0]==' | ||
+ | { | ||
+ | p++; | ||
+ | char * px=p; | ||
+ | for (int ii=1; | ||
+ | if (p[0]==' | ||
+ | byte xpinopt=xPinOptNone; | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | if (strcmp(p," | ||
+ | *xparam& | ||
+ | *xparam|=xpinopt; | ||
+ | } | ||
+ | *wkey=xKEYpin; | ||
+ | } | ||
+ | else | ||
+ | if (strcmp(xstr," | ||
+ | else | ||
+ | *wkey=xKEYnone; | ||
+ | } | ||
+ | else | ||
+ | if (* qsubmode==xCFGv) | ||
+ | { | ||
+ | if (ix>0){ ix--; | ||
+ | | ||
+ | #if modDisplay == 1 | ||
+ | if (*wkey==xKEYDispButt) | ||
+ | { | ||
+ | DisplayPressButton(xstr); | ||
+ | } | ||
+ | else | ||
+ | #endif | ||
+ | |||
+ | // --------------------------------------- | ||
+ | |||
+ | if (*wkey==xKEYDpin) | ||
+ | { | ||
+ | byte xpk=((*xparam)& | ||
+ | tDPinConf * pconf; | ||
+ | pconf=(tDPinConf*)datastruct; | ||
+ | | ||
+ | if (xpk==xDPinOptName) | ||
+ | { | ||
+ | int xpinindex=(((*xparam)& | ||
+ | strncpy(pconf-> | ||
+ | DPIN_epWriteConfName(xpinindex, | ||
+ | for (int ii=0; | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xDPinSetStatus) { | ||
+ | DPINstatus=(uint16_t)WebServer_ph(xstr); | ||
+ | DPINUpdateHW(); | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xDPinOptSetStatus) { | ||
+ | int xpinindex=(((*xparam)& | ||
+ | uint16_t xpinstatus=(atoi(xstr))& | ||
+ | DPINstatus& | ||
+ | DPINstatus|=(xpinstatus<< | ||
+ | DPINUpdateHW(); | ||
+ | } | ||
+ | |||
+ | | ||
+ | } | ||
+ | else | ||
+ | // --------------------------------------- | ||
+ | if (*wkey==xKEYpin) | ||
+ | { | ||
+ | byte xpk=((*xparam)& | ||
+ | tPinConf * pconf; | ||
+ | pconf=(tPinConf*)datastruct; | ||
+ | | ||
+ | if (xpk==xPinOptEnabled) { | ||
+ | if (strcmp(xstr," | ||
+ | pconf-> | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xPinOptName) | ||
+ | { | ||
+ | strncpy(pconf-> | ||
+ | pconf-> | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xPinOptMin) { | ||
+ | signed long xsl=0;int xsl10000=0; | ||
+ | WebServer_pf(xstr,& | ||
+ | pconf-> | ||
+ | } | ||
+ | else if (xpk==xPinOptMax) { | ||
+ | signed long xsl=0;int xsl10000=0; | ||
+ | WebServer_pf(xstr,& | ||
+ | pconf-> | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xPinOptUnit) | ||
+ | strncpy(pconf-> | ||
+ | else | ||
+ | if (xpk==xPinOptType) | ||
+ | { | ||
+ | char w=xstr[0]; | ||
+ | pconf-> | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xPinOptGroup) | ||
+ | { | ||
+ | char w=xstr[0]; | ||
+ | pconf-> | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | if (w==' | ||
+ | } | ||
+ | else | ||
+ | if (xpk==xPinCmdWrite) { | ||
+ | WebServer_wp(WebServer_pb(xstr), | ||
+ | for (int ii=0; | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | // -------------------------------------------- | ||
+ | else | ||
+ | if (*wkey==xKEYcmd) | ||
+ | { | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | if (strcmp(xstr," | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void WebServer() { | ||
+ | EthernetClient client = server.available(); | ||
+ | if (client) { | ||
+ | boolean cl = true; | ||
+ | char xln[200]=""; | ||
+ | word xmode=xWEBhome; | ||
+ | unsigned long xparam=0; | ||
+ | int cx=sizeof(tPinConf); | ||
+ | int cxq=sizeof(tDPinConf); | ||
+ | byte xDataStruct[cx]; | ||
+ | for (int ii=0; | ||
+ | int ix=0; | ||
+ | SetLiveLed(HIGH); | ||
+ | while (client.connected()) { | ||
+ | if (client.available()) | ||
+ | { | ||
+ | char c=client.read(); | ||
+ | if (c==' | ||
+ | ix=strlen(xln); | ||
+ | if (ix< | ||
+ | xmode=WebServer_c(xln, | ||
+ | byte qmode=xmode& | ||
+ | byte qsubmode=xmode& | ||
+ | byte qsaction=(xmode>> | ||
+ | if (c == ' | ||
+ | client.write(" | ||
+ | if (qsaction==xACTep) | ||
+ | { | ||
+ | client.write(" | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | client.write(" | ||
+ | client.write(" | ||
+ | } | ||
+ | else | ||
+ | client.write(" | ||
+ | if (qmode==xWEBpins) { | ||
+ | for (int ain = 0; ain < NUM_ANALOG_INPUTS; | ||
+ | if (ain>0) client.write("," | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | if (qsaction==xACThw) | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | char cq[]=" | ||
+ | sprintf(xln, | ||
+ | (int)lxHttpErrors, | ||
+ | client.write((byte*)xln, | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | sprintf(xln, | ||
+ | (int)E2END, | ||
+ | client.write((byte*)xln, | ||
+ | sprintf(xln," | ||
+ | NETmac[0], | ||
+ | client.write((byte*)xln, | ||
+ | char cf[]=" | ||
+ | IPAddress xaddr; | ||
+ | xaddr=Ethernet.localIP(); | ||
+ | for (byte i=0; | ||
+ | { | ||
+ | if (i==1) xaddr=Ethernet.subnetMask(); | ||
+ | if (i==2) xaddr=Ethernet.gatewayIP(); | ||
+ | if (i==3) xaddr=Ethernet.dnsServerIP(); | ||
+ | sprintf(xln, | ||
+ | if (i<3) strcat(xln,"/" | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | client.write(" | ||
+ | for (int i=0; | ||
+ | { | ||
+ | int qb=DPINmap[i]; | ||
+ | sprintf(xln," | ||
+ | if (i<16) strcat(xln,"," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | sprintf(xln,"/ | ||
+ | client.write((byte*)xln, | ||
+ | |||
+ | char xstr[30]=""; | ||
+ | tMpwDateTime xMpwDateTime; | ||
+ | GetCurrentDateTime(& | ||
+ | FormatDateTimeStr(xstr, | ||
+ | |||
+ | |||
+ | sprintf(xln," | ||
+ | (int)xMpwAccess.mpwremoteDateMonth, | ||
+ | (int)xMpwAccess.mpwremoteDateDay, | ||
+ | (signed long)xMpwAccess.mpwremoteTimeS, | ||
+ | xMpwAccess.mpwremoteCheckedAtS, | ||
+ | xMpwAccess.mpwlogintimeS, | ||
+ | xMpwAccess.mpwDeviceId, | ||
+ | xMpwAccess.mpwAccessId, | ||
+ | (int)xMpwAccess.xComStatus, | ||
+ | (int)xMpwAccess.mpwremoteDateWeek, | ||
+ | (int)xMpwAccess.mpwremoteDateDayOfWeek, | ||
+ | (unsigned long)(lxSeconds-xMpwAccess.mpwremoteCheckedAtS)); | ||
+ | client.write((byte*)xln, | ||
+ | | ||
+ | } | ||
+ | else | ||
+ | // ---------------------------------- | ||
+ | if ((qsaction==xACTds) || (qsaction==xACTwds)) | ||
+ | { | ||
+ | if (qsaction==xACTwds) client.write(" | ||
+ | for (int xp=0; | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | char cname[30]=""; | ||
+ | DPIN_epReadConfName(xp, | ||
+ | xln[0]=0; | ||
+ | char xf[]=" | ||
+ | char xh[3]; | ||
+ | for (int i=0; | ||
+ | int xi=(uint8_t)cname[i]; | ||
+ | sprintf(xh, | ||
+ | strcat(xln, | ||
+ | } | ||
+ | strcat(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | else | ||
+ | // ---------------------------------- | ||
+ | if ((qsaction==xACTas) || (qsaction==xACTwas)) | ||
+ | { | ||
+ | if (qsaction==xACTwas) client.write(" | ||
+ | for (int xp=0; | ||
+ | { | ||
+ | tPinConf pconf; | ||
+ | boolean isvalid=ReadPinConf(& | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | if (!isvalid) | ||
+ | strcat(xln," | ||
+ | else | ||
+ | { | ||
+ | char smin10k[30]=""; | ||
+ | char smax10k[30]=""; | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | xln[0]=0; | ||
+ | char xf[]=" | ||
+ | char xh[3]; | ||
+ | byte * p; | ||
+ | p=(byte*)pconf.xname; | ||
+ | for (int i=0; | ||
+ | sprintf(xh, | ||
+ | client.write((byte*)xln, | ||
+ | strcpy(xln,"/" | ||
+ | p=(byte*)pconf.xunit; | ||
+ | for (int i=0; | ||
+ | sprintf(xh, | ||
+ | strcat(xln,"/" | ||
+ | client.write((byte*)xln, | ||
+ | sprintf(xln," | ||
+ | } | ||
+ | strcat(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | if (qsaction==xACTsp) | ||
+ | { | ||
+ | client.write(" | ||
+ | byte qindex=0; | ||
+ | while (true) | ||
+ | { | ||
+ | qindex++; | ||
+ | byte qpins[4]; | ||
+ | SamplerGet4PinGroup(qpins,& | ||
+ | SamplerExec(qpins,& | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | for (int x=0; | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | client.write(" | ||
+ | for (int p=0; | ||
+ | { | ||
+ | tSampledPin * qSampledPin=& | ||
+ | int qpin=qSampledPin-> | ||
+ | if (qpin< | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | client.write((byte*)xln, | ||
+ | for (int x=0; | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | client.write("/" | ||
+ | for (int x=0; | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | client.write(" | ||
+ | } | ||
+ | } | ||
+ | if (qindex==0) break; | ||
+ | } | ||
+ | for (int x=0; | ||
+ | { | ||
+ | tPinValue * qPinValue; | ||
+ | qPinValue=& | ||
+ | sprintf(xln," | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | if ((qsaction==xACTdp) || (qsaction==xACTwdp)) | ||
+ | { | ||
+ | if (qsaction==xACTwdp) | ||
+ | client.write(" | ||
+ | else | ||
+ | client.write(" | ||
+ | #if modDisplay == 1 | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | int xa,la; | ||
+ | CalcDisplayConfEpromSpace(& | ||
+ | int xs=la-xa; | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | byte chsum=0; | ||
+ | byte rchsum=EEPROM.read(xa); | ||
+ | for (int i=1; | ||
+ | { | ||
+ | int xv=EEPROM.read(xa+i); | ||
+ | if (xv==0) break; | ||
+ | chsum+=((xv& | ||
+ | sprintf(xln," | ||
+ | if ((i-1)%10==9) strcat(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | if (EEPROM.read(la)!=0) EEPROM.write(la, | ||
+ | client.write(" | ||
+ | #endif | ||
+ | } | ||
+ | else | ||
+ | | ||
+ | #if ((modDisplay == 1) && (modDisplayType == dLCDKeyPad1602)) | ||
+ | if (qsaction==xACTdd) | ||
+ | { | ||
+ | char lcdlbuf0[17]=""; | ||
+ | char lcdlbuf1[17]=""; | ||
+ | _lcdweblbuf0=lcdlbuf0; | ||
+ | _lcdweblbuf1=lcdlbuf1; | ||
+ | tDispStats lcdwebdispstats; | ||
+ | _lcdwebdispstats=& | ||
+ | DrawDisplayPage(); | ||
+ | client.write(" | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | _lcdweblbuf0=NULL; | ||
+ | _lcdweblbuf1=NULL; | ||
+ | _lcdwebdispstats=NULL; | ||
+ | } | ||
+ | else | ||
+ | #endif | ||
+ | #if (modDisplay == 1) | ||
+ | if (qsaction==xACTdb) | ||
+ | { | ||
+ | client.write(" | ||
+ | } | ||
+ | else | ||
+ | # | ||
+ | if (qsaction==xACTep) | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | unsigned long xsum=0; | ||
+ | char s[20]=""; | ||
+ | for (int i=0; | ||
+ | { | ||
+ | if ((i& | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | int v=EEPROM.read(i); | ||
+ | sprintf(xln," | ||
+ | int xi=i& | ||
+ | s[xi]=((v> | ||
+ | s[xi+1]=0; | ||
+ | client.write((byte*)xln, | ||
+ | xsum=(((xsum>> | ||
+ | if ((i& | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | s[0]=0; | ||
+ | } | ||
+ | else client.write(" | ||
+ | } | ||
+ | if (s[0]!=0) | ||
+ | { | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | s[0]=0; | ||
+ | } | ||
+ | sprintf(xln," | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | else | ||
+ | if (qmode==xWEBcfg) | ||
+ | { | ||
+ | client.write(" | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | client.write("< | ||
+ | client.write(" | ||
+ | client.write(" | ||
+ | client.write("</ | ||
+ | if (qmode==xWEBhome) client.write("< | ||
+ | client.write("< | ||
+ | client.write("< | ||
+ | client.write("< | ||
+ | client.write("< | ||
+ | if (qmode==xWEBhome) { | ||
+ | | ||
+ | |||
+ | for (int x=0; | ||
+ | { | ||
+ | tPinValue * qPinValue; | ||
+ | qPinValue=& | ||
+ | sprintf(xln," | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | qPinValue-> | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | | ||
+ | /* | ||
+ | | ||
+ | for (int ain = 0; ain < NUM_ANALOG_INPUTS; | ||
+ | sprintf(xln,"< | ||
+ | client.write((byte*)xln, | ||
+ | } | ||
+ | |||
+ | */ | ||
+ | } | ||
+ | else | ||
+ | if (qmode==xWEBmpw) { | ||
+ | client.write("< | ||
+ | client.write(modMyPowerHost); | ||
+ | client.write("/ | ||
+ | client.write(MPWMicroLogVersion); | ||
+ | client.write(" | ||
+ | client.write("< | ||
+ | } | ||
+ | client.write("< | ||
+ | client.write("< | ||
+ | client.write("</ | ||
+ | } | ||
+ | break; | ||
+ | } | ||
+ | if (c == ' | ||
+ | } | ||
+ | } | ||
+ | SetLiveLed(LOW); | ||
+ | delay(1); | ||
+ | client.stop(); | ||
+ | } | ||
+ | } | ||
+ | #endif | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // -- [DISPLAY] ---------------------------------------------- | ||
+ | |||
+ | |||
+ | #if (modDisplay == 1) | ||
+ | |||
+ | #if (modDisplayType == dLCDKeyPad1602) | ||
+ | |||
+ | #define lcdPageSelect | ||
+ | #define lcdPageLeft | ||
+ | #define lcdPageRight | ||
+ | #define lcdPageNone | ||
+ | |||
+ | struct tDispVar { | ||
+ | char * xname; | ||
+ | signed long xval; | ||
+ | int xval10000; | ||
+ | char * xunit; | ||
+ | }; | ||
+ | |||
+ | char lcdLastButton=0; | ||
+ | unsigned long lcdLastButtonTime=0; | ||
+ | |||
+ | void DisplayDetectButton() | ||
+ | { | ||
+ | char qbutt=0; | ||
+ | int xb=analogRead(0); | ||
+ | if (xb<50) qbutt=' | ||
+ | if (xb<200) qbutt=' | ||
+ | if (xb<400) qbutt=' | ||
+ | if (xb<550) qbutt=' | ||
+ | if (xb<800) qbutt=' | ||
+ | if ((qbutt!=lcdLastButton) && ((millis()-lcdLastButtonTime)> | ||
+ | { | ||
+ | if ((lcdLastButton==0) && (qbutt!=0)) | ||
+ | DisplayPressButton(& | ||
+ | lcdLastButton=qbutt; | ||
+ | lcdLastButtonTime=millis(); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | void DisplayPressButton(char * xbutt) | ||
+ | { | ||
+ | char p=xbutt[0]; | ||
+ | if (p==' | ||
+ | else if (p==' | ||
+ | else if (p==' | ||
+ | else if (p==' | ||
+ | else if (p==' | ||
+ | else if (p==' | ||
+ | DrawDisplayPage(); | ||
+ | if (lcdCurrentPage> | ||
+ | } | ||
+ | |||
+ | int DisplayGetConfigVarNames(char * xnamebuf, | ||
+ | { | ||
+ | boolean hasvar=false; | ||
+ | char cvn[30]=" | ||
+ | strcpy(xnamebuf, | ||
+ | int xret=0; | ||
+ | for (int i=1; | ||
+ | { | ||
+ | char c=EEPROM.read(xa+i); | ||
+ | if (hasvar) | ||
+ | { | ||
+ | if ((c==' | ||
+ | if ((c> | ||
+ | c='#'; | ||
+ | if ( (DisplayParseVariables_IsVarChar(c)) && (c!='#' | ||
+ | { | ||
+ | int xq=strlen(cvn); | ||
+ | if (xq< | ||
+ | continue; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if (cvn[1]!=' | ||
+ | { | ||
+ | strcat(cvn," | ||
+ | if (strstr(xnamebuf, | ||
+ | { | ||
+ | int qx=(strlen(cvn)-1); | ||
+ | if (((strlen(xnamebuf)+qx)< | ||
+ | { | ||
+ | char *p=cvn+1; | ||
+ | strcat(xnamebuf, | ||
+ | xret++; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | strcpy(cvn," | ||
+ | if (c=='#' | ||
+ | { | ||
+ | hasvar=false; | ||
+ | continue; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | if (c==0) break; | ||
+ | hasvar=(c==' | ||
+ | } | ||
+ | return (xret< | ||
+ | } | ||
+ | |||
+ | struct tDispVar * DisplayFindVarByName(char * xname,byte * xvars, int xmaxvars) { | ||
+ | tDispVar * xret=NULL; | ||
+ | tDispVar * xvar=(tDispVar *)xvars; | ||
+ | for (int i=0; | ||
+ | if (strcmp(xvar-> | ||
+ | xvar++; } | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | void DisplayInitConfigVars(char * xnamebuf, | ||
+ | { | ||
+ | char * p=xnamebuf; | ||
+ | if (p[0]==' | ||
+ | { | ||
+ | p++; | ||
+ | tDispVar * xvar=(tDispVar *)xvars; | ||
+ | char * q=p; | ||
+ | int ix=strlen(p); | ||
+ | int qcvars=0; | ||
+ | for (int i=0; | ||
+ | if (p[i]==' | ||
+ | p[i]=0; | ||
+ | if (q[0]!=0) | ||
+ | { | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | qcvars++; | ||
+ | if (qcvars< | ||
+ | } | ||
+ | q=p+1+i; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DisplayParseConfig(byte * qWpage) | ||
+ | { | ||
+ | int xa,la; | ||
+ | CalcDisplayConfEpromSpace(& | ||
+ | int xs=la-xa; | ||
+ | byte chsum=0; | ||
+ | byte rchsum=EEPROM.read(xa); | ||
+ | for (int i=1; | ||
+ | if (xv==0) break; chsum+=((xv& | ||
+ | if (rchsum==chsum) { | ||
+ | byte xpage=0xFF; | ||
+ | byte xpageline=0xFF; | ||
+ | char xln[60]=""; | ||
+ | char xnamebuf[200]=" | ||
+ | int xmaxvars=DisplayGetConfigVarNames(xnamebuf, | ||
+ | tDispVar xvars[xmaxvars]; | ||
+ | if (_lcdwebdispstats!=NULL) { | ||
+ | _lcdwebdispstats-> | ||
+ | _lcdwebdispstats-> | ||
+ | } | ||
+ | DisplayInitConfigVars(xnamebuf, | ||
+ | word xflag=lcdPageNone; | ||
+ | for (int i=1; | ||
+ | int xv=EEPROM.read(xa+i); | ||
+ | if ((xv==0) || (xv==' | ||
+ | char * p=xln; | ||
+ | while ((p[0]!=0) && (p[0]==32)) p++; | ||
+ | for (int ii=0; | ||
+ | for (int ii=strlen(p)-1; | ||
+ | if (p[0]!=0) DisplayParseConfigL(p,& | ||
+ | xln[0]=0; | ||
+ | } | ||
+ | else | ||
+ | { int xls=strlen(xln); | ||
+ | if (xv==0) break; | ||
+ | } | ||
+ | if (xpage!=0xFF) lcdMaxPage=xpage; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DisplayParseConfigL(char * xln,byte * xpage,byte * xpageline, | ||
+ | { | ||
+ | if (xln[0]=='#' | ||
+ | { | ||
+ | *xflag=lcdPageNone; | ||
+ | if (xln[1]==' | ||
+ | if (xln[1]==' | ||
+ | if (xln[1]==' | ||
+ | (*xpage)++; | ||
+ | (*xpageline)=0xFF; | ||
+ | } | ||
+ | else | ||
+ | if ((*xpage)==0xFF) | ||
+ | DisplayParseConfigCmdL(xln, | ||
+ | else | ||
+ | if ((*xpage)!=0xFF) | ||
+ | { | ||
+ | if ((*xpageline)==0xFF) (*xpageline)=0; | ||
+ | if (((*qWpage)==(*xpage)) || ((*xflag)==(*qWpage))) | ||
+ | { | ||
+ | *qWpage=(*xpage); | ||
+ | *xflag=lcdPageNone; | ||
+ | if (*xpageline< | ||
+ | { | ||
+ | lcdClearLine(); | ||
+ | char * p=xln; | ||
+ | for (int i=0; | ||
+ | char px[20]; | ||
+ | if (p==xln) | ||
+ | { | ||
+ | DisplayParseVariables(px, | ||
+ | lcdPrintCenter(px); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | DisplayParseVariables(px, | ||
+ | lcdPrintLeft(px); | ||
+ | px[0]=0; | ||
+ | DisplayParseVariables(px, | ||
+ | lcdPrintRight(px); | ||
+ | } | ||
+ | lcdPrintLine(*xpageline); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | #define xVarOpNONE | ||
+ | #define xVarOpADD | ||
+ | #define xVarOpSUB | ||
+ | #define xVarOpMUL | ||
+ | #define xVarOpDIV | ||
+ | #define xVarOpEQ | ||
+ | |||
+ | void DisplayParseConfigCmdL(char * xln, byte * xvars, int xmaxvars, word * xflag) | ||
+ | { | ||
+ | byte xop=xVarOpNONE; | ||
+ | tDispVar constVar; | ||
+ | tDispVar * xr=NULL; | ||
+ | tDispVar * xvar=NULL; | ||
+ | int xconstdecs=-1; | ||
+ | boolean hasvar=false; | ||
+ | boolean hasconst=false; | ||
+ | char cvarname[20]=""; | ||
+ | for (int i=0; | ||
+ | { | ||
+ | char c=xln[i]; | ||
+ | if ((hasvar) && (!hasconst)) | ||
+ | { | ||
+ | if (c==' | ||
+ | if ( (DisplayParseVariables_IsVarChar(c)) && (c!='#' | ||
+ | { | ||
+ | int xq=strlen(cvarname); | ||
+ | if (xq< | ||
+ | continue; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | char qunit[10]=""; | ||
+ | constVar.xname=cvarname; | ||
+ | constVar.xunit=qunit; | ||
+ | constVar.xval=0; | ||
+ | constVar.xval10000=0; | ||
+ | xvar=& | ||
+ | if (cvarname[0]==' | ||
+ | { | ||
+ | char r=cvarname[1]; | ||
+ | char *p=cvarname+2; | ||
+ | int xpin=0; | ||
+ | for (int ic=0; | ||
+ | { xpin*=10; char e=p[ic]; if ((e> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | | ||
+ | if ( (xvar-> | ||
+ | DisplayFillVarByTimeVar(xvar); | ||
+ | else | ||
+ | DisplayFillVarByPinValue(xpin, | ||
+ | | ||
+ | } | ||
+ | else | ||
+ | xvar = DisplayFindVarByName(cvarname, | ||
+ | |||
+ | if ((xvar!=NULL) && (xr!=NULL) && (xop!=xVarOpNONE)) { | ||
+ | if (xop==xVarOpEQ) | ||
+ | { xr-> | ||
+ | else | ||
+ | DisplayDoVarOp(xr, | ||
+ | xop=xVarOpNONE; | ||
+ | } | ||
+ | cvarname[0]=0; | ||
+ | if (c=='#' | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | if ((!hasvar) && (hasconst)) | ||
+ | { | ||
+ | boolean isnum=((c> | ||
+ | if ((c==' | ||
+ | { | ||
+ | xconstdecs=0; | ||
+ | continue; | ||
+ | } | ||
+ | else | ||
+ | if ((isnum) && (xvar!=NULL)) | ||
+ | { | ||
+ | int cn=c-' | ||
+ | if (xconstdecs< | ||
+ | { | ||
+ | if (xconstdecs> | ||
+ | { | ||
+ | xconstdecs--; | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | if (xconstdecs< | ||
+ | { | ||
+ | xconstdecs++; | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | } | ||
+ | continue; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | |||
+ | if ((xvar!=NULL) && (xr!=NULL) && (xop!=xVarOpNONE)) { | ||
+ | if (xconstdecs> | ||
+ | if (xop==xVarOpEQ) | ||
+ | { xr-> | ||
+ | else | ||
+ | DisplayDoVarOp(xr, | ||
+ | xop=xVarOpNONE; | ||
+ | } | ||
+ | | ||
+ | xvar=NULL; | ||
+ | hasconst=false; | ||
+ | xconstdecs=-1; | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | if (c==0) break; | ||
+ | hasvar=(c==' | ||
+ | if (!hasvar) { | ||
+ | |||
+ | hasconst=((c> | ||
+ | if (hasconst) | ||
+ | { | ||
+ | constVar.xval=0; | ||
+ | constVar.xval10000=0; | ||
+ | xvar=& | ||
+ | i--; | ||
+ | continue; | ||
+ | } | ||
+ | |||
+ | if (c!=' ' | ||
+ | { | ||
+ | byte xlastop=xop; | ||
+ | if (c==' | ||
+ | if (c==' | ||
+ | if (c==' | ||
+ | if (c==' | ||
+ | if (c=='/' | ||
+ | if ((xlastop==xVarOpNONE) && (xop==xVarOpEQ) && (xvar!=NULL) && (xr==NULL)) | ||
+ | { xr=xvar; xvar=NULL; } | ||
+ | } | ||
+ | else | ||
+ | hasconst=false; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void DisplayDoVarOp(struct tDispVar * xr,struct tDispVar * xvar,byte xop) | ||
+ | { | ||
+ | int64 xq1, | ||
+ | if (xop==xVarOpMUL) { | ||
+ | i64x10k2int10kH(& | ||
+ | i64x10k2int10kH(& | ||
+ | } else { | ||
+ | i64x10k2int10k(& | ||
+ | i64x10k2int10k(& | ||
+ | } | ||
+ | if (xop==xVarOpADD) i64addS(& | ||
+ | if (xop==xVarOpSUB) i64subS(& | ||
+ | if (xop==xVarOpDIV) { word xmod; i64divW(& | ||
+ | if (xop==xVarOpMUL) { int64 xretH; i64mul64(& | ||
+ | i64int10k2x10k(& | ||
+ | } | ||
+ | |||
+ | void PrintComputedPinValue(int xpin,char * xret,int maxunitsize, | ||
+ | { | ||
+ | tDispVar xvar; | ||
+ | DisplayFillVarByPinValue(xpin,& | ||
+ | //signed long xval=xvar.xval; | ||
+ | //int xval10k=xvar.xval10000; | ||
+ | sprint10k(xret, | ||
+ | // | ||
+ | } | ||
+ | |||
+ | void DisplayFillVarByPinValue(int xpin,struct tDispVar * xvar,char xpintype) | ||
+ | { | ||
+ | if ((xpin< | ||
+ | { | ||
+ | tPinConf pconf; | ||
+ | byte qpintype=xpinOPTdefault; | ||
+ | if ((xpintype==' | ||
+ | if ((xpintype==' | ||
+ | if ((xpintype==' | ||
+ | if ((xpintype==' | ||
+ | if ((xpintype==' | ||
+ | int pinval=SamplerAnalogReadType(xpin, | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | if ((xpintype> | ||
+ | { | ||
+ | boolean isvalid = ReadPinConf(& | ||
+ | if (isvalid) | ||
+ | { | ||
+ | int qxval10000; | ||
+ | signed long qxval; | ||
+ | DisplayMapPinValue(pinval,& | ||
+ | pconf.xmin, | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DisplayMapPinValue(int pinval, | ||
+ | signed long xmin, int xmin10k, signed long xmax, int xmax10k) | ||
+ | { | ||
+ | *qxval10k=0; | ||
+ | i64x10k2int10k(& | ||
+ | boolean msf=qmin.msf; | ||
+ | msf=qdif.msf; | ||
+ | i64divW(& | ||
+ | i64int10k2x10k(qxval, | ||
+ | } | ||
+ | |||
+ | |||
+ | boolean DisplayParseVariables_IsVarChar(char c) { | ||
+ | return ( ((c> | ||
+ | (c==' | ||
+ | |||
+ | void DisplayParseVariables(char * xdst,char * xsrc, int xmaxlen, byte * xvars,int xmaxvars) | ||
+ | { | ||
+ | int ix=0; | ||
+ | boolean hasvar=false; | ||
+ | char cvarname[20]=""; | ||
+ | byte xdecs=0xFF; | ||
+ | for (int i=0; | ||
+ | { | ||
+ | char c=xsrc[i]; | ||
+ | if (hasvar) | ||
+ | { | ||
+ | if (c==' | ||
+ | if (c==' | ||
+ | if ((c> | ||
+ | c='#'; | ||
+ | if ( (DisplayParseVariables_IsVarChar(c)) && (c!='#' | ||
+ | { | ||
+ | int xq=strlen(cvarname); | ||
+ | if (xq< | ||
+ | continue; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | char qunit[10]=""; | ||
+ | tDispVar pinVar; | ||
+ | pinVar.xname=cvarname; | ||
+ | pinVar.xunit=qunit; | ||
+ | pinVar.xval=0; | ||
+ | pinVar.xval10000=0; | ||
+ | tDispVar * xvar=& | ||
+ | if (cvarname[0]==' | ||
+ | { | ||
+ | char r=cvarname[1]; | ||
+ | char *p=cvarname+2; | ||
+ | int xpin=0; | ||
+ | for (int ic=0; | ||
+ | { xpin*=10; char e=p[ic]; if ((e> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | DisplayFillVarByPinValue(xpin, | ||
+ | } | ||
+ | else | ||
+ | xvar = DisplayFindVarByName(cvarname, | ||
+ | |||
+ | if (xvar!=NULL) | ||
+ | { | ||
+ | char pxval[50]=""; | ||
+ | if ( (xvar-> | ||
+ | { | ||
+ | DisplayGetValueByTimeVar(pxval, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | char qsc[]=" | ||
+ | char *xsc=qsc; | ||
+ | signed long xval=xvar-> | ||
+ | int xval10k=xvar-> | ||
+ | |||
+ | if (xdecs==0xFE) | ||
+ | { | ||
+ | sprintf(pxval," | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | while (xval> | ||
+ | { | ||
+ | if (xsc[1]==0) break; | ||
+ | int64 xq,xr; word xmod; | ||
+ | i64x10k2int10k(& | ||
+ | i64divW(& | ||
+ | i64int10k2x10k(& | ||
+ | xsc++; | ||
+ | } | ||
+ | sprint10k(pxval, | ||
+ | // sprintf(pxval," | ||
+ | DisplayCorrectDecs(pxval, | ||
+ | if ((xsc[0]!=' | ||
+ | } | ||
+ | } | ||
+ | for (int cc=0; | ||
+ | if (ix< | ||
+ | } | ||
+ | cvarname[0]=0; | ||
+ | if (c=='#' | ||
+ | { | ||
+ | hasvar=false; | ||
+ | continue; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | if (c==0) break; | ||
+ | hasvar=(c==' | ||
+ | if ((!hasvar) && (ix< | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void DisplayFillVarByTimeVar(struct tDispVar * xvar) | ||
+ | { | ||
+ | char px[30]=""; | ||
+ | DisplayGetValueByTimeVar(px, | ||
+ | xvar-> | ||
+ | xvar-> | ||
+ | } | ||
+ | |||
+ | |||
+ | void DisplayGetValueByTimeVar(char * xbuf,char * xvarname, | ||
+ | { | ||
+ | xbuf[0]=0; | ||
+ | if ((xvarname[0]==' | ||
+ | { | ||
+ | if (strlen(xvarname)> | ||
+ | { | ||
+ | char xfmt[5]=""; | ||
+ | tMpwDateTime xMpwDateTime; | ||
+ | FormatDateTimeStr(xbuf, | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DisplayCorrectDecs(char * pxval, byte xdecs) | ||
+ | { | ||
+ | int xl=strlen(pxval); | ||
+ | if (xl>0) { | ||
+ | if (xdecs==0xFF) { for (;;) { xl=strlen(pxval); | ||
+ | else { if (xdecs> | ||
+ | for (byte xx=0; | ||
+ | xl=strlen(pxval); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DrawDisplayPage() | ||
+ | { | ||
+ | if (lcdCurrentPage==0xFF) | ||
+ | { | ||
+ | lcdClear(); | ||
+ | lcdCurrentPage=0; | ||
+ | } | ||
+ | DisplayParseConfig(& | ||
+ | } | ||
+ | |||
+ | #endif | ||
+ | |||
+ | #endif | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // -- [SAMPLER] ---------------------------------------------- | ||
+ | |||
+ | int SamplerAnalogRead(byte xpin) | ||
+ | { | ||
+ | return SamplerAnalogReadType(xpin, | ||
+ | } | ||
+ | |||
+ | |||
+ | void SamplerReset() { | ||
+ | for (int i=0; | ||
+ | xSamplerStruct.tPinValues[i].smpTime=0; | ||
+ | } | ||
+ | |||
+ | int SamplerAnalogReadType(byte xpin,byte forcextype) | ||
+ | { | ||
+ | int xret=0; | ||
+ | if (xpin< | ||
+ | { | ||
+ | tPinValue * xpinvalue; | ||
+ | xpinvalue=& | ||
+ | byte xtype=SamplerGetPinType(xpin); | ||
+ | if (forcextype!=xpinOPTdefault) xtype=forcextype; | ||
+ | if (xtype==xpinOPTavg) xret=xpinvalue-> | ||
+ | if (xtype==xpinOPTeffective) xret=xpinvalue-> | ||
+ | if (xtype==xpinOPTmin) xret=xpinvalue-> | ||
+ | if (xtype==xpinOPTmax) xret=xpinvalue-> | ||
+ | xret=xpinvalue-> | ||
+ | } | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | void SamplerRun() | ||
+ | { | ||
+ | byte qpins[4]; | ||
+ | SamplerGetNext4PinGroup(qpins); | ||
+ | SamplerExec(qpins,& | ||
+ | } | ||
+ | |||
+ | byte SamplerGroupindex=0; | ||
+ | unsigned long Stime=0; | ||
+ | |||
+ | void SamplerGetNext4PinGroup(byte * qpins) | ||
+ | { | ||
+ | SamplerGroupindex++; | ||
+ | SamplerGet4PinGroup(qpins,& | ||
+ | } | ||
+ | |||
+ | byte SamplerGetPinType(byte xpin) | ||
+ | { | ||
+ | byte xret=xpinOPTsample; | ||
+ | if (ReadPinConf(& | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | byte SamplerGetPinGroup(byte xpin) | ||
+ | { | ||
+ | byte xret=0; | ||
+ | byte qret=0; | ||
+ | tPinConf pconf; | ||
+ | if (ReadPinConf(& | ||
+ | qret=pconf.xopt& | ||
+ | if (qret==xpinOPTsampleG0) xret=0; else | ||
+ | if (qret==xpinOPTsampleG1) xret=1; else | ||
+ | if (qret==xpinOPTsampleG2) xret=2; else | ||
+ | if (qret==xpinOPTsampleG3) xret=3; | ||
+ | } | ||
+ | return xret; | ||
+ | } | ||
+ | |||
+ | void SamplerGet4PinGroup(byte * qpins,byte * qgroupindex) | ||
+ | { | ||
+ | char pgroups[4][NUM_ANALOG_INPUTS+1]; | ||
+ | for (int x=0; | ||
+ | char qch[2]=""; | ||
+ | for (int x=0; | ||
+ | char pgroups4[NUM_ANALOG_INPUTS][5]; | ||
+ | for (int x=0; | ||
+ | int p4index=0; | ||
+ | for (int x=0; | ||
+ | while (strlen(pgroups[x])> | ||
+ | strncpy(pgroups4[p4index], | ||
+ | pgroups4[p4index][4]=0; | ||
+ | if (strlen(pgroups[x])> | ||
+ | char * p=(pgroups[x])+4; | ||
+ | strcpy(pgroups[x], | ||
+ | } | ||
+ | else | ||
+ | strcpy(pgroups[x],"" | ||
+ | p4index++; | ||
+ | } | ||
+ | } | ||
+ | for (int p4s=0; | ||
+ | int xl=strlen(pgroups4[p4s]); | ||
+ | if (xl==4) continue; | ||
+ | else { | ||
+ | int xr=4-xl; | ||
+ | boolean xfound=false; | ||
+ | while (!xfound) { | ||
+ | for (int x=p4s+1; | ||
+ | if (strlen(pgroups4[x])==xr) { | ||
+ | strcat(pgroups4[p4s], | ||
+ | strcpy(pgroups4[x],"" | ||
+ | xfound=true; | ||
+ | break; | ||
+ | } | ||
+ | if (xfound) break; else if (!xfound) { if (xr>0) xr--; else break; } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | byte p4count=0; | ||
+ | for (int x=0; | ||
+ | for (int x=0; | ||
+ | byte idx=0; | ||
+ | if (p4count> | ||
+ | idx=*qgroupindex%p4count; | ||
+ | *qgroupindex=idx; | ||
+ | char *p=pgroups4[idx]; | ||
+ | int xl=strlen(p); | ||
+ | if (xl>4) xl=4; | ||
+ | if (xl!=0) | ||
+ | for (int x=0; | ||
+ | qpins[x]=(p[x])-' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void SamplerResetPinStruct(int xpin,struct tSampledPin * xSampledPin) | ||
+ | { | ||
+ | xSampledPin-> | ||
+ | for (int x=0; | ||
+ | for (int x=0; | ||
+ | xSampledPin-> | ||
+ | xSampledPin-> | ||
+ | xSampledPin-> | ||
+ | xSampledPin-> | ||
+ | xSampledPin-> | ||
+ | } | ||
+ | |||
+ | |||
+ | void SamplerExec(byte * pins, struct tSamplerStruct * qSamplerStruct, | ||
+ | { | ||
+ | byte * xtimes=qSamplerStruct-> | ||
+ | tSampledPin * xPinSamples=qSamplerStruct-> | ||
+ | unsigned long wqms,wqme; | ||
+ | for (int x=0; | ||
+ | for (int x=0; | ||
+ | int qscount=sizeof(xPinSamples[0].smpHi8); | ||
+ | int smpCount=0; | ||
+ | unsigned long xxs, | ||
+ | unsigned long qms,qm1; | ||
+ | int qsample=0; | ||
+ | int inputpin=0; | ||
+ | tSampledPin * qSampledPin; | ||
+ | int xs3=0; | ||
+ | int xs2=0; | ||
+ | xxs=micros(); | ||
+ | xms=0; | ||
+ | qms=0; | ||
+ | while (true) { xm1=micros()-xxs; | ||
+ | xms=xm1; | ||
+ | |||
+ | wqms=micros(); | ||
+ | for (int x=0; | ||
+ | { | ||
+ | xs2=x>> | ||
+ | xs3=(x& | ||
+ | for (int p=0; | ||
+ | { | ||
+ | qSampledPin=& | ||
+ | if (qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | } | ||
+ | smpCount++; | ||
+ | qms=xms>> | ||
+ | while (true) { xm1=micros()-xxs; | ||
+ | xtimes[x]=(byte)( (xm1-xms) - 400 ); | ||
+ | xms=xm1; | ||
+ | } | ||
+ | |||
+ | wqme=micros()-wqms; | ||
+ | qSamplerStruct-> | ||
+ | |||
+ | for (int x=0; | ||
+ | { | ||
+ | xs2=x>> | ||
+ | xs3=(x& | ||
+ | for (int p=0; | ||
+ | { | ||
+ | qSampledPin=& | ||
+ | qsample=(((int)qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | if (qSampledPin-> | ||
+ | if (qSampledPin-> | ||
+ | unsigned long qs=qsample; | ||
+ | qSampledPin-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | byte qpoint=64; | ||
+ | for (int p=0; | ||
+ | { | ||
+ | qSampledPin=& | ||
+ | byte qxpin=qSampledPin-> | ||
+ | if (qxpin< | ||
+ | { | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | qSampledPin-> | ||
+ | tPinValue * xpinvalue=& | ||
+ | xs3=(qpoint& | ||
+ | xpinvalue-> | ||
+ | xpinvalue-> | ||
+ | xpinvalue-> | ||
+ | xpinvalue-> | ||
+ | xpinvalue-> | ||
+ | xpinvalue-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // -- [MATH10k] ------------------------------------------------- | ||
+ | |||
+ | boolean isnegative10k(signed long xval, int x10k) { | ||
+ | boolean xret=(xval< | ||
+ | } | ||
+ | |||
+ | void sprint10k(char * xret, signed long xval, int x10k) { | ||
+ | char xsgn[5]=""; | ||
+ | if (xval<0) xval=-xval; if (x10k<0) x10k=-x10k; | ||
+ | sprintf(xret," | ||
+ | } | ||
+ | |||
+ | // -- [MATH64] ------------------------------------------------- | ||
+ | |||
+ | void i64print(struct int64 * xval,char * xstr) { | ||
+ | char x[200]=""; | ||
+ | (long)xval-> | ||
+ | |||
+ | void i64cpy(struct int64 * xdst,struct int64 * xsrc) { xdst-> | ||
+ | xdst-> | ||
+ | void i64nul(struct int64 * q1) { q1-> | ||
+ | void i64shl16(struct int64 * xret) { xret-> | ||
+ | int i64cmpS(struct int64 * q1, struct int64 * q2) { for (byte i=0; | ||
+ | word x1=((i==0)? | ||
+ | word x2=((i==0)? | ||
+ | signed long s1=(signed long)x1; signed long s2=(signed long)x2; | ||
+ | if (q1-> | ||
+ | return 0; } | ||
+ | |||
+ | void i64addS(struct int64 * xret, struct int64 * q1, struct int64 * q2) { | ||
+ | i64nul(xret); | ||
+ | xx=(signed long)q1-> | ||
+ | xx=(signed long)q1-> | ||
+ | xx=(signed long)q1-> | ||
+ | xx=(signed long)q1-> | ||
+ | xret-> | ||
+ | else if ((q1-> | ||
+ | else if ((!q1-> | ||
+ | } | ||
+ | |||
+ | void i64subS(struct int64 * xret, struct int64 * q1, struct int64 * q2) { | ||
+ | i64nul(xret); | ||
+ | if ((q1-> | ||
+ | if ((q1-> | ||
+ | if ((!q1-> | ||
+ | if (xcmp==0) return; else if (xcmp==-1) { i64subS(xret, | ||
+ | else { signed long xx, | ||
+ | xh=(xx> | ||
+ | xh=(xx> | ||
+ | xh=(xx> | ||
+ | xret-> | ||
+ | } | ||
+ | |||
+ | boolean i64divW(struct int64 * xret, word * xmod, struct int64 * q1, word q2) { | ||
+ | i64nul(xret); | ||
+ | else { unsigned long ql; | ||
+ | ql=(((unsigned long)(*xmod))<< | ||
+ | ql=(((unsigned long)(*xmod))<< | ||
+ | ql=(((unsigned long)(*xmod))<< | ||
+ | return true; } | ||
+ | } | ||
+ | |||
+ | unsigned long i64lo(struct int64 * xint) { return (((unsigned long)xint-> | ||
+ | unsigned long i64hi(struct int64 * xint) { return (((unsigned long)xint-> | ||
+ | |||
+ | void i64mul64(struct int64 * xretH, struct int64 * xretL, struct int64 * q1, struct int64 * q2) | ||
+ | { i64nul(xretH); | ||
+ | q1l=i64lo(q1); | ||
+ | i64mul(& | ||
+ | xretL-> | ||
+ | xr2.hh=0; | ||
+ | xr1x.lh=xr1.hh; | ||
+ | i64addS(& | ||
+ | int64 xr23o; | ||
+ | xr3.lh=(word)(xr3h>> | ||
+ | i64addS(& | ||
+ | } | ||
+ | |||
+ | void i64mul(struct int64 * xret, unsigned long q1, unsigned long q2) { | ||
+ | unsigned long x1, | ||
+ | word all=(word)q1; | ||
+ | x1=(unsigned long)all*(unsigned long)bll; | ||
+ | x1=(unsigned long)alh*(unsigned long)bll; | ||
+ | x2=(unsigned long)all*(unsigned long)blh; | ||
+ | xret-> | ||
+ | x1+=qp; | ||
+ | } | ||
+ | |||
+ | void i64int10k2x10k(signed long * xval, int * x10k, struct int64 * xint64) { | ||
+ | boolean msf=xint64-> | ||
+ | word xmod=0; | ||
+ | signed long qval=(((unsigned long)qret.lh)<< | ||
+ | *xval=msf? | ||
+ | xint64-> | ||
+ | } | ||
+ | |||
+ | void i64x10k2int10k(struct int64 * xret, signed long xval, int x10k) { | ||
+ | int64 q1;int64 q2; | ||
+ | /* boolean msf=((xval)< | ||
+ | if (msf) xval=-(xval); | ||
+ | q2.ll=(x10k)& | ||
+ | i64addS(xret, | ||
+ | } | ||
+ | |||
+ | void i64x10k2int10kH(struct int64 * xret, signed long xval, int x10k) { | ||
+ | int64 q1;int64 q2; | ||
+ | /* boolean msf=((xval)< | ||
+ | if (msf) xval=-(xval); | ||
+ | q2.ll=(x10k/ | ||
+ | i64addS(xret, | ||
+ | } | ||
+ | |||
+ | |||
+ | // ---[ Digital Pin Output ]---------------------------------------- | ||
+ | |||
+ | int DPIN_epGetConfNameAddr(byte xpinindex) { | ||
+ | return (xpinindex< | ||
+ | } | ||
+ | |||
+ | void DPIN_epWriteConfName(byte xpinindex, | ||
+ | int xaddr=DPIN_epGetConfNameAddr(xpinindex); | ||
+ | if (xaddr> | ||
+ | { | ||
+ | byte chsum=(xaddr& | ||
+ | for (int i=1; | ||
+ | byte ch=xnamebuf[i-1]; | ||
+ | chsum+=ch+i+(ch& | ||
+ | if (EEPROM.read(xaddr+i)!=ch) EEPROM.write(xaddr+i, | ||
+ | if (ch==0) break; | ||
+ | } | ||
+ | if (EEPROM.read(xaddr)!=chsum) EEPROM.write(xaddr, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DPIN_epReadConfName(byte xpinindex, | ||
+ | char xbuf[20]=""; | ||
+ | int xaddr=DPIN_epGetConfNameAddr(xpinindex); | ||
+ | byte chsum=(xaddr& | ||
+ | if (xaddr> | ||
+ | { | ||
+ | for (int i=1; | ||
+ | byte ch=EEPROM.read(xaddr+i); | ||
+ | chsum+=ch+i+(ch& | ||
+ | if (ch==0) break; | ||
+ | xbuf[i-1]=ch; | ||
+ | xbuf[i]=0; | ||
+ | } | ||
+ | if (EEPROM.read(xaddr)==chsum) | ||
+ | { | ||
+ | strncpy(xnamebuf, | ||
+ | xnamebuf[xbufsize-1]=0; | ||
+ | } | ||
+ | else | ||
+ | xnamebuf[0]=0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DPINUpdateHW() { | ||
+ | uint16_t dstat=DPINstatus^DPINlogicmask; | ||
+ | for (int i=0; | ||
+ | if ((xdpin> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void DPINResetHW() { | ||
+ | for (int i=0; | ||
+ | if ((xdpin> | ||
+ | } | ||
+ | DPINUpdateHW(); | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | </ |
source.txt · Poslední úprava: 2016/04/22 21:34 autor: 127.0.0.1