|
LevelMeter-Display
2.0
An ultrasonic Level Meter for Stormwater Cisterns
|
The Main Program and miscellaneous Routines. More...

Functions | |
| void | delay10ms (delay_t delay10ms) |
| Delay for a multiple of 10ms. More... | |
| static void | DoCflags (void) |
| Checks for Communication Flags. More... | |
| static void | DoKFlags (void) |
| Checks for Key Flags. More... | |
| static void | DoTflags (void) |
| Checks for Time Flags. More... | |
| int8_t | HBarGraphPerCent (uint8_t line) |
| Draws a horizontal Bar Graph showing the Cistern Filling in %. More... | |
| void | HBarTest (void) |
| static void | Init (void) |
| Initializes the System. More... | |
| static int16_t | IntLimit (LITERS_T i) |
| limits an integer from -9999 to +9999 for display purposes More... | |
| ISR (TIMER0_COMP_vect) | |
| Timer0 compare interrupt (100Hz) More... | |
| LITERS_T | LitersFromDist (double dist) |
| Computes the Volume in Liters from the Distance in Meters. More... | |
| int | main (void) |
| The Main Program. More... | |
| void | ResetDisplayFlags (void) |
| Resets the Error Flags in the Display. More... | |
| void | SetAnalogPerCent (double perCent) |
| Sets the analog Instrument display. More... | |
| static void | ShowScreen (showScreen_t action, uint8_t pageNo) |
| Steps through various Screens (or Pages) to be displayed. More... | |
| bool | VBarGraphPrepare (void) |
| Prepares the lcdVbarChar[]-Array. More... | |
| void | VBarTest (void) |
| void | VBarTestPrint () |
Variables | |
| bool | backlightAlwaysOn |
| Shall the Backlight be always on? More... | |
| uint8_t | backlightOnTime |
| Time in Seconds the LCD-Backlight is already on (topped at 255 Seconds) More... | |
| volatile uint8_t | blFlags |
| Boot Loader Communication Flags. More... | |
| uint8_t | boCnt |
| Counts the number of Brown Out Resets. More... | |
| uint16_t | bootLdAdr |
| The address of the page. More... | |
| uint8_t | bootLdPage [32] |
| Holds the data for boot loader write/read. More... | |
| BTStatus_t | BTStatus |
| Status for Bluetooth connection. More... | |
| const char * | build = __DATE__ |
| The Build Date as to be displayed in the Boot Screen. More... | |
| volatile uint8_t | cFlags |
| Flags set by Serial Communication with the Sensor. More... | |
| volatile char | cmdline [81] |
| Ready to hold 80 chars plus terminating 0. More... | |
| uint8_t | deadTime |
| Received dead time value from the sensor. More... | |
| static volatile delay_t | delaycnt |
| Counter for delay() More... | |
| volatile uint8_t | dFlags |
| Flags Controlling Debug Output. More... | |
| bool | discardFlightTime |
| Used to discard the first measurement after sensor power on. More... | |
| char | displayError [80] |
| const displayMetrics_T | displayMetrics [2] |
| Metrics for each of the possible displays. More... | |
| static uint8_t | displayTimer |
| Counts the seconds for each display page. More... | |
| displayValues_t | displayValues |
| Holds all values that are used for display. More... | |
| double | distance |
| To the reflecting surface in meters. More... | |
| FUSES | |
| Fuse settings for the Production ELF file. More... | |
| volatile uint8_t | hrCnt |
| Hours of the RTC. More... | |
| double | lastReportedVolume |
| Last Volume spontaneously reported. More... | |
| LOCKBITS = (LB_MODE_1) | |
| The Lock Bits for the production File. More... | |
| volatile uint8_t | minCnt |
| Minutes of the RTC. More... | |
| double | pulseTime |
| In seconds. More... | |
| uint16_t | pulseTimeInt |
| Traveling time of the last pulse in timer1-clocks of the sensor CPU. More... | |
| uint8_t | pulseTimeMult |
| 1 or 8 clocks from sensor timer1 prescaler More... | |
| volatile RTCAdj_t | RTCAdj |
| Soft Adjustment of the RTC (+-1%) More... | |
| const char * | RTCAdjTxt [] ={"normal","faster","slower"} |
| Human readable interpretation of RTCAdj. More... | |
| volatile uint8_t | secCnt |
| Seconds of the RTC. More... | |
| static bool | sensorDead |
| Is set to false when a sensor telegram arrives. More... | |
| double | speedOfSound |
| In m/s, temperature calibrated. More... | |
| uint8_t | tempRaw |
| Raw value from the ADC. More... | |
| volatile uint8_t | tFlags |
| Flags set by Timer Interrupt to signal Main Loop. More... | |
| volatile uint8_t | tickCnt |
| counter for timer0 interrupts More... | |
| uint8_t | wdrCnt |
| Counts the number of Watchdog Resets. More... | |
| volatile uint16_t | xmin |
| volatile uint16_t | xres |
The Main Program and miscellaneous Routines.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
| void delay10ms | ( | delay_t | delay10ms | ) |
Delay for a multiple of 10ms.
This function allows delays up to the range of delay_t controlled by the timer interrupt.
delay_t should be an unsigned integer type.
delaycnt must be decremented in the 100Hz-Interrupt.
This function of course takes care of the Watchdog and puts the CPU into sleep mode until the time expires.
| delay10ms | Delay in multiple of 10ms |
References delay10ms(), and delaycnt.
Referenced by CmdCalibrate(), delay10ms(), FTest485(), HBarTest(), and VBarTest().


|
static |
Checks for Communication Flags.
References signalOutput_t::activeAbove, signalOutput_t::activeBelow, ADEUNIS_CFM, ADEUNIS_IND, ADEUNIS_REQ, ADEUNIS_RES, AssertRTS(), BTStatus, CFLAG_BTRECEIVED, CFLAG_BYTERECEIVED, CFLAG_CHECKSUMERROR, CFLAG_CMDRECEIVED, CFLAG_PARITYERROR, CFLAG_TEMPRECEIVED, CFLAG_TIMERECEIVED, cFlags, charsInRbuf0, displayValues_t::checksumErrorChar, confStruct_t::cistCapacity, cmdline, computedChecksum, config, BTPacket_t::data, deadTime, DFLAG_SENSOR, dFlags, discardFlightTime, displayValues, distance, ExecCommand(), BTStatus_t::haveBT, hprintf_P(), BTStatus_t::linkEstablished, displayValues_t::liters, LitersFromDist(), displayValues_t::litersPerCent, displayValues_t::litersTemp, displayValues_t::literUnitChar, LMX9830_READY, BTStatus_t::localPort, displayValues_t::nlitersTemp, BTPacket_t::opcode, BTPacket_t::packetType, displayValues_t::parityErrorChar, pulseTime, pulseTimeInt, pulseTimeMult, rbuf0, BTStatus_t::remoteAddress, SCREENREFRESH, secCnt, sensorDead, displayValues_t::sensorDeadChar, SensorPowerOff(), SetAnalogPerCent(), ShowScreen(), Sig1OFF(), Sig1ON(), Sig2OFF(), Sig2ON(), confStruct_t::signalOutputs, speedOfSound, SPP_INCOMING_LINK_ESTABLISHED, SPP_LINK_RELEASED, SPP_TRANSPARENT_MODE, tempRaw, displayValues_t::tempSemi, tickCnt, BTStatus_t::unknTelCnt, and VBarGraphPrepare().
Referenced by main().


|
static |
Checks for Key Flags.
References backlightAlwaysOn, backlightOnTime, config, delay50ms(), displayTimer, KFLAG_KEYPRESSED, KFLAG_KEYPRESSEDLONG, KFLAG_KEYPRESSEDSHORT, KFLAG_KEYRELEASED, kflags, confStruct_t::LCDBright, LCDGetBrightness(), LCDSetBrightness(), confStruct_t::pageTimeK, SCREENSTEPMANU, and ShowScreen().
Referenced by main().


|
static |
Checks for Time Flags.
References ADCcli(), ADCDataMaxTmp, ADCDataMinTmp, ADCResetMinMax(), ADCsei(), ADCData_t::array, backlightAlwaysOn, confStruct_t::backlightOnTime, backlightOnTime, config, DFLAG_ADC, dFlags, discardFlightTime, displayTimer, displayValues, GetSig1(), GetSig2(), hprintf_P(), hrCnt, lastReportedVolume, LCDGetBrightness(), LCDSetBrightness(), displayValues_t::liters, displayValues_t::litersLastHour, displayValues_t::litersPerHour, displayValues_t::litersTemp, displayValues_t::litersToday, displayValues_t::litersYesterday, displayValues_t::literUnitChar, minCnt, displayValues_t::nlitersTemp, displayValues_t::not10ErrorChar, confStruct_t::pageTime, PlaySequence(), ResetDisplayFlags(), SCREENREFRESH, SCREENSTEPAUTO, secCnt, sensorDead, displayValues_t::sensorDeadChar, SensorPowerOff(), SensorPowerOn(), ShowScreen(), sndBigBenSeq, confStruct_t::sndMask, SNDMASK_ALERT1ALWAYS, SNDMASK_ALERT2ALWAYS, sndSig1, sndSig2, SoundsOK(), confStruct_t::spontaneousReportVolume, Stackchk(), Tbub1IsEmpty(), displayValues_t::tempSemi, TFLAG_DAY, TFLAG_HOUR, TFLAG_MIN, TFLAG_SEC, and tFlags.
Referenced by main().


| int8_t HBarGraphPerCent | ( | uint8_t | line | ) |
Draws a horizontal Bar Graph showing the Cistern Filling in %.
| line | The 0-based Line Number |
References config, displayMetrics, confStruct_t::displayType, displayValues, LCDHBarGraph(), displayValues_t::litersPerCent, and displayMetrics_T::width.
Referenced by ShowScreen().


| void HBarTest | ( | void | ) |
References delay10ms(), LCDClear(), LCDHBarGraph(), and LCDPrintLine_P().

|
static |
Initializes the System.
References confStruct_t::backlightAlwaysOn, backlightAlwaysOn, confStruct_t::backlightOnTime, backlightOnTime, BluetoothPowerOn(), boCnt, config, displayValues, InitADC(), InitDCF77(), InitLCD(), InitSound(), InitUart(), lcd, confStruct_t::LCDBright, confStruct_t::LCDV0, ReadConfig(), ResetDisplayFlags(), speedOfSound, displayValues_t::tempSemi, and wdrCnt.
Referenced by main().


|
static |
limits an integer from -9999 to +9999 for display purposes
| i | the value to limit |
Referenced by ShowScreen().

| ISR | ( | TIMER0_COMP_vect | ) |
Timer0 compare interrupt (100Hz)
The 100Hz-interrupt is not only used to create a RTC (Real Time Clock) but also for other tasks that rely on a constant timing, i.e. the DCF77 routines and debouncing of the pushbutton key.
If you change the frequency, be sure of all of the consequences!
References DCF77int(), delaycnt, hrCnt, KeyInt(), LEDYellowOff(), LEDYellowOn(), minCnt, RTC_FASTER, RTC_SLOWER, RTCAdj, secCnt, SndTimerCallback(), TFLAG_DAY, TFLAG_HOUR, TFLAG_MIN, TFLAG_SEC, tFlags, tickCnt, and UsartTimerCallback().

| LITERS_T LitersFromDist | ( | double | dist | ) |
Computes the Volume in Liters from the Distance in Meters.
| dist | The distance in Meters |
References CIST_CONST_AREA, CIST_HORIZ_CYL, CIST_SPHERE, confStruct_t::cistAreaOrDiameter, confStruct_t::cisternType, confStruct_t::cistHeight, confStruct_t::cistLength, and config.
Referenced by CmdDistance(), and DoCflags().

| int main | ( | void | ) |
The Main Program.
References ADCData_t::ADC_Unreg, ADCDataMax, ADCDataMin, cFlags, config, displayError, displayTimer, displayValues, DoCflags(), DoKFlags(), DoTflags(), displayValues_t::error, Init(), kflags, LEDGreenOff(), LEDGreenOn(), ADCData_t::named, confStruct_t::pageTime, PlaySequence(), SCREENABSPAGE, SCREENABSPAGE_VERSION, ShowScreen(), sndSuccessSeq, tFlags, and UnregFromADC().

| void ResetDisplayFlags | ( | void | ) |
Resets the Error Flags in the Display.
Replaces the character type members flag characters (aka "<PC") by printable default values.
References displayValues_t::checksumErrorChar, displayValues, displayValues_t::error, displayValues_t::literUnitChar, displayValues_t::not10ErrorChar, displayValues_t::parityErrorChar, and displayValues_t::sensorDeadChar.
Referenced by CmdClearErrors(), DoTflags(), and Init().

| void SetAnalogPerCent | ( | double | perCent | ) |
Sets the analog Instrument display.
| perCent | The value in a range from 0.0 to 100.0. Exceeding values will be trimmed correctly. |
References config, and confStruct_t::instCal.
Referenced by CmdAnalog(), CmdCalibrate(), and DoCflags().

|
static |
Steps through various Screens (or Pages) to be displayed.
The static variable page is automatically incremented on each call (except of SCREENREFRESH) and automatically resets to 0 if no case exists for the value. This makes the function really handy. If you want to add a page, simply add a case with the next higher value, and insert the code to display it, that's all.
| action | What to do:
|
| pageNo | The zero-based index of the Page to be displayed. Only used if action==SCREENABSPAGE |
References ADCData_t::ADC_P3, ADCData_t::ADC_P5, ADCData_t::ADC_SWUnreg, ADCData_t::ADC_Unreg, ADCDataAvg, boCnt, build, displayValues_t::checksumErrorChar, config, DCFInSync, DISPLAY_2x16, DISPLAY_4x20, DISPLAY_ANALOG, displayMetrics, confStruct_t::displayType, displayValues, distance, displayValues_t::error, HBarGraphPerCent(), StackchkStruct::heapmax, hrCnt, IntLimit(), LCDClear(), LCDGoTo(), LCDPrintLine_P(), lcdVbarChar, displayValues_t::liters, displayValues_t::litersLastHour, displayValues_t::litersPerHour, displayValues_t::litersToday, displayValues_t::litersYesterday, displayValues_t::literUnitChar, minCnt, ADCData_t::named, displayValues_t::not10ErrorChar, P3FromADC(), P5FromADC(), displayValues_t::parityErrorChar, pulseTime, SCREENABSPAGE, SCREENABSPAGE_VERSION, SCREENREFRESH, SCREENSTEPAUTO, secCnt, displayValues_t::sensorDeadChar, speedOfSound, stackchk, Stackchk(), StackchkStruct::stackmin, SWUnregFromADC(), TempFromADC(), displayValues_t::tempSemi, UnregFromADC(), and wdrCnt.
Referenced by DoCflags(), DoKFlags(), DoTflags(), and main().


| bool VBarGraphPrepare | ( | void | ) |
Prepares the lcdVbarChar[]-Array.
References config, displayMetrics, confStruct_t::displayType, displayValues, LCDBuildVBarChars(), displayValues_t::litersPerCent, and displayMetrics_T::nLines.
Referenced by DoCflags().


| void VBarTest | ( | void | ) |
References delay10ms(), LCDBuildVBarChars(), LCDClear(), and VBarTestPrint().

| void VBarTestPrint | ( | ) |
References LCDPrintLine_P(), and lcdVbarChar.
Referenced by VBarTest().


| bool backlightAlwaysOn |
Shall the Backlight be always on?
Referenced by DoKFlags(), DoTflags(), and Init().
| uint8_t backlightOnTime |
Time in Seconds the LCD-Backlight is already on (topped at 255 Seconds)
Referenced by DoKFlags(), DoTflags(), and Init().
| volatile uint8_t blFlags |
Boot Loader Communication Flags.
Referenced by BootldRead(), BootldWrite(), ISR(), ProgramSensor(), UpdateSensorFirmware(), and VerifySensorFirmware().
| uint8_t boCnt |
Counts the number of Brown Out Resets.
Referenced by CmdClearErrors(), CmdStat(), Init(), and ShowScreen().
| uint16_t bootLdAdr |
The address of the page.
| uint8_t bootLdPage[32] |
Holds the data for boot loader write/read.
Referenced by ISR(), and VerifySensor().
| BTStatus_t BTStatus |
Status for Bluetooth connection.
Referenced by CmdStat(), and DoCflags().
| const char* build = __DATE__ |
The Build Date as to be displayed in the Boot Screen.
Referenced by ShowScreen().
| volatile uint8_t cFlags |
Flags set by Serial Communication with the Sensor.
The flags are set by serial interrupt and must be cleared by the main loop
Referenced by CmdCalibrate(), CmdDistance(), DoCflags(), EnterDouble(), ISR(), main(), ReadIntelHex(), and usart1FlushRx().
| volatile char cmdline[81] |
Ready to hold 80 chars plus terminating 0.
Referenced by CopyRbuf1ToCmdline(), DoCflags(), DoOneLine(), EnterDouble(), and ReadIntelHex().
| uint8_t deadTime |
Received dead time value from the sensor.
Referenced by DoCflags(), and ISR().
|
static |
Counter for delay()
Referenced by delay10ms(), and ISR().
| volatile uint8_t dFlags |
Flags Controlling Debug Output.
Referenced by CmdDebug(), DCF77int(), DoCflags(), DoTflags(), PushBit(), and RTCsync().
| bool discardFlightTime |
Used to discard the first measurement after sensor power on.
Referenced by DoCflags(), and DoTflags().
| char displayError[80] |
Referenced by main().
| const displayMetrics_T displayMetrics[2] |
Metrics for each of the possible displays.
Referenced by HBarGraphPerCent(), LCDBuildVBarChars(), LCDHBarGraph(), LCDPrintLine_P(), ShowScreen(), and VBarGraphPrepare().
|
static |
Counts the seconds for each display page.
Referenced by DoKFlags(), DoTflags(), and main().
| displayValues_t displayValues |
Holds all values that are used for display.
Referenced by CmdDistance(), CmdGetSensorValues(), CmdStat(), DoCflags(), DoTflags(), HBarGraphPerCent(), Init(), ISR(), main(), ResetDisplayFlags(), ShowScreen(), and VBarGraphPrepare().
| double distance |
To the reflecting surface in meters.
Referenced by CmdDistance(), CmdStat(), DoCflags(), and ShowScreen().
| FUSES |
Fuse settings for the Production ELF file.
| volatile uint8_t hrCnt |
Hours of the RTC.
Referenced by CmdDistance(), CmdSetTime(), CmdStat(), DoTflags(), ISR(), RTCsync(), ShowScreen(), and SoundsOK().
| double lastReportedVolume |
Last Volume spontaneously reported.
Referenced by CmdStat(), and DoTflags().
| LOCKBITS = (LB_MODE_1) |
The Lock Bits for the production File.
| volatile uint8_t minCnt |
Minutes of the RTC.
Referenced by CmdDistance(), CmdSetTime(), CmdStat(), DoTflags(), ISR(), RTCsync(), and ShowScreen().
| double pulseTime |
In seconds.
Referenced by CmdDistance(), DoCflags(), and ShowScreen().
| uint16_t pulseTimeInt |
Traveling time of the last pulse in timer1-clocks of the sensor CPU.
Referenced by CmdDistance(), DoCflags(), and ISR().
| uint8_t pulseTimeMult |
1 or 8 clocks from sensor timer1 prescaler
Referenced by CmdDistance(), DoCflags(), and ISR().
| volatile RTCAdj_t RTCAdj |
Soft Adjustment of the RTC (+-1%)
Referenced by CmdStat(), Invalidate(), ISR(), and RTCsync().
| const char* RTCAdjTxt[] ={"normal","faster","slower"} |
| volatile uint8_t secCnt |
Seconds of the RTC.
Referenced by CmdDistance(), CmdSetTime(), CmdStat(), DoCflags(), DoTflags(), FTest485(), ISR(), RTCsync(), and ShowScreen().
|
static |
Is set to false when a sensor telegram arrives.
Referenced by DoCflags(), and DoTflags().
| double speedOfSound |
In m/s, temperature calibrated.
Referenced by CmdDistance(), DoCflags(), Init(), and ShowScreen().
| uint8_t tempRaw |
Raw value from the ADC.
Referenced by DoCflags(), and ISR().
| volatile uint8_t tFlags |
Flags set by Timer Interrupt to signal Main Loop.
The flags are set each second, minute, hour or day respectively by timer interrupt. The flags must be cleared by the main loop.
Referenced by DoTflags(), ISR(), and main().
| volatile uint8_t tickCnt |
counter for timer0 interrupts
Referenced by BootldWrite(), DoCflags(), FTestSWUnreg(), ISR(), RTCsync(), and WaitKeyBlinking().
| uint8_t wdrCnt |
Counts the number of Watchdog Resets.
Referenced by CmdClearErrors(), CmdStat(), Init(), and ShowScreen().
| volatile uint16_t xmin |
| volatile uint16_t xres |
1.8.15