LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions | Variables
Display.c File Reference

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...
 
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...
 
static LITERS_T LitersFromDist (double dist)
 Computes the Volume in Liters from the Distance in Meters. More...
 
int main (void)
 The Main Program. More...
 
static 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 to be displayed. More...
 

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...
 
const char * build ="Bld " __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...
 
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...
 
 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...
 
signed char tempSemi
 Temperature in 0.5°C. 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...
 

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

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!
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
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
static void DoTflags ( void  )
static

Checks for Time Flags.

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

Initializes the System.

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
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 Key.
If you change the frequency, be sure of all of the consequences!

static LITERS_T LitersFromDist ( double  dist)
inlinestatic

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
int main ( void  )

The Main Program.

static void ResetDisplayFlags ( void  )
static

Resets the Error Flags in the Display.

Replaces the error flag characters (aka "<PC") by spaces

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 beeing displayed at the position they reside!
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.
static void ShowScreen ( showScreen_t  action,
uint8_t  pageNo 
)
static

Steps through various Screens to be displayed.

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.

Variable Documentation

bool backlightAlwaysOn

Shall the Backlight be always on?

uint8_t backlightOnTime

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

volatile uint8_t blFlags

Boot Loader Communication Flags.

uint8_t boCnt

Counts the number of Brown Out Resets.

uint16_t bootLdAdr

The address of the page.

uint8_t bootLdPage[32]

Holds the data for boot loader write/read.

const char* build ="Bld " __DATE__

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

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

volatile char cmdline[81]

Ready to hold 80 chars plus terminating 0.

uint8_t deadTime

Received dead time value from the sensor.

volatile delay_t delaycnt
static

Counter for delay()

volatile uint8_t dFlags

Flags Controlling Debug Output.

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.

uint8_t displayTimer
static

Counts the seconds for each display page.

displayValues_t displayValues

Holds all values that are used for display.

double distance

To the reflecting surface in meters.

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

Fuse settings for the Production ELF file.

volatile uint8_t hrCnt

Hours of the RTC.

LOCKBITS = (LB_MODE_1)

The Lock Bits for the production File.

volatile uint8_t minCnt

Minutes of the RTC.

double pulseTime

In seconds.

uint16_t pulseTimeInt

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

uint8_t pulseTimeMult

1 or 8 clocks from sensor timer1 prescaler

volatile RTCAdj_t RTCAdj

Soft Adjustment of the RTC (+-1%)

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

Human readable interpretation of RTCAdj.

volatile uint8_t secCnt

Seconds of the RTC.

bool sensorDead
static

Is set to false when a sensor telegram arrives.

double speedOfSound

In m/s, temperature calibrated.

uint8_t tempRaw

Raw value from the ADC.

signed char tempSemi

Temperature in 0.5°C.

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.

volatile uint8_t tickCnt

counter for timer0 interrupts

uint8_t wdrCnt

Counts the number of Watchdog Resets.