LevelMeter-Display  2.0
An ultrasonic Level Meter for Stormwater Cisterns
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
display.h File Reference
Include dependency graph for display.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  displayMetrics_T
 Parameters for each of the possible Displays. More...
 
struct  displayValues_t
 Holds all values used for Display Purposes. More...
 

Macros

#define ADCVoltsPerLSB   (2.56/1024)
 Voltage step for one LSB of the AD converter. More...
 
#define dividerP3   (4.7/(4.7+8.2))
 Resistor divider for P3. Gives 7.03V FSR or 6.86mV/LSB. More...
 
#define dividerP5   (4.7/(4.7+8.2))
 Resistor divider for P5. Gives 7.03V FSR or 6.86mV/LSB. More...
 
#define dividerSWUnreg   (4.7/(4.7+68))
 Resistor divider for SWUnreg. Gives 39.6V FSR or 38.7mV/LSB. More...
 
#define dividerUnreg   (4.7/(4.7+68))
 Resistor divider for Unreg. Gives 39.6V FSR or 38.7mV/LSB. More...
 
#define SCREENABSPAGE_VERSION   128
 Display Version Screen at startup. More...
 
#define SIGNAL_1_MASK   0b00000100
 
#define SIGNAL_2_MASK   0b00001000
 
#define SIGNAL_PORT   PORTA
 
#define WITH_UPDATE
 Compile with Sensor Update Function. More...
 

Typedefs

typedef uint8_t delay_t
 
typedef double LITERS_T
 Remember that liters may go negative. More...
 

Enumerations

enum  displayType_t { DISPLAY_2x16, DISPLAY_4x20, DISPLAY_ANALOG }
 Constants for Display Type. More...
 
enum  RTCAdj_t { RTC_NORMAL, RTC_FASTER, RTC_SLOWER }
 Current speed of the RTC (Real Time Clock) More...
 
enum  showScreen_t { SCREENSTEPAUTO, SCREENSTEPMANU, SCREENREFRESH, SCREENABSPAGE }
 Command for ShowScreen() More...
 

Functions

static void BluetoothPowerOff (void)
 Switches the Bluetooth Power off. More...
 
static void BluetoothPowerOn (void)
 Switches the Bluetooth Power on. More...
 
void delay10ms (delay_t delay10ms)
 Delay for a multiple of 10ms. More...
 
static bool GetSig1 (void)
 Gets State of Optocoupler 1 True means Optocoupler is ON. More...
 
static bool GetSig2 (void)
 Gets State of Optocoupler 2 True means Optocoupler is ON. More...
 
LITERS_T LitersFromDist (double dist)
 Computes the Volume in Liters from the Distance in Meters. More...
 
void ResetDisplayFlags (void)
 Resets the Error Flags in the Display. More...
 
static void SensorPowerOff (void)
 Switches the Sensor Power off. More...
 
static void SensorPowerOn (void)
 Switches the Sensor Power on. More...
 
void SetAnalogPerCent (double perCent)
 Sets the analog Instrument display. More...
 
static void Sig1OFF (void)
 Switches Signal Output Optocoupler 1 to OFF. More...
 
static void Sig1ON (void)
 Switches Signal Output Optocoupler 1 to ON. More...
 
static void Sig2OFF (void)
 Switches Signal Output Optocoupler 2 to OFF. More...
 
static void Sig2ON (void)
 Switches Signal Output Optocoupler 2 to ON. More...
 

Variables

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...
 
static const uint8_t BOOTLDDATA =2
 Boot Loader Data received ("=") More...
 
static const uint8_t BOOTLDERROR =8
 Boot Loader Error received ("-") More...
 
static const uint8_t BOOTLDHELLO =1
 Boot Loader Hello received ("*") More...
 
static const uint8_t BOOTLDOK =4
 Boot Loader Data received ("+") More...
 
uint8_t bootLdPage []
 Holds the data for boot loader write/read. More...
 
static const uint8_t BOOTLDPROTECTED =16
 Boot Loader Protected Area received ("P") More...
 
static const uint8_t CFLAG_BTRECEIVED =64
 Received a telegram from the Bluetooth-Module. More...
 
static const uint8_t CFLAG_BYTERECEIVED =32
 Received a Byte from the host. More...
 
static const uint8_t CFLAG_CHECKSUMERROR =8
 Checksum Error in received Telegram. More...
 
static const uint8_t CFLAG_CMDRECEIVED =16
 Received the terminating CR of a Command. More...
 
static const uint8_t CFLAG_PARITYERROR =4
 Parity Error in received Byte. More...
 
static const uint8_t CFLAG_TEMPRECEIVED =2
 Received the current Sensor Temperature. More...
 
static const uint8_t CFLAG_TIMERECEIVED =1
 Received a Travel Time from the Sensor. 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 const uint8_t DFLAG_ADC =4
 Gives information about ADC MIN/MAX Values. More...
 
static const uint8_t DFLAG_DCF77 =1
 Gives information about DCF77 and RTC. More...
 
static const uint8_t DFLAG_SENSOR =2
 Gives information about Sensor Communication. More...
 
volatile uint8_t dFlags
 Flags Controlling Debug Output. More...
 
const displayMetrics_T displayMetrics []
 Metrics for each of the possible displays. More...
 
displayType_t displayType
 
displayValues_t displayValues
 Holds all values that are used for display. More...
 
double distance
 To the reflecting surface in meters. More...
 
volatile uint8_t hrCnt
 Hours of the RTC. More...
 
double lastReportedVolume
 Last Volume spontaneously reported. 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 []
 Human readable interpretation of RTCAdj. More...
 
volatile uint8_t secCnt
 Seconds of the RTC. More...
 
double speedOfSound
 In m/s, temperature calibrated. More...
 
uint8_t tempRaw
 Raw value from the ADC. More...
 
signed char tempSemi
 
static const uint8_t TFLAG_DAY =8
 Is set every Day at Midnight. More...
 
static const uint8_t TFLAG_HOUR =4
 Is set once per Hour at Minute 0. More...
 
static const uint8_t TFLAG_MIN =2
 Is set once per Minute at Second 0. More...
 
static const uint8_t TFLAG_SEC =1
 Is set once per Second. 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...
 

Macro Definition Documentation

◆ ADCVoltsPerLSB

#define ADCVoltsPerLSB   (2.56/1024)

Voltage step for one LSB of the AD converter.

◆ dividerP3

#define dividerP3   (4.7/(4.7+8.2))

Resistor divider for P3. Gives 7.03V FSR or 6.86mV/LSB.

◆ dividerP5

#define dividerP5   (4.7/(4.7+8.2))

Resistor divider for P5. Gives 7.03V FSR or 6.86mV/LSB.

◆ dividerSWUnreg

#define dividerSWUnreg   (4.7/(4.7+68))

Resistor divider for SWUnreg. Gives 39.6V FSR or 38.7mV/LSB.

◆ dividerUnreg

#define dividerUnreg   (4.7/(4.7+68))

Resistor divider for Unreg. Gives 39.6V FSR or 38.7mV/LSB.

◆ SCREENABSPAGE_VERSION

#define SCREENABSPAGE_VERSION   128

Display Version Screen at startup.

◆ SIGNAL_1_MASK

#define SIGNAL_1_MASK   0b00000100

◆ SIGNAL_2_MASK

#define SIGNAL_2_MASK   0b00001000

◆ SIGNAL_PORT

#define SIGNAL_PORT   PORTA

◆ WITH_UPDATE

#define WITH_UPDATE

Compile with Sensor Update Function.

Typedef Documentation

◆ delay_t

typedef uint8_t delay_t

◆ LITERS_T

typedef double LITERS_T

Remember that liters may go negative.

Enumeration Type Documentation

◆ displayType_t

Constants for Display Type.

Enumerator
DISPLAY_2x16 

Display is a Winstar WH1602B3 or equivalent.

DISPLAY_4x20 

Display is a Winstar WH2004A or equivalent.

DISPLAY_ANALOG 

We have no LCD at all, only analog output.

◆ RTCAdj_t

enum RTCAdj_t

Current speed of the RTC (Real Time Clock)

Enumerator
RTC_NORMAL 

RTC is running at normal speed (realtime)

RTC_FASTER 

RTC is running faster by 1%.

RTC_SLOWER 

RTC is running slower by 1%.

◆ showScreen_t

Command for ShowScreen()

Enumerator
SCREENSTEPAUTO 

Advance to the next page of the frequently used.

SCREENSTEPMANU 

Advance to the next of all available pages.

SCREENREFRESH 

Do not change the page, just refresh the current one.

SCREENABSPAGE 

Show a special page. Currently only used for the init-screen.

Function Documentation

◆ BluetoothPowerOff()

static void BluetoothPowerOff ( void  )
inlinestatic

Switches the Bluetooth Power off.

◆ BluetoothPowerOn()

static void BluetoothPowerOn ( void  )
inlinestatic

Switches the Bluetooth Power on.

Referenced by Init().

Here is the caller graph for this function:

◆ 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:

◆ GetSig1()

static bool GetSig1 ( void  )
inlinestatic

Gets State of Optocoupler 1 True means Optocoupler is ON.

References SIGNAL_1_MASK, and SIGNAL_PORT.

Referenced by DoTflags().

Here is the caller graph for this function:

◆ GetSig2()

static bool GetSig2 ( void  )
inlinestatic

Gets State of Optocoupler 2 True means Optocoupler is ON.

References SIGNAL_2_MASK, and SIGNAL_PORT.

Referenced by DoTflags().

Here is the caller 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:

◆ 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:

◆ SensorPowerOff()

static void SensorPowerOff ( void  )
inlinestatic

Switches the Sensor Power off.

Referenced by CmdCalibrate(), CmdDistance(), DoCflags(), DoTflags(), FTest(), FTestSWUnreg(), UpdateSensorFirmware(), and VerifySensorFirmware().

Here is the caller graph for this function:

◆ SensorPowerOn()

static void SensorPowerOn ( void  )
inlinestatic

Switches the Sensor Power on.

Referenced by CmdCalibrate(), CmdDistance(), DoTflags(), FTestSWUnreg(), UpdateSensorFirmware(), and VerifySensorFirmware().

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:

◆ Sig1OFF()

static void Sig1OFF ( void  )
inlinestatic

Switches Signal Output Optocoupler 1 to OFF.

References SIGNAL_1_MASK, and SIGNAL_PORT.

Referenced by DoCflags(), and FTestToggleSignal().

Here is the caller graph for this function:

◆ Sig1ON()

static void Sig1ON ( void  )
inlinestatic

Switches Signal Output Optocoupler 1 to ON.

References SIGNAL_1_MASK, and SIGNAL_PORT.

Referenced by DoCflags(), and FTestToggleSignal().

Here is the caller graph for this function:

◆ Sig2OFF()

static void Sig2OFF ( void  )
inlinestatic

Switches Signal Output Optocoupler 2 to OFF.

References SIGNAL_2_MASK, and SIGNAL_PORT.

Referenced by DoCflags(), and FTestToggleSignal().

Here is the caller graph for this function:

◆ Sig2ON()

static void Sig2ON ( void  )
inlinestatic

Switches Signal Output Optocoupler 2 to ON.

References SIGNAL_2_MASK, and SIGNAL_PORT.

Referenced by DoCflags(), and FTestToggleSignal().

Here is the caller graph for this function:

Variable Documentation

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

◆ BOOTLDDATA

const uint8_t BOOTLDDATA =2
static

Boot Loader Data received ("=")

Referenced by BootldRead(), and ISR().

◆ BOOTLDERROR

const uint8_t BOOTLDERROR =8
static

Boot Loader Error received ("-")

Referenced by BootldRead(), BootldWrite(), and ISR().

◆ BOOTLDHELLO

const uint8_t BOOTLDHELLO =1
static

Boot Loader Hello received ("*")

Referenced by ISR(), UpdateSensorFirmware(), and VerifySensorFirmware().

◆ BOOTLDOK

const uint8_t BOOTLDOK =4
static

Boot Loader Data received ("+")

Referenced by ISR().

◆ bootLdPage

uint8_t bootLdPage[]

Holds the data for boot loader write/read.

Referenced by ISR(), and VerifySensor().

◆ BOOTLDPROTECTED

const uint8_t BOOTLDPROTECTED =16
static

Boot Loader Protected Area received ("P")

Referenced by ISR().

◆ CFLAG_BTRECEIVED

const uint8_t CFLAG_BTRECEIVED =64
static

Received a telegram from the Bluetooth-Module.

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

◆ CFLAG_BYTERECEIVED

const uint8_t CFLAG_BYTERECEIVED =32
static

Received a Byte from the host.

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

◆ CFLAG_CHECKSUMERROR

const uint8_t CFLAG_CHECKSUMERROR =8
static

Checksum Error in received Telegram.

Referenced by DoCflags(), and ISR().

◆ CFLAG_CMDRECEIVED

const uint8_t CFLAG_CMDRECEIVED =16
static

Received the terminating CR of a Command.

Referenced by DoCflags(), EnterDouble(), ISR(), ReadIntelHex(), and usart1FlushRx().

◆ CFLAG_PARITYERROR

const uint8_t CFLAG_PARITYERROR =4
static

Parity Error in received Byte.

Referenced by DoCflags(), and ISR().

◆ CFLAG_TEMPRECEIVED

const uint8_t CFLAG_TEMPRECEIVED =2
static

Received the current Sensor Temperature.

Referenced by DoCflags(), and ISR().

◆ CFLAG_TIMERECEIVED

const uint8_t CFLAG_TIMERECEIVED =1
static

Received a Travel Time from the Sensor.

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

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

◆ DFLAG_ADC

const uint8_t DFLAG_ADC =4
static

Gives information about ADC MIN/MAX Values.

Referenced by CmdDebug(), and DoTflags().

◆ DFLAG_DCF77

const uint8_t DFLAG_DCF77 =1
static

Gives information about DCF77 and RTC.

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

◆ DFLAG_SENSOR

const uint8_t DFLAG_SENSOR =2
static

Gives information about Sensor Communication.

Referenced by CmdDebug(), and DoCflags().

◆ dFlags

volatile uint8_t dFlags

Flags Controlling Debug Output.

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

◆ displayMetrics

const displayMetrics_T displayMetrics[]

Metrics for each of the possible displays.

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

◆ displayType

displayType_t displayType

◆ displayValues

displayValues_t displayValues

◆ distance

double distance

To the reflecting surface in meters.

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

◆ hrCnt

volatile uint8_t hrCnt

◆ lastReportedVolume

double lastReportedVolume

Last Volume spontaneously reported.

Referenced by CmdStat(), and DoTflags().

◆ 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[]

Human readable interpretation of RTCAdj.

Referenced by CmdStat(), and RTCsync().

◆ secCnt

volatile uint8_t secCnt

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

◆ tempSemi

signed char tempSemi

◆ TFLAG_DAY

const uint8_t TFLAG_DAY =8
static

Is set every Day at Midnight.

Referenced by DoTflags(), and ISR().

◆ TFLAG_HOUR

const uint8_t TFLAG_HOUR =4
static

Is set once per Hour at Minute 0.

Referenced by DoTflags(), and ISR().

◆ TFLAG_MIN

const uint8_t TFLAG_MIN =2
static

Is set once per Minute at Second 0.

Referenced by DoTflags(), and ISR().

◆ TFLAG_SEC

const uint8_t TFLAG_SEC =1
static

Is set once per Second.

Referenced by DoTflags(), 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().