LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Functions | Variables
display.c File Reference

The Main Program and miscellaneous Routines. More...

Include dependency graph for display.c:

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
 

Detailed Description

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/.

Function Documentation

◆ delay10ms()

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.

Parameters
delay10msDelay in multiple of 10ms
Note
This function is not reentrant since there is only one delaycnt! The timer interrupt has to be enabled when calling this function else it will result in an infinite loop. Not even the watchdog would take you out!
The granularity of this function is 10ms, i.e. called with a value of 10, it may delay for 90..100ms.

References delay10ms(), and delaycnt.

Referenced by CmdCalibrate(), delay10ms(), FTest485(), HBarTest(), and VBarTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoCflags()

static void DoCflags ( void  )
static

Checks for Communication Flags.

Note
Be sure to check and clear all Flags even if you don't use them to avoid unnecessary calls of this function

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoKFlags()

static void DoKFlags ( void  )
static

Checks for Key Flags.

Note
Be sure to check and clear all Flags even if you don't use them to avoid unnecessary calls of this function

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoTflags()

static void DoTflags ( void  )
static

◆ HBarGraphPerCent()

int8_t HBarGraphPerCent ( uint8_t  line)

Draws a horizontal Bar Graph showing the Cistern Filling in %.

Parameters
lineThe 0-based Line Number
Returns
The return Value of LCDBarGraph (-1 on Error, 0 if OK)

References config, displayMetrics, confStruct_t::displayType, displayValues, LCDHBarGraph(), displayValues_t::litersPerCent, and displayMetrics_T::width.

Referenced by ShowScreen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HBarTest()

void HBarTest ( void  )

References delay10ms(), LCDClear(), LCDHBarGraph(), and LCDPrintLine_P().

Here is the call graph for this function:

◆ Init()

static void Init ( void  )
static

◆ IntLimit()

static int16_t IntLimit ( LITERS_T  i)
static

limits an integer from -9999 to +9999 for display purposes

Parameters
ithe value to limit
Returns
i if in range, else -9999 or +9999

Referenced by ShowScreen().

Here is the caller graph for this function:

◆ ISR()

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().

Here is the call graph for this function:

◆ LitersFromDist()

LITERS_T LitersFromDist ( double  dist)

Computes the Volume in Liters from the Distance in Meters.

Parameters
distThe distance in Meters
Note
The calculation of the volume is, especially with horizontal cylinders, quite complex and may take more than a millisecond of CPU time.
If dist is zero, liters will be returned as zero to indicate an invalid value. This is not fail safe since it might be exactly zero but the user will notice that the liters are invalid.
Returns
The Volume in Liters

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().

Here is the caller graph for this function:

◆ main()

int main ( void  )

◆ ResetDisplayFlags()

void ResetDisplayFlags ( void  )

Resets the Error Flags in the Display.

Replaces the character type members flag characters (aka "<PC") by printable default values.

Note
This function has to be called at least during system initialization since the characters would be 0 by default. This would terminate any line being displayed at the position they reside!

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().

Here is the caller graph for this function:

◆ SetAnalogPerCent()

void SetAnalogPerCent ( double  perCent)

Sets the analog Instrument display.

Parameters
perCentThe 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().

Here is the caller graph for this function:

◆ ShowScreen()

static void ShowScreen ( showScreen_t  action,
uint8_t  pageNo 
)
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.

Parameters
actionWhat to do:
  • SCREENSTEPAUTO steps through the most frequent pages
  • SCREENSTEPMANU additionally displays some extra pages normally not needed
  • SCREENREFRESH just redraws the current page with actual values
  • SCREENABSPAGE show a special page according to pageNo
pageNoThe zero-based index of the Page to be displayed. Only used if action==SCREENABSPAGE
Note
Each screen should assure that no previous artifacts remain, i.e. it should either display four (or two, according to the display type) complete lines, including trailing spaces, or clear the display before drawing.
To assure a 'quiet' display without flicker redrawing all lines of the display is the preferred method. ShowScreen may be called several times a second.
Remaining lines or characters from previous screens would not be updated and might irritate the user.
So redrawing each line via LCDPrintLine_P() is the method of choice.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VBarGraphPrepare()

bool VBarGraphPrepare ( void  )

Prepares the lcdVbarChar[]-Array.

Returns
The return Value of LCDBuildVBarChars (true if OK, false if not)

References config, displayMetrics, confStruct_t::displayType, displayValues, LCDBuildVBarChars(), displayValues_t::litersPerCent, and displayMetrics_T::nLines.

Referenced by DoCflags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VBarTest()

void VBarTest ( void  )

References delay10ms(), LCDBuildVBarChars(), LCDClear(), and VBarTestPrint().

Here is the call graph for this function:

◆ VBarTestPrint()

void VBarTestPrint ( )

References LCDPrintLine_P(), and lcdVbarChar.

Referenced by VBarTest().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ backlightAlwaysOn

bool backlightAlwaysOn

Shall the Backlight be always on?

Referenced by DoKFlags(), DoTflags(), and Init().

◆ backlightOnTime

uint8_t backlightOnTime

Time in Seconds the LCD-Backlight is already on (topped at 255 Seconds)

Referenced by DoKFlags(), DoTflags(), and Init().

◆ blFlags

volatile uint8_t blFlags

Boot Loader Communication Flags.

Referenced by BootldRead(), BootldWrite(), ISR(), ProgramSensor(), UpdateSensorFirmware(), and VerifySensorFirmware().

◆ boCnt

uint8_t boCnt

Counts the number of Brown Out Resets.

Referenced by CmdClearErrors(), CmdStat(), Init(), and ShowScreen().

◆ bootLdAdr

uint16_t bootLdAdr

The address of the page.

◆ bootLdPage

uint8_t bootLdPage[32]

Holds the data for boot loader write/read.

Referenced by ISR(), and VerifySensor().

◆ BTStatus

BTStatus_t BTStatus

Status for Bluetooth connection.

Referenced by CmdStat(), and DoCflags().

◆ build

const char* build = __DATE__

The Build Date as to be displayed in the Boot Screen.

Referenced by ShowScreen().

◆ cFlags

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().

◆ cmdline

volatile char cmdline[81]

Ready to hold 80 chars plus terminating 0.

Referenced by CopyRbuf1ToCmdline(), DoCflags(), DoOneLine(), EnterDouble(), and ReadIntelHex().

◆ deadTime

uint8_t deadTime

Received dead time value from the sensor.

Referenced by DoCflags(), and ISR().

◆ delaycnt

volatile delay_t delaycnt
static

Counter for delay()

Referenced by delay10ms(), and ISR().

◆ dFlags

volatile uint8_t dFlags

Flags Controlling Debug Output.

Referenced by CmdDebug(), DCF77int(), DoCflags(), DoTflags(), PushBit(), and RTCsync().

◆ discardFlightTime

bool discardFlightTime

Used to discard the first measurement after sensor power on.

Referenced by DoCflags(), and DoTflags().

◆ displayError

char displayError[80]

Referenced by main().

◆ displayMetrics

const displayMetrics_T displayMetrics[2]
Initial value:
=
{
{16,2,{0,64,20,84}},
{20,4,{0,64,20,84}}
}

Metrics for each of the possible displays.

Referenced by HBarGraphPerCent(), LCDBuildVBarChars(), LCDHBarGraph(), LCDPrintLine_P(), ShowScreen(), and VBarGraphPrepare().

◆ displayTimer

uint8_t displayTimer
static

Counts the seconds for each display page.

Referenced by DoKFlags(), DoTflags(), and main().

◆ displayValues

displayValues_t displayValues

◆ distance

double distance

To the reflecting surface in meters.

Referenced by CmdDistance(), CmdStat(), DoCflags(), and ShowScreen().

◆ FUSES

FUSES
Initial value:
=
{
.low = (FUSE_BODLEVEL & FUSE_BODEN),
.high = (FUSE_SPIEN & FUSE_BOOTSZ0 & FUSE_BOOTSZ1),
.extended = (0xff),
}

Fuse settings for the Production ELF file.

◆ hrCnt

volatile uint8_t hrCnt

◆ lastReportedVolume

double lastReportedVolume

Last Volume spontaneously reported.

Referenced by CmdStat(), and DoTflags().

◆ LOCKBITS

LOCKBITS = (LB_MODE_1)

The Lock Bits for the production File.

◆ minCnt

volatile uint8_t minCnt

Minutes of the RTC.

Referenced by CmdDistance(), CmdSetTime(), CmdStat(), DoTflags(), ISR(), RTCsync(), and ShowScreen().

◆ pulseTime

double pulseTime

In seconds.

Referenced by CmdDistance(), DoCflags(), and ShowScreen().

◆ pulseTimeInt

uint16_t pulseTimeInt

Traveling time of the last pulse in timer1-clocks of the sensor CPU.

Referenced by CmdDistance(), DoCflags(), and ISR().

◆ pulseTimeMult

uint8_t pulseTimeMult

1 or 8 clocks from sensor timer1 prescaler

Referenced by CmdDistance(), DoCflags(), and ISR().

◆ RTCAdj

volatile RTCAdj_t RTCAdj

Soft Adjustment of the RTC (+-1%)

Referenced by CmdStat(), Invalidate(), ISR(), and RTCsync().

◆ RTCAdjTxt

const char* RTCAdjTxt[] ={"normal","faster","slower"}

Human readable interpretation of RTCAdj.

Referenced by CmdStat(), and RTCsync().

◆ secCnt

volatile uint8_t secCnt

◆ sensorDead

bool sensorDead
static

Is set to false when a sensor telegram arrives.

Referenced by DoCflags(), and DoTflags().

◆ speedOfSound

double speedOfSound

In m/s, temperature calibrated.

Referenced by CmdDistance(), DoCflags(), Init(), and ShowScreen().

◆ tempRaw

uint8_t tempRaw

Raw value from the ADC.

Referenced by DoCflags(), and ISR().

◆ tFlags

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().

◆ tickCnt

volatile uint8_t tickCnt

counter for timer0 interrupts

Referenced by BootldWrite(), DoCflags(), FTestSWUnreg(), ISR(), RTCsync(), and WaitKeyBlinking().

◆ wdrCnt

uint8_t wdrCnt

Counts the number of Watchdog Resets.

Referenced by CmdClearErrors(), CmdStat(), Init(), and ShowScreen().

◆ xmin

volatile uint16_t xmin

◆ xres

volatile uint16_t xres