diff --git a/ccu4_73.ino b/ccu4_74.ino similarity index 97% rename from ccu4_73.ino rename to ccu4_74.ino index 6a0974e..88b788f 100644 --- a/ccu4_73.ino +++ b/ccu4_74.ino @@ -11,7 +11,7 @@ // define SERIALCOMMON 1 for testing the serial connection over usb #define SERIALCOMMON 0 -PAR_TEXT configSoft[16] = "7.3"; +PAR_TEXT configSoft[16] = "7.4"; long now; // global variable, updated by FastHandler byte inside; @@ -28,7 +28,8 @@ enum { p_heLevel, p_heRaw, p_heAvailable, p_heDrive, p_heCurrent, p_heVolt, p_heHigh, p_heLow, p_heWiRes, p_heEmpty, p_heFull, p_heFastTime, p_heSlowTime, p_heSlope, p_heFirst, p_heValve, p_heSensState, p_heAuto, p_heMeas, p_heFast, p_heCommand, /* p_heBooster, */ - p_heIncreaseTolerance, p_heFastTimeout, + p_heIncreaseTolerance, p_heFastTimeout, p_heExtAvailable, p_heChannel, p_heExtDrive, + p_heExtWiRes, p_heExtEmpty, p_heExtFull, p_n2Available, p_n2upper, p_n2lower, p_n2threshold, p_n2tubecooldelay, p_n2filltimeout, p_n2fault, p_n2auto, p_n2valve, p_n2command, p_boostdelay, p_codeA, p_codeB, p_codeAbad, p_codeBbad, p_freeRam, @@ -37,12 +38,12 @@ enum { p_configSave, p_configVersion, p_configItem, p_instr, p_instrConnected, p_instrList, p_auxAvailable, p_aux, p_auxScale, p_auxDigits, p_auxLabel, - p_heFeedback, p_n2Feedback, p_vuAvailable, p_heExtAvailable, p_heExtChannel, - p_nBase + p_heFeedback, p_n2Feedback, p_vuAvailable, + p_heExtLevel, p_heExtState = p_heExtLevel + 6, + p_nBase = p_heExtState + 6 }; enum {p_vu = p_nBase - 1, p_vuCmd = p_vu + 12}; // valve unit base (+ 24 parameters) -enum {p_heExtWiRes = p_nBase, p_heExtEmpty, p_heExtFull, p_heExtLevel, p_heExtState = p_heExtLevel + 6}; // he ext base (+ 15 parameters) enum {p_nPar = p_nBase + 24}; // max. parameter of all extensions diff --git a/dipdisplay.ino b/dipdisplay.ino index 79e92f8..58040aa 100644 --- a/dipdisplay.ino +++ b/dipdisplay.ino @@ -204,6 +204,10 @@ void DispBigValue(byte nr, byte stateNr) { DispValueArg(fmt_big, 0, nr, stateNr); } +void DispMediumValue(char *head, byte nr, byte stateNr) { + DispValueArg(fmt_medium, head, nr, stateNr); +} + void DispLargeValue(char *head, byte nr, byte stateNr) { DispValueArg(fmt_large, head, nr, stateNr); } @@ -219,7 +223,7 @@ void DispSend(const char *data) { SerialD.write((byte)0); } -boolean DispInit(void (*handler)(), byte homescreen) { +byte DispInit(void (*handler)(), byte homescreen) { long start; disp.commdebug = false; @@ -311,6 +315,7 @@ void DispDrawRow(struct Disp_Row *row, boolean doclear) { boolean skip = false; int len, maxlen; byte ytop, ybot; + char *afterHead = 0; disp.handler(); ytop = disp.textPos; @@ -337,25 +342,34 @@ void DispDrawRow(struct Disp_Row *row, boolean doclear) { case fmt_none: goto drawline; case fmt_lsmall: - DispPutStr("#ZF4,"); align='L'; xpos = 0; break; + DispPutStr("#ZF4,"); align='L'; xpos = 0; + break; case fmt_rsmall: //sameline = true; - DispPutStr("#ZF4,"); align='R'; xpos = 63; break; + DispPutStr("#ZF4,"); align='R'; xpos = 63; + break; case fmt_medium: - if (len >= 32) { + if (head && *head) { + afterHead = "#ZF4,#ZZ1,2,"; + DispPutStr("#ZF4,"); zoom = 1; + } else if (len >= 32) { DispPutStr("#ZF4,#ZZ1,2,"); zoom = 1; } else { DispPutStr("#ZF4,#ZZ2,2,"); zoom = 2; } - align='R'; xpos = 63; break; + align='R'; xpos = 63; + break; case fmt_large: DispPutStr("#ZF4,"); - align='R'; xpos = 63; break; + align='R'; xpos = 63; + break; case fmt_big: + afterHead = "#ZF6,"; if (len >= 24) { DispPutStr("#ZF4,#ZZ1,2,"); zoom = 1; } else { - DispPutStr("#ZF6,"); head = 0; + DispPutStr(afterHead); head = 0; + afterHead = 0; } align='R'; xpos = 63; break; @@ -371,7 +385,7 @@ void DispDrawRow(struct Disp_Row *row, boolean doclear) { DispPut('L'); DispPut(0); DispPut(ytop); DispSend(head); maxlen -= DispTextWidth(head) + 1; - if (fmt == fmt_large && len < 24) DispPutStr("#ZF6,"); // use Big for number + if (afterHead) DispPutStr(afterHead); // change format for value DispPutStr("\033Z"); DispPut(align); DispPut(xpos); DispPut(ytop); } else { DispPut(align); DispPut(xpos); DispPut(ytop); diff --git a/he.ino b/he.ino index 5958c89..363ef24 100644 --- a/he.ino +++ b/he.ino @@ -7,7 +7,7 @@ PAR_LONG heLevel = 0; // channel 6 (internal) PAR_LONG heRaw = 0; PAR_LONG heHigh = 9500; // stop filling PAR_LONG heLow = 1000; // start filling -PAR_LONG heDrive = 10; +PAR_LONG heDrive = 75; PAR_LONG heWiRes = 500; PAR_LONG heCurrent = 0; PAR_LONG heVolt = 0; @@ -27,11 +27,12 @@ PAR_BYTE heFast = 1; // 0: slow, 1: fast PAR_BYTE heAuto = 1; // 0: off, 1: auto fill PAR_BYTE heMeas = 0; // 0: idle, 1: measuring, 2:checking PAR_LONG heExtLevel[6] = {0}; -PAR_BYTE heExtState[6] = {he_disabled, he_disabled, he_disabled, he_disabled, he_disabled, he_disabled}; // disabled +PAR_BYTE heExtState[6] = {he_not_yet, he_disabled, he_disabled, he_disabled, he_disabled, he_disabled}; // disabled PAR_LONG heExtWiRes = 460; PAR_LONG heExtEmpty = 565; PAR_LONG heExtFull = 90; -PAR_LONG heExtChannel = 7; +PAR_LONG heExtDrive = 75; +PAR_LONG heChannel = 7; long heMinLev[7] = {0,0,0,0,0,0,0}; long heMinLevel; long heIntLevel = 0; @@ -48,9 +49,10 @@ const long heMeasTol = 20; // mm ulong heLastIncrease = -240000; boolean checking = false; boolean started = false; -float volt_to_mm = 300; +float res_to_len = 300; long empty_10um = 20000; float mm_to_percent = 0.5; +long heIntDrive = 0; void HePars() { byte changed; @@ -90,21 +92,29 @@ void HePars() { if (ParEnum("hcd", heCommand, he_cmd_text) == par_command) { HeRemoteCmd(heCommand); } - ParEnum("hea", heExtAvailable, F("0")); // use enum 0 for pure byte + changed = (ParEnum("hea", heExtAvailable, F("0")) == par_command); // use enum 0 for pure byte if (heExtAvailable > 6) { ParSet(heExtAvailable, 1); } + changed |= (ParFixed("hd0", heExtDrive, 0) == par_command); changed |= (ParFixed("hwr0", heExtWiRes, 0) == par_command); changed |= (ParFixed("hem0", heExtEmpty, 0) == par_command); changed |= (ParFixed("hfu0", heExtFull, 0) == par_command); if (changed) { - for (byte n = 0; n < 6; n++) { - if (heExtState[n] != he_disabled) { - ParArraySet(heExtState, n, he_not_yet); + if (heExtAvailable == 1) { + if (HEDEBUG) { + Serial.println("activate channel 0"); + } + ParArraySet(heExtState, 0, he_not_yet); + } else { + for (byte n = 0; n < 6; n++) { + if (heExtState[n] != he_disabled) { + ParArraySet(heExtState, n, he_not_yet); + } } } } - ParFixed("hch", heExtChannel, 0); + ParFixed("hch", heChannel, 0); //ParFixedArray("h", heExtLevel, 0, heExtAvailable - 1, 2); //ParEnumArray("hs", heExtState, 0, heExtAvailable - 1, he_sens_text); ParFixedArray("h", heExtLevel, 0, 5, 2); @@ -181,10 +191,10 @@ long HeGetLevel(byte channel) { } void HeLoadChannel() { - heIntState = HeGetState(heExtChannel); - heIntLevel = HeGetLevel(heExtChannel); - if (heExtChannel >= 0 && heExtChannel <= 6) { - heMinLevel = heMinLev[heExtChannel]; + heIntState = HeGetState(heChannel); + heIntLevel = HeGetLevel(heChannel); + if (heChannel >= 0 && heChannel <= 6) { + heMinLevel = heMinLev[heChannel]; } } @@ -303,15 +313,21 @@ boolean HeDispShort(boolean *big) { boolean isbig = true; HeStateDisp("He "); - if (heAvailable == 1) { - DispBigValue(p_heLevel, p_heSensState); // He level + if (heAvailable == 1 && heExtState[0] == he_sens_ok) { + isbig = true; } else { isbig = false; } + if (heAvailable == 1) { + if (isbig) { + DispMediumValue("", p_heLevel, p_heSensState); // He level + } else { + DispBigValue(p_heLevel, p_heSensState); // He level + } + } if (heExtState[0] == he_sens_ok) { - DispValue("vessel", HeValueNr(0), HeStateNr(0)); - } else { - isbig = false; + // DispValue("vessel", HeValueNr(0), HeStateNr(0)); + DispMediumValue("vessel", HeValueNr(0), HeStateNr(0)); } *big = isbig; return heValve == valve_on; @@ -388,22 +404,25 @@ void HeDisp() { } void HeEndMeas() { - if (HEDEBUG) {Serial.print(heExtChannel); if (heMeas == 2) Serial.println(" HeEndChk"); else Serial.println(" HeEndMeas"); } + if (HEDEBUG) {Serial.print(heChannel); if (heMeas == 2) Serial.println(" HeEndChk"); else Serial.println(" HeEndMeas"); } // switch off current digitalWrite(io_lev_enable, LOW); pinMode(io_lev_enable, OUTPUT); analogWrite(io_lev_current, 0); digitalWrite(io_lev_boost, HIGH); // 48 V booster inactive - if (heIntState != he_disabled) { + if (HeGetState(heChannel) != he_disabled) { + if (HEDEBUG) { + Serial.print(heChannel); Serial.print(" state "); Serial.println(heIntState); + } // saving result - HeSetState(heExtChannel, heIntState); - if (heExtChannel >= 0 && heExtChannel <= 6) { - heMinLev[heExtChannel] = heMinLevel; + HeSetState(heChannel, heIntState); + if (heChannel >= 0 && heChannel <= 6) { + heMinLev[heChannel] = heMinLevel; } if (heIntState == he_sens_ok) { - if (heMeas == 1) HeSetLev(heExtChannel, heIntLevel); + if (heMeas == 1) HeSetLev(heChannel, heIntLevel); } else if (heIntState == he_no_sens) { - HeSetLev(heExtChannel, 0); + HeSetLev(heChannel, 0); } } ParSet(heMeas, 0); // off @@ -422,20 +441,22 @@ void HeEndMeas() { void HeSelect() { byte pin; - if (heExtChannel == 6) { - volt_to_mm = 1e7 / (heWiRes * heCurrent); // result is in 1e-5 m (+5), input in 1e-2 V (-2), heWiRes in Ohm/m, heCurrent in 1e-4 A (+4) + if (heChannel == 6) { + heIntDrive = heDrive; + res_to_len = 1e7 / heWiRes; // result is in 1e-5 m (+5), input in 1e-2 V (-2), heWiRes in Ohm/m, heCurrent in 1e-4 A (+4) mm_to_percent = 100.0 / (heEmpty - heFull); empty_10um = 100 * heEmpty; digitalWrite(io_he_select, LOW); } else { - volt_to_mm = 1e7 / (heExtWiRes * heCurrent); + heIntDrive = heExtDrive; + res_to_len = 1e7 / heExtWiRes; mm_to_percent = 100.0 / (heExtEmpty - heExtFull); empty_10um = 100 * heExtEmpty; digitalWrite(io_he_select, HIGH); } if (heExtAvailable > 1) { for (pin = 0; pin < 6; pin++) { - digitalWrite(io_ext1 + pin, pin != heExtChannel); + digitalWrite(io_ext1 + pin, pin != heChannel); } } } @@ -477,8 +498,8 @@ void HeHandler() { started = true; return; } - ParSet(heExtChannel, heExtChannel + 1); - if (heExtChannel > 6) { // this was the last channel + ParSet(heChannel, heChannel + 1); + if (heChannel > 6) { // this was the last channel checking = false; return; } @@ -486,9 +507,9 @@ void HeHandler() { if (heIntState == he_disabled) return; ParSet(heMeas, 2); // check started = true; - } else if (heExtChannel <= 6) { // we are finished with measuring a channel - ParSet(heExtChannel, heExtChannel + 1); - if (heExtChannel > 6) { // this was the last channel + } else if (heChannel <= 6) { // we are finished with measuring a channel + ParSet(heChannel, heChannel + 1); + if (heChannel > 6) { // this was the last channel return; } HeLoadChannel(); @@ -502,14 +523,14 @@ void HeHandler() { expTime = heSlowTime; } if (expired(&last, 1000 * expTime)) { - ParSet(heExtChannel, 0); + ParSet(heChannel, 0); HeLoadChannel(); if (heIntState == he_disabled) return; ParSet(heMeas, 1); started = true; } else if (expired(&lastChk, 1000 * 2)) { // check period checking = true; - ParSet(heExtChannel, 0); + ParSet(heChannel, 0); HeLoadChannel(); if (heIntState == he_disabled) return; ParSet(heMeas, 2); // check @@ -523,7 +544,7 @@ void HeHandler() { if (started) { HeSelect(); started = false; - if (HEDEBUG) { Serial.print(heExtChannel); Serial.print (" start chk, "); }; + if (HEDEBUG) { Serial.print(heChannel); Serial.print (" start chk, "); }; sumc = 0; cnt = 0; start = now; @@ -544,6 +565,7 @@ void HeHandler() { if (cur > 3) { // there is a current if (HEDEBUG) Serial.print("sens yes "); if (heIntState == he_no_sens) { + if (HEDEBUG) Serial.print("was no "); heIntState = he_not_yet; } HeEndMeas(); @@ -557,7 +579,7 @@ void HeHandler() { if (started) { HeSelect(); started = false; - if (HEDEBUG) { Serial.print(heExtChannel); Serial.print (" start he, "); }; + if (HEDEBUG) { Serial.print(heChannel); Serial.print (" start he, "); }; sumc = 0; sump = 0; summ = 0; @@ -567,10 +589,10 @@ void HeHandler() { hiLev = 0; slope = 0; if (heIntState == he_sens_warm) { - heDriveCurrent = heDrive / 3; + heDriveCurrent = heIntDrive / 3; heWarmCheck = true; } else { - heDriveCurrent = heDrive; + heDriveCurrent = heIntDrive; heWarmCheck = false; } analogWrite(io_lev_current, heDriveCurrent); @@ -582,7 +604,7 @@ void HeHandler() { } } tim = now; - if (heExtChannel < 6) { + if (heChannel < 6) { for (i = 0 ; i < 20; i++) { sump += aRead(a_levb_vplus); summ += aRead(a_levb_vminus); @@ -614,10 +636,10 @@ void HeHandler() { return; } } - if (heExtChannel < 6) { + if (heChannel < 6) { if (HEDEBUG && 0) { Serial.print("he "); - Serial.println(heExtChannel); + Serial.println(heChannel); Serial.println(sump); Serial.println(summ); } @@ -646,7 +668,7 @@ void HeHandler() { sump = 0; summ = 0; cnt = 0; - lev = heVolt * volt_to_mm; + lev = heVolt * (res_to_len / heCurrent); if (HEDEBUG) { //Serial.print("("); Serial.print(heVolt); Serial.print(" "); Serial.print(heWiRes); Serial.print(" "); Serial.print(heCurrent); Serial.print(")"); //Serial.print(lev, DEC); Serial.print(" "); @@ -669,7 +691,7 @@ void HeHandler() { pos = (pos + 1) % 4; lastLevels[pos] = lev; if (HEDEBUG && 0) {Serial.print(lev); Serial.print("\n"); } - if (lev > heEmpty * 103) { // value more than 3% more than empty length: + if (lev > empty_10um + empty_10um / 33) { // value more than 3% more than empty length: heIntState = he_sens_warm; if (HEDEBUG) Serial.print("warm"); HeEndMeas(); @@ -687,6 +709,7 @@ void HeHandler() { HeEndMeas(); return; } + if (HEDEBUG) { Serial.print(" stab"); Serial.print(stab, DEC); } if (stab < 8) return; // not yet finished heIntState = he_sens_ok; @@ -872,6 +895,7 @@ boolean HeStateDisp(char *title) { } void HeStore(EeMode mode) { + // store parameters for external device byte channel, usedMask; if (mode == ee_write) { usedMask = 0; @@ -879,10 +903,10 @@ void HeStore(EeMode mode) { if (HeGetState(channel) != he_disabled) bitSet(usedMask, channel); } } - eeStore((void *)&heWiRes, sizeof heWiRes, mode); - eeStore((void *)&heDrive, sizeof heDrive, mode); - eeStore((void *)&heEmpty, sizeof heEmpty, mode); - eeStore((void *)&heFull, sizeof heFull, mode); + eeStore((void *)&heExtWiRes, sizeof heExtWiRes, mode); + eeStore((void *)&heExtDrive, sizeof heExtDrive, mode); + eeStore((void *)&heExtEmpty, sizeof heExtEmpty, mode); + eeStore((void *)&heExtFull, sizeof heExtFull, mode); eeStore((void *)&usedMask, sizeof usedMask, mode); if (mode == ee_read) { Serial.print("enabled he channels:"); @@ -894,10 +918,10 @@ void HeStore(EeMode mode) { HeSetState(channel, he_disabled); } } - Serial.print("\nwire res. "); Serial.print(heWiRes); - Serial.print(" Ohm/m\ndrive current "); Serial.print(heDrive); - Serial.print(" mA\nempty at "); Serial.print(heEmpty); - Serial.print(" mm from top\nfull at "); Serial.print(heFull); + Serial.print("\nwire res."); Serial.print(heExtWiRes); + Serial.print(" Ohm/m\ndrive current "); Serial.print(heExtDrive); + Serial.print(" mA\nempty at "); Serial.print(heExtEmpty); + Serial.print(" mm from top\nfull at "); Serial.print(heExtFull); Serial.print(" mm from top\n"); dispEco = 35; // default for vessels diff --git a/motor.ino b/motor.ino index 5dc34f6..8e28b0b 100644 --- a/motor.ino +++ b/motor.ino @@ -81,7 +81,8 @@ boolean FlowDispShort(boolean big) { DispText("flow/mbar"); DispBigValue(p_flow, p_flowSensState); // flow value } else { - DispValue("flow", p_flow, p_flowSensState); + DispMediumValue("flow", p_flow, p_flowSensState); // flow value + //DispValue("flow", p_flow, p_flowSensState); } FlowStateDisp(); return motorState == motor_opening || motorState == motor_closing;