This is a demonstration program which draws a keypad on the LCD and uses the touch screen to allow an operator to key-in an access code. Two possible codes are allowed to grant to different levels of access. Additionally the push button is used to allow an operator to send Moorse Code pulses in to the device which is checked against two characters to determine if there was a match, and if so, access is granted.

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI

Also draws a mushroom on the screen and animates it.

Committer:
Damotclese
Date:
Sat Jun 01 20:43:11 2019 +0000
Revision:
1:316582aec4fb
Parent:
0:04d4cc695e56
Child:
3:0e554d8d5a19
Added animation of a mushroom sprite that occasionally teleports.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Damotclese 0:04d4cc695e56 1
Damotclese 0:04d4cc695e56 2 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 3 // SecurityUnlockDemo-Main.cpp
Damotclese 0:04d4cc695e56 4 //
Damotclese 1:316582aec4fb 5 // Fredric L. Rice, June 2019
Damotclese 0:04d4cc695e56 6 //
Damotclese 0:04d4cc695e56 7 // This is a demonstration of how to build a keypad on the liquid
Damotclese 0:04d4cc695e56 8 // crystal display and then use the touch screen as a keypad to enter
Damotclese 0:04d4cc695e56 9 // an access code which grants access to other functionality. Two
Damotclese 0:04d4cc695e56 10 // levels of access is possible, with the more permissive access a
Damotclese 0:04d4cc695e56 11 // longer series of digits than the lesser-permissive access code.
Damotclese 0:04d4cc695e56 12 //
Damotclese 0:04d4cc695e56 13 // The keypad is built using position information in a table with some
Damotclese 0:04d4cc695e56 14 // fairly easy ways to move the keypad around on the display.
Damotclese 0:04d4cc695e56 15 //
Damotclese 0:04d4cc695e56 16 // The demonstration code also allows for the push button to be used
Damotclese 0:04d4cc695e56 17 // to key in Moorse Code pulses which are timed and then checked to
Damotclese 0:04d4cc695e56 18 // see if they match an expected access code for Moorse access.
Damotclese 0:04d4cc695e56 19 //
Damotclese 0:04d4cc695e56 20 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 21
Damotclese 1:316582aec4fb 22 #include "mbed.h" // The mbed operating system
Damotclese 1:316582aec4fb 23 #include "LCD_DISCO_F429ZI.h" // For controlling the LCD
Damotclese 1:316582aec4fb 24 #include "TS_DISCO_F429ZI.h" // For controlling the touch screen
Damotclese 1:316582aec4fb 25 #include "SecurityUnlockDemo-Main.h" // Always include our own header
Damotclese 1:316582aec4fb 26 #include "SecurityUnlockDemo-Keypad.h" // For all of the keypad functionality
Damotclese 1:316582aec4fb 27 #include "SecurityUnlockDemo-Moorse.h" // For all of the Moorse Code functionality
Damotclese 1:316582aec4fb 28 #include "SecurityUnlockDemo-Animation.h" // For performing animation
Damotclese 0:04d4cc695e56 29
Damotclese 0:04d4cc695e56 30 // ----------------------------------------------------------------------
Damotclese 1:316582aec4fb 31 // Define global data storage which we will export
Damotclese 0:04d4cc695e56 32 //
Damotclese 0:04d4cc695e56 33 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 34
Damotclese 0:04d4cc695e56 35 // We will be using the LCD so instantiate an object locally
Damotclese 1:316582aec4fb 36 LCD_DISCO_F429ZI st_lcd;
Damotclese 0:04d4cc695e56 37
Damotclese 0:04d4cc695e56 38 // We will be using the touch screen so instantiate an object
Damotclese 1:316582aec4fb 39 TS_DISCO_F429ZI st_touchScreen;
Damotclese 0:04d4cc695e56 40
Damotclese 1:316582aec4fb 41 // ----------------------------------------------------------------------
Damotclese 1:316582aec4fb 42 // Local data storage this module will hold
Damotclese 1:316582aec4fb 43 //
Damotclese 1:316582aec4fb 44 // ----------------------------------------------------------------------
Damotclese 1:316582aec4fb 45
Damotclese 1:316582aec4fb 46 // Because the mbed randomizer is not very good, we maintain the
Damotclese 1:316582aec4fb 47 // following counter which is incremented every time the main
Damotclese 1:316582aec4fb 48 // thread executes so that we can use it to assist in randoming
Damotclese 1:316582aec4fb 49 // our numbers for the animation
Damotclese 1:316582aec4fb 50 static uint32_t u32_randomSeeder;
Damotclese 0:04d4cc695e56 51
Damotclese 0:04d4cc695e56 52 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 53 // MainInit()
Damotclese 0:04d4cc695e56 54 //
Damotclese 0:04d4cc695e56 55 // This function will:
Damotclese 0:04d4cc695e56 56 // o Initialize the module's locally-held data
Damotclese 0:04d4cc695e56 57 // o Clear the LCD and set the display to WHITE
Damotclese 0:04d4cc695e56 58 // o Set the default character font size
Damotclese 0:04d4cc695e56 59 // o Initialize the touch screen by polling the size of the LCD
Damotclese 0:04d4cc695e56 60 // o Sets the push button to have no pull-up
Damotclese 0:04d4cc695e56 61 //
Damotclese 0:04d4cc695e56 62 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 63 static void MainInit(void)
Damotclese 0:04d4cc695e56 64 {
Damotclese 1:316582aec4fb 65 // Initialize locally-held data
Damotclese 1:316582aec4fb 66 u32_randomSeeder = 0;
Damotclese 0:04d4cc695e56 67
Damotclese 1:316582aec4fb 68 uint8_t u8_TouchScreenStatus = 0;
Damotclese 1:316582aec4fb 69
Damotclese 0:04d4cc695e56 70 // Bring the LCD up
Damotclese 0:04d4cc695e56 71 st_lcd.Clear(LCD_COLOR_WHITE);
Damotclese 0:04d4cc695e56 72
Damotclese 0:04d4cc695e56 73 // Set the default font size
Damotclese 0:04d4cc695e56 74 BSP_LCD_SetFont(&Font16);
Damotclese 0:04d4cc695e56 75
Damotclese 0:04d4cc695e56 76 // Initialize the touch screen
Damotclese 0:04d4cc695e56 77 u8_TouchScreenStatus = st_touchScreen.Init(st_lcd.GetXSize(), st_lcd.GetYSize());
Damotclese 0:04d4cc695e56 78
Damotclese 0:04d4cc695e56 79 if (TS_OK != u8_TouchScreenStatus)
Damotclese 0:04d4cc695e56 80 {
Damotclese 0:04d4cc695e56 81 st_lcd.DisplayStringAt(1, LINE(ENTERED_KEYS_LINE),
Damotclese 0:04d4cc695e56 82 (uint8_t *)"Touch screen failed", CENTER_MODE);
Damotclese 0:04d4cc695e56 83 }
Damotclese 0:04d4cc695e56 84 }
Damotclese 0:04d4cc695e56 85
Damotclese 0:04d4cc695e56 86 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 87 // MainGrantAccess()
Damotclese 0:04d4cc695e56 88 //
Damotclese 0:04d4cc695e56 89 // This function is invoked to display what access level has been
Damotclese 0:04d4cc695e56 90 // granted.
Damotclese 0:04d4cc695e56 91 //
Damotclese 0:04d4cc695e56 92 // ----------------------------------------------------------------------
Damotclese 1:316582aec4fb 93 void MainGrantAccess(uint8_t u8_thisAccessLevel)
Damotclese 0:04d4cc695e56 94 {
Damotclese 0:04d4cc695e56 95 uint8_t au8_reportString[21] = { 0 };
Damotclese 0:04d4cc695e56 96
Damotclese 0:04d4cc695e56 97 // Clear the display
Damotclese 0:04d4cc695e56 98 st_lcd.Clear(LCD_COLOR_WHITE);
Damotclese 0:04d4cc695e56 99
Damotclese 0:04d4cc695e56 100 // Build a report to offer
Damotclese 0:04d4cc695e56 101 (void)sprintf((char *)au8_reportString, "Level %u", u8_thisAccessLevel);
Damotclese 0:04d4cc695e56 102
Damotclese 0:04d4cc695e56 103 // Display the level of access that was granted
Damotclese 0:04d4cc695e56 104 st_lcd.DisplayStringAt(1, LINE(1), (uint8_t *)"Access granted", CENTER_MODE);
Damotclese 0:04d4cc695e56 105 st_lcd.DisplayStringAt(1, LINE(2), au8_reportString, CENTER_MODE);
Damotclese 0:04d4cc695e56 106 st_lcd.DisplayStringAt(1, LINE(3), (uint8_t *)"Press RESET to exit", CENTER_MODE);
Damotclese 0:04d4cc695e56 107
Damotclese 1:316582aec4fb 108 // Perform the screen animation
Damotclese 1:316582aec4fb 109 AnimationPerformAnimation(u32_randomSeeder);
Damotclese 0:04d4cc695e56 110 }
Damotclese 0:04d4cc695e56 111
Damotclese 0:04d4cc695e56 112 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 113 // MainThread()
Damotclese 0:04d4cc695e56 114 //
Damotclese 0:04d4cc695e56 115 // Called ten times a second.
Damotclese 0:04d4cc695e56 116 //
Damotclese 0:04d4cc695e56 117 // This function will:
Damotclese 0:04d4cc695e56 118 // o Get the state of the touch screen
Damotclese 0:04d4cc695e56 119 // o Check to see if a touch screen touch was detected
Damotclese 0:04d4cc695e56 120 // o Extract the X and Y coordinates of the screen touch
Damotclese 0:04d4cc695e56 121 // o Call a function which will handle the screen touch
Damotclese 0:04d4cc695e56 122 // o Call a function to monitor the push button to drive the
Damotclese 0:04d4cc695e56 123 // Moorse Code access functionality
Damotclese 0:04d4cc695e56 124 //
Damotclese 0:04d4cc695e56 125 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 126 static void MainThread(void)
Damotclese 0:04d4cc695e56 127 {
Damotclese 0:04d4cc695e56 128 uint16_t u16_screenX = 0;
Damotclese 0:04d4cc695e56 129 uint16_t u16_screenY = 0;
Damotclese 0:04d4cc695e56 130 TS_StateTypeDef st_touchScreenState;
Damotclese 0:04d4cc695e56 131
Damotclese 0:04d4cc695e56 132 // Get the status of the Touch Screen interface
Damotclese 0:04d4cc695e56 133 st_touchScreen.GetState(&st_touchScreenState);
Damotclese 0:04d4cc695e56 134
Damotclese 0:04d4cc695e56 135 // Has the screen been touched?
Damotclese 0:04d4cc695e56 136 if (st_touchScreenState.TouchDetected)
Damotclese 0:04d4cc695e56 137 {
Damotclese 0:04d4cc695e56 138 // It has been, extract the X and Y coordinates touched
Damotclese 0:04d4cc695e56 139 u16_screenX = st_touchScreenState.X;
Damotclese 0:04d4cc695e56 140 u16_screenY = st_touchScreenState.Y;
Damotclese 0:04d4cc695e56 141
Damotclese 0:04d4cc695e56 142 // Call the routine which handles the key press
Damotclese 1:316582aec4fb 143 KeypadHandleKeyPress(u16_screenX, u16_screenY);
Damotclese 0:04d4cc695e56 144 }
Damotclese 0:04d4cc695e56 145
Damotclese 0:04d4cc695e56 146 // Drive the Moorse Code access functionality, scanning the
Damotclese 0:04d4cc695e56 147 // push button 10 times a second
Damotclese 1:316582aec4fb 148 MoorseScanPushButton();
Damotclese 0:04d4cc695e56 149
Damotclese 1:316582aec4fb 150 // Keep track of how many times this function has been called
Damotclese 1:316582aec4fb 151 // so that we can attempt to see the random generator
Damotclese 1:316582aec4fb 152 u32_randomSeeder++;
Damotclese 0:04d4cc695e56 153 }
Damotclese 0:04d4cc695e56 154
Damotclese 0:04d4cc695e56 155 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 156 // main()
Damotclese 0:04d4cc695e56 157 //
Damotclese 0:04d4cc695e56 158 // This is the main entry called by thembed operating system.
Damotclese 0:04d4cc695e56 159 //
Damotclese 0:04d4cc695e56 160 // This function will:
Damotclese 0:04d4cc695e56 161 // o Initialize this module
Damotclese 0:04d4cc695e56 162 // o Call the function that established the LCD screen and
Damotclese 0:04d4cc695e56 163 // draws the keypad
Damotclese 0:04d4cc695e56 164 // o Goes in to a forever loop that wakes up 10 times a second
Damotclese 0:04d4cc695e56 165 // o Calls a function which drives the main task which scans the
Damotclese 0:04d4cc695e56 166 // LCD touch screen for screen touches
Damotclese 0:04d4cc695e56 167 //
Damotclese 0:04d4cc695e56 168 // ----------------------------------------------------------------------
Damotclese 0:04d4cc695e56 169 int main(void)
Damotclese 0:04d4cc695e56 170 {
Damotclese 0:04d4cc695e56 171 // Perform local module initialization, if any
Damotclese 0:04d4cc695e56 172 MainInit();
Damotclese 0:04d4cc695e56 173
Damotclese 1:316582aec4fb 174 // Initialize the Keypad module
Damotclese 1:316582aec4fb 175 KeypadInit();
Damotclese 1:316582aec4fb 176
Damotclese 1:316582aec4fb 177 // Initialize the Moorse Code module
Damotclese 1:316582aec4fb 178 MoorseInit();
Damotclese 1:316582aec4fb 179
Damotclese 1:316582aec4fb 180 // Initialize the Animation module
Damotclese 1:316582aec4fb 181 AnimationInit();
Damotclese 1:316582aec4fb 182
Damotclese 0:04d4cc695e56 183 // When we start up we will draw the touch screen keypad
Damotclese 1:316582aec4fb 184 KeypadDrawKeypad();
Damotclese 0:04d4cc695e56 185
Damotclese 0:04d4cc695e56 186 // Enter in to a forever loop which wakes up once a second
Damotclese 0:04d4cc695e56 187 while (true)
Damotclese 0:04d4cc695e56 188 {
Damotclese 0:04d4cc695e56 189 // Sleep for a tenth of a second
Damotclese 0:04d4cc695e56 190 wait(0.1);
Damotclese 0:04d4cc695e56 191
Damotclese 0:04d4cc695e56 192 // Call the main process
Damotclese 0:04d4cc695e56 193 MainThread();
Damotclese 0:04d4cc695e56 194 }
Damotclese 0:04d4cc695e56 195 }
Damotclese 0:04d4cc695e56 196
Damotclese 0:04d4cc695e56 197 // End of file
Damotclese 0:04d4cc695e56 198