Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 SDFileSystem SRF02 TMP102 mbed
Fork of Ranger by
main.h@11:b64d123b9f4f, 2016-05-05 (annotated)
- Committer:
- el15pjt
- Date:
- Thu May 05 10:51:19 2016 +0000
- Revision:
- 11:b64d123b9f4f
- Parent:
- 10:c9f3c22368f1
- Child:
- 12:0171e8723d9d
Final commit.... Maybe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15pjt | 7:14cfb0df30e6 | 1 | /** |
el15pjt | 7:14cfb0df30e6 | 2 | @file main.h |
el15pjt | 7:14cfb0df30e6 | 3 | @brief Header file containing functions prototypes, defines and global variables. |
el15pjt | 7:14cfb0df30e6 | 4 | @brief Ranger Project |
el15pjt | 11:b64d123b9f4f | 5 | @brief Revision 1.3. |
el15pjt | 7:14cfb0df30e6 | 6 | @author Philip Thompson |
el15pjt | 7:14cfb0df30e6 | 7 | @date March 2016 |
el15pjt | 7:14cfb0df30e6 | 8 | @brief The following code has been writen for the University of Leeds ELEC264501 embedded system project and is intended to |
el15pjt | 7:14cfb0df30e6 | 9 | create a programe that can read a distance from an SRF02 sensor and then based aponn the reading disply the distance on the screen |
el15pjt | 7:14cfb0df30e6 | 10 | and increment the LEDs and buzzer according the provision of a temperature sensor is also provied as a secondary function when no |
el15pjt | 7:14cfb0df30e6 | 11 | object is detected with in range. |
el15pjt | 7:14cfb0df30e6 | 12 | */ |
el15pjt | 7:14cfb0df30e6 | 13 | |
el15pjt | 7:14cfb0df30e6 | 14 | #ifndef MAIN_H |
el15pjt | 7:14cfb0df30e6 | 15 | #define MAIN_H |
el15pjt | 7:14cfb0df30e6 | 16 | #include "mbed.h" |
el15pjt | 7:14cfb0df30e6 | 17 | #include "mbed.h" |
el15pjt | 7:14cfb0df30e6 | 18 | #include "SRF02.h" |
el15pjt | 7:14cfb0df30e6 | 19 | #include "N5110.h" |
el15pjt | 7:14cfb0df30e6 | 20 | #include "TMP102.h" |
el15pjt | 7:14cfb0df30e6 | 21 | #include "SDFileSystem.h" |
el15pjt | 7:14cfb0df30e6 | 22 | |
el15pjt | 7:14cfb0df30e6 | 23 | #define LOW 0 /// No output |
el15pjt | 7:14cfb0df30e6 | 24 | #define HIGH 1 /// High output |
el15pjt | 10:c9f3c22368f1 | 25 | |
el15pjt | 10:c9f3c22368f1 | 26 | |
el15pjt | 11:b64d123b9f4f | 27 | /// for PC debug |
el15pjt | 11:b64d123b9f4f | 28 | Serial serial(USBTX, USBRX); |
el15pjt | 7:14cfb0df30e6 | 29 | |
el15pjt | 8:fe6ebe807b9d | 30 | |
el15pjt | 7:14cfb0df30e6 | 31 | /** |
el15pjt | 7:14cfb0df30e6 | 32 | @namespace LEDs |
el15pjt | 7:14cfb0df30e6 | 33 | @brief Output for Alert LEDs |
el15pjt | 7:14cfb0df30e6 | 34 | */ |
el15pjt | 7:14cfb0df30e6 | 35 | DigitalOut rr_led (PTA1); |
el15pjt | 7:14cfb0df30e6 | 36 | DigitalOut a_led (PTC2); |
el15pjt | 7:14cfb0df30e6 | 37 | DigitalOut gg_led(PTB23); |
el15pjt | 7:14cfb0df30e6 | 38 | |
el15pjt | 7:14cfb0df30e6 | 39 | /** |
el15pjt | 7:14cfb0df30e6 | 40 | @namespace BOARDLEDs |
el15pjt | 7:14cfb0df30e6 | 41 | @brief On board LEDs |
el15pjt | 7:14cfb0df30e6 | 42 | */ |
el15pjt | 7:14cfb0df30e6 | 43 | DigitalOut r_led(LED_RED); |
el15pjt | 7:14cfb0df30e6 | 44 | DigitalOut g_led(LED_GREEN); |
el15pjt | 7:14cfb0df30e6 | 45 | DigitalOut b_led(LED_BLUE); |
el15pjt | 7:14cfb0df30e6 | 46 | |
el15pjt | 7:14cfb0df30e6 | 47 | /** |
el15pjt | 7:14cfb0df30e6 | 48 | @namespace Buzzer |
el15pjt | 7:14cfb0df30e6 | 49 | @brief PWM output for Buzzer |
el15pjt | 7:14cfb0df30e6 | 50 | */ |
el15pjt | 7:14cfb0df30e6 | 51 | PwmOut buzzer(PTA2); |
el15pjt | 7:14cfb0df30e6 | 52 | |
el15pjt | 7:14cfb0df30e6 | 53 | /** |
el15pjt | 7:14cfb0df30e6 | 54 | @namespace Buttons |
el15pjt | 7:14cfb0df30e6 | 55 | @brief Button triggered Interrupts |
el15pjt | 7:14cfb0df30e6 | 56 | */ |
el15pjt | 7:14cfb0df30e6 | 57 | InterruptIn sw1(PTB19); |
el15pjt | 7:14cfb0df30e6 | 58 | InterruptIn sw2(PTB18); |
el15pjt | 7:14cfb0df30e6 | 59 | |
el15pjt | 7:14cfb0df30e6 | 60 | /** |
el15pjt | 7:14cfb0df30e6 | 61 | @namespace Timers |
el15pjt | 8:fe6ebe807b9d | 62 | @brief Tickers and Timeouts |
el15pjt | 7:14cfb0df30e6 | 63 | */ |
el15pjt | 11:b64d123b9f4f | 64 | Ticker ticker; // Ticker to control LED flash |
el15pjt | 11:b64d123b9f4f | 65 | Ticker ticker_srf02; //Ticker to get distance reading |
el15pjt | 11:b64d123b9f4f | 66 | Ticker ticker_standby; //Ticker to control standby |
el15pjt | 11:b64d123b9f4f | 67 | Timeout buzzoff; //Buzzer off duratuion |
el15pjt | 11:b64d123b9f4f | 68 | Timeout buzzon; // buzzer on duration |
el15pjt | 7:14cfb0df30e6 | 69 | |
el15pjt | 7:14cfb0df30e6 | 70 | // Create TMP102 object |
el15pjt | 7:14cfb0df30e6 | 71 | TMP102 tmp102(I2C_SDA,I2C_SCL); |
el15pjt | 7:14cfb0df30e6 | 72 | |
el15pjt | 7:14cfb0df30e6 | 73 | /** |
el15pjt | 7:14cfb0df30e6 | 74 | @namespace Ranger |
el15pjt | 7:14cfb0df30e6 | 75 | @brief Creat the Ranger object |
el15pjt | 7:14cfb0df30e6 | 76 | */ |
el15pjt | 7:14cfb0df30e6 | 77 | SRF02 srf02(I2C_SDA,I2C_SCL); |
el15pjt | 7:14cfb0df30e6 | 78 | |
el15pjt | 7:14cfb0df30e6 | 79 | /** |
el15pjt | 7:14cfb0df30e6 | 80 | @namespace LCD |
el15pjt | 7:14cfb0df30e6 | 81 | @brief Creats the LCD object |
el15pjt | 7:14cfb0df30e6 | 82 | */ |
el15pjt | 7:14cfb0df30e6 | 83 | N5110 lcd(PTE26,PTA0,PTC4,PTD0,PTD2,PTD1,PTC3); |
el15pjt | 7:14cfb0df30e6 | 84 | |
el15pjt | 7:14cfb0df30e6 | 85 | /// Connections to SD card holder on K64F (SPI interface) |
el15pjt | 7:14cfb0df30e6 | 86 | SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS |
el15pjt | 8:fe6ebe807b9d | 87 | FILE *fp; |
el15pjt | 11:b64d123b9f4f | 88 | |
el15pjt | 11:b64d123b9f4f | 89 | //FLAGS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
el15pjt | 11:b64d123b9f4f | 90 | |
el15pjt | 7:14cfb0df30e6 | 91 | /** |
el15pjt | 7:14cfb0df30e6 | 92 | @namespace TimerFlags |
el15pjt | 7:14cfb0df30e6 | 93 | @brief Flags for use with timed interupts |
el15pjt | 7:14cfb0df30e6 | 94 | */ |
el15pjt | 9:bc259fc22fa2 | 95 | volatile int g_timer_flag_led = 0, g_timer_flag_srf02 = 0; /** Flag rised by interupts*/ |
el15pjt | 7:14cfb0df30e6 | 96 | volatile int g_timer_flag_standby = 0; |
el15pjt | 8:fe6ebe807b9d | 97 | volatile int buzz_flag = 0; |
el15pjt | 7:14cfb0df30e6 | 98 | /** |
el15pjt | 7:14cfb0df30e6 | 99 | @namespace ButtonFlages |
el15pjt | 7:14cfb0df30e6 | 100 | @brief Flags for use with button interupts |
el15pjt | 7:14cfb0df30e6 | 101 | */ |
el15pjt | 7:14cfb0df30e6 | 102 | volatile int g_sw1_flag = 0, g_sw2_flag = 0; |
el15pjt | 7:14cfb0df30e6 | 103 | |
el15pjt | 11:b64d123b9f4f | 104 | |
el15pjt | 11:b64d123b9f4f | 105 | |
el15pjt | 11:b64d123b9f4f | 106 | //VERIABLES\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
el15pjt | 11:b64d123b9f4f | 107 | /// Upper limit of alert 1 |
el15pjt | 11:b64d123b9f4f | 108 | int r1 = 03; |
el15pjt | 11:b64d123b9f4f | 109 | /// Upper limit of alert 2 |
el15pjt | 11:b64d123b9f4f | 110 | int r2 = 10; |
el15pjt | 11:b64d123b9f4f | 111 | /// Upper limit of alert 3 |
el15pjt | 11:b64d123b9f4f | 112 | int r3 = 20; |
el15pjt | 11:b64d123b9f4f | 113 | /// Upper limit of alert 4 |
el15pjt | 11:b64d123b9f4f | 114 | int r4 = 30; |
el15pjt | 11:b64d123b9f4f | 115 | /// Upper limit of alert 5 |
el15pjt | 11:b64d123b9f4f | 116 | int r5 = 40; |
el15pjt | 11:b64d123b9f4f | 117 | /// Upper limit of alert 6 |
el15pjt | 11:b64d123b9f4f | 118 | int r6 = 50; |
el15pjt | 11:b64d123b9f4f | 119 | /// Upper limit of alert 7 |
el15pjt | 11:b64d123b9f4f | 120 | int r7 = 70; |
el15pjt | 11:b64d123b9f4f | 121 | /// Veriable to hold sumation of distance readings for mean vale calculation |
el15pjt | 9:bc259fc22fa2 | 122 | int totaldistance; |
el15pjt | 11:b64d123b9f4f | 123 | ///< veriable to hold the page being viewed with in the submenu |
el15pjt | 11:b64d123b9f4f | 124 | int subpage; |
el15pjt | 11:b64d123b9f4f | 125 | /// veriable to hold the page being viewed with in the menu |
el15pjt | 11:b64d123b9f4f | 126 | int page; |
el15pjt | 11:b64d123b9f4f | 127 | /// veriable to hold the offset and adjust the 0 Range point |
el15pjt | 11:b64d123b9f4f | 128 | int offset = 0; |
el15pjt | 11:b64d123b9f4f | 129 | /// veriable to hold the current alert level |
el15pjt | 11:b64d123b9f4f | 130 | int alert; |
el15pjt | 11:b64d123b9f4f | 131 | /// veriable to hold the distance read from the srf02 sensor |
el15pjt | 11:b64d123b9f4f | 132 | int distance; |
el15pjt | 11:b64d123b9f4f | 133 | /// veriable to hold the current unit type set to 1 = METRIC as default |
el15pjt | 11:b64d123b9f4f | 134 | int units = 1; |
el15pjt | 11:b64d123b9f4f | 135 | ///standby state 1. path clear 2. Temp 3.Temp no backlight |
el15pjt | 11:b64d123b9f4f | 136 | int standby = 0; |
el15pjt | 11:b64d123b9f4f | 137 | ///flag raised is there is a collision |
el15pjt | 11:b64d123b9f4f | 138 | int check_flag = 0; |
el15pjt | 11:b64d123b9f4f | 139 | /// Temp reading return from TMP120 sensor |
el15pjt | 11:b64d123b9f4f | 140 | float Traw; |
el15pjt | 11:b64d123b9f4f | 141 | /// veriable to hold the current LED backlight of the 5110 LCD |
el15pjt | 11:b64d123b9f4f | 142 | float bright = 1.0; |
el15pjt | 11:b64d123b9f4f | 143 | /// Temperature value retured from TMP102 sensor |
el15pjt | 11:b64d123b9f4f | 144 | float T; |
el15pjt | 11:b64d123b9f4f | 145 | /// Veriable to hold the distance across the screen the distance bar should go |
el15pjt | 9:bc259fc22fa2 | 146 | float distbar; |
el15pjt | 11:b64d123b9f4f | 147 | /// Averaged Distance vale from ten previous readings |
el15pjt | 11:b64d123b9f4f | 148 | float avgdistance =0; |
el15pjt | 11:b64d123b9f4f | 149 | /// convertion factor from Cm to inch 1 = metric no convertion |
el15pjt | 11:b64d123b9f4f | 150 | float c =1; |
el15pjt | 11:b64d123b9f4f | 151 | // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) not needed to be globle but reused frquently throuhout |
el15pjt | 11:b64d123b9f4f | 152 | char buffer[14], buffer1[14], buffer2[14], buffer3[14], buffer4[14],buffer5[14]; |
el15pjt | 11:b64d123b9f4f | 153 | |
el15pjt | 11:b64d123b9f4f | 154 | |
el15pjt | 11:b64d123b9f4f | 155 | /*!< Stucture to hold all outputs. Steady LEDs, Flashing LEDs, Tone on, Tonne off*/ |
el15pjt | 7:14cfb0df30e6 | 156 | struct Alertlevel { |
el15pjt | 7:14cfb0df30e6 | 157 | char srr_led; /// stead RED LED state |
el15pjt | 7:14cfb0df30e6 | 158 | char sa_led; /// stead AMBER LED state |
el15pjt | 7:14cfb0df30e6 | 159 | char sgg_led; /// stead GREEN LED state |
el15pjt | 7:14cfb0df30e6 | 160 | char frr_led;///FLASHING RED LED state |
el15pjt | 7:14cfb0df30e6 | 161 | char fa_led; ///FLASHING AMBER LED state |
el15pjt | 7:14cfb0df30e6 | 162 | char fgg_led; ///FLASHING GREEN LED state |
el15pjt | 11:b64d123b9f4f | 163 | float toneon; ///Tone on time |
el15pjt | 11:b64d123b9f4f | 164 | float toneoff; ///Tone off time |
el15pjt | 11:b64d123b9f4f | 165 | }; |
el15pjt | 7:14cfb0df30e6 | 166 | typedef const struct Alertlevel STyp; |
el15pjt | 7:14cfb0df30e6 | 167 | |
el15pjt | 11:b64d123b9f4f | 168 | /*!< Array contaning structures for diffent outputs */ |
el15pjt | 7:14cfb0df30e6 | 169 | STyp Alertlevel[8] = { |
el15pjt | 7:14cfb0df30e6 | 170 | {LOW,LOW,LOW,LOW,LOW,LOW,0,1}, // no output |
el15pjt | 10:c9f3c22368f1 | 171 | {LOW,LOW,LOW,LOW,LOW,HIGH,0.1,1.0}, //flash green |
el15pjt | 8:fe6ebe807b9d | 172 | {LOW,LOW,HIGH,LOW,LOW,LOW,0.1,0.5}, //steady green |
el15pjt | 10:c9f3c22368f1 | 173 | {LOW,LOW,HIGH,LOW,HIGH,LOW,0.1,0.25}, //flash amber |
el15pjt | 10:c9f3c22368f1 | 174 | {LOW,HIGH,HIGH,LOW,LOW,LOW,0.1,0.1}, //steady amber |
el15pjt | 8:fe6ebe807b9d | 175 | {LOW,HIGH,HIGH,HIGH,LOW,LOW,0.2,0.1}, //flash red |
el15pjt | 10:c9f3c22368f1 | 176 | {HIGH,HIGH,HIGH,LOW,LOW,LOW,0.1,0.05},// steady red |
el15pjt | 8:fe6ebe807b9d | 177 | {LOW,LOW,LOW,HIGH,HIGH,HIGH,1,0} // all flash |
el15pjt | 7:14cfb0df30e6 | 178 | };/*!< Array contaning structures for diffent outputs */ |
el15pjt | 7:14cfb0df30e6 | 179 | |
el15pjt | 11:b64d123b9f4f | 180 | |
el15pjt | 7:14cfb0df30e6 | 181 | |
el15pjt | 8:fe6ebe807b9d | 182 | |
el15pjt | 11:b64d123b9f4f | 183 | //FUNCTIONS///////////////////////////////////////////// |
el15pjt | 11:b64d123b9f4f | 184 | |
el15pjt | 11:b64d123b9f4f | 185 | /** |
el15pjt | 11:b64d123b9f4f | 186 | Function called to stop buzzer at end of on period and then make buzzer avilable again after off period |
el15pjt | 11:b64d123b9f4f | 187 | @param buzz_flag 1 or 0 |
el15pjt | 11:b64d123b9f4f | 188 | @param buzzer = 0.0 buzzer off |
el15pjt | 11:b64d123b9f4f | 189 | @code |
el15pjt | 11:b64d123b9f4f | 190 | { |
el15pjt | 11:b64d123b9f4f | 191 | buzz_flag = 1; |
el15pjt | 11:b64d123b9f4f | 192 | buzzer = 0.0; |
el15pjt | 11:b64d123b9f4f | 193 | buzzon.attach(&buzzflag,Alertlevel[alert].toneoff); |
el15pjt | 11:b64d123b9f4f | 194 | } |
el15pjt | 11:b64d123b9f4f | 195 | @endcode |
el15pjt | 11:b64d123b9f4f | 196 | */ |
el15pjt | 11:b64d123b9f4f | 197 | void flip(); |
el15pjt | 11:b64d123b9f4f | 198 | |
el15pjt | 11:b64d123b9f4f | 199 | /** Flag used it indicate if buzzer is avilable or on a off period |
el15pjt | 11:b64d123b9f4f | 200 | @param buzz_flag zero |
el15pjt | 11:b64d123b9f4f | 201 | @code |
el15pjt | 11:b64d123b9f4f | 202 | { |
el15pjt | 11:b64d123b9f4f | 203 | buzz_flag = 0; |
el15pjt | 11:b64d123b9f4f | 204 | return; |
el15pjt | 11:b64d123b9f4f | 205 | } |
el15pjt | 11:b64d123b9f4f | 206 | @endcode |
el15pjt | 11:b64d123b9f4f | 207 | */ |
el15pjt | 11:b64d123b9f4f | 208 | void buzzflag(); |
el15pjt | 11:b64d123b9f4f | 209 | |
el15pjt | 11:b64d123b9f4f | 210 | /** Controls the LCD while not in a Menu |
el15pjt | 11:b64d123b9f4f | 211 | |
el15pjt | 11:b64d123b9f4f | 212 | @param i used to scale the max distaance to the width of the screen |
el15pjt | 11:b64d123b9f4f | 213 | @param distance Distance read from sensor to be dispayed |
el15pjt | 11:b64d123b9f4f | 214 | @param distbar used to adjust how far along the screen the bar is to go acorrding to distance |
el15pjt | 11:b64d123b9f4f | 215 | |
el15pjt | 8:fe6ebe807b9d | 216 | @code |
el15pjt | 8:fe6ebe807b9d | 217 | if (alert == 0) { |
el15pjt | 8:fe6ebe807b9d | 218 | if (g_timer_flag_standby) { |
el15pjt | 8:fe6ebe807b9d | 219 | g_timer_flag_standby = 0; |
el15pjt | 8:fe6ebe807b9d | 220 | T = tmp102.get_temperature(); |
el15pjt | 8:fe6ebe807b9d | 221 | standby++; |
el15pjt | 8:fe6ebe807b9d | 222 | if (standby >3) { |
el15pjt | 8:fe6ebe807b9d | 223 | standby = 3; |
el15pjt | 8:fe6ebe807b9d | 224 | } |
el15pjt | 8:fe6ebe807b9d | 225 | } |
el15pjt | 8:fe6ebe807b9d | 226 | |
el15pjt | 8:fe6ebe807b9d | 227 | switch (standby) { |
el15pjt | 8:fe6ebe807b9d | 228 | case 1: |
el15pjt | 8:fe6ebe807b9d | 229 | if (check_flag == 1) { |
el15pjt | 8:fe6ebe807b9d | 230 | sprintf(buffer4,"COLLISIONCHECK"); |
el15pjt | 8:fe6ebe807b9d | 231 | } |
el15pjt | 8:fe6ebe807b9d | 232 | lcd.clear(); |
el15pjt | 8:fe6ebe807b9d | 233 | sprintf(buffer,"**PATH CLEAR**"); |
el15pjt | 8:fe6ebe807b9d | 234 | lcd.printString(buffer,0,0); |
el15pjt | 8:fe6ebe807b9d | 235 | lcd.printString(buffer4,0,5); |
el15pjt | 8:fe6ebe807b9d | 236 | lcd.refresh(); |
el15pjt | 8:fe6ebe807b9d | 237 | break; |
el15pjt | 8:fe6ebe807b9d | 238 | case 2: |
el15pjt | 8:fe6ebe807b9d | 239 | if (check_flag == 1) { |
el15pjt | 8:fe6ebe807b9d | 240 | sprintf(buffer4,"COLLISIONCHECK"); |
el15pjt | 8:fe6ebe807b9d | 241 | lcd.clear(); |
el15pjt | 8:fe6ebe807b9d | 242 | sprintf(buffer3,"TEMP = %.2f",T); |
el15pjt | 8:fe6ebe807b9d | 243 | sprintf(buffer2,"TEMPERATER"); |
el15pjt | 8:fe6ebe807b9d | 244 | lcd.printString(buffer3,4,2); |
el15pjt | 8:fe6ebe807b9d | 245 | lcd.printString(buffer2,12,1); |
el15pjt | 8:fe6ebe807b9d | 246 | lcd.printString(buffer4,0,5); |
el15pjt | 8:fe6ebe807b9d | 247 | |
el15pjt | 8:fe6ebe807b9d | 248 | break; |
el15pjt | 8:fe6ebe807b9d | 249 | case 3: |
el15pjt | 8:fe6ebe807b9d | 250 | if (check_flag == 1) { |
el15pjt | 8:fe6ebe807b9d | 251 | sprintf(buffer4,"COLLISIONCHECK"); |
el15pjt | 8:fe6ebe807b9d | 252 | lcd.clear(); |
el15pjt | 8:fe6ebe807b9d | 253 | sprintf(buffer3,"TEMP = %.2f",T); |
el15pjt | 8:fe6ebe807b9d | 254 | sprintf(buffer2,"TEMPERATER"); |
el15pjt | 8:fe6ebe807b9d | 255 | lcd.refresh(); |
el15pjt | 8:fe6ebe807b9d | 256 | lcd.printString(buffer3,4,2); |
el15pjt | 8:fe6ebe807b9d | 257 | lcd.printString(buffer2,12,1); |
el15pjt | 8:fe6ebe807b9d | 258 | lcd.printString(buffer4,0,5); |
el15pjt | 8:fe6ebe807b9d | 259 | lcd.setBrightness(0); |
el15pjt | 8:fe6ebe807b9d | 260 | break; |
el15pjt | 8:fe6ebe807b9d | 261 | } |
el15pjt | 8:fe6ebe807b9d | 262 | } |
el15pjt | 8:fe6ebe807b9d | 263 | |
el15pjt | 8:fe6ebe807b9d | 264 | //If alert isn't 0 then the distance is to be dispayed alonng with the the distance bar |
el15pjt | 8:fe6ebe807b9d | 265 | else { |
el15pjt | 8:fe6ebe807b9d | 266 | lcd.setBrightness(bright); |
el15pjt | 8:fe6ebe807b9d | 267 | standby =0; |
el15pjt | 8:fe6ebe807b9d | 268 | lcd.clear(); |
el15pjt | 8:fe6ebe807b9d | 269 | |
el15pjt | 9:bc259fc22fa2 | 270 | if (units == 1) { |
el15pjt | 8:fe6ebe807b9d | 271 | sprintf(buffer,"%0.2f Cm",avgdistance); |
el15pjt | 8:fe6ebe807b9d | 272 | sprintf(buffer1,"****RANGE!****"); |
el15pjt | 8:fe6ebe807b9d | 273 | sprintf(buffer2,"DISTANCE"); |
el15pjt | 8:fe6ebe807b9d | 274 | |
el15pjt | 8:fe6ebe807b9d | 275 | sprintf(buffer4,"Menu"); |
el15pjt | 8:fe6ebe807b9d | 276 | |
el15pjt | 8:fe6ebe807b9d | 277 | } else { |
el15pjt | 8:fe6ebe807b9d | 278 | sprintf(buffer,"%0.2f Inches",avgdistance); |
el15pjt | 8:fe6ebe807b9d | 279 | sprintf(buffer1,"****RANGE!****"); |
el15pjt | 8:fe6ebe807b9d | 280 | sprintf(buffer2,"***DISTANCE***"); |
el15pjt | 8:fe6ebe807b9d | 281 | sprintf(buffer4,"Menu"); |
el15pjt | 8:fe6ebe807b9d | 282 | } |
el15pjt | 8:fe6ebe807b9d | 283 | lcd.printString(buffer,25,2); |
el15pjt | 8:fe6ebe807b9d | 284 | lcd.printString(buffer1,0,0); |
el15pjt | 8:fe6ebe807b9d | 285 | lcd.printString(buffer2,16,1); |
el15pjt | 8:fe6ebe807b9d | 286 | lcd.printString(buffer4,0,5); |
el15pjt | 8:fe6ebe807b9d | 287 | |
el15pjt | 8:fe6ebe807b9d | 288 | |
el15pjt | 8:fe6ebe807b9d | 289 | float h = (r7/84); |
el15pjt | 8:fe6ebe807b9d | 290 | float distbar = (avgdistance*h); |
el15pjt | 8:fe6ebe807b9d | 291 | //drawRect(int x0,int y0,int width,int height,int fill); |
el15pjt | 8:fe6ebe807b9d | 292 | lcd.drawRect(0,29,distbar,7,1); // |
el15pjt | 8:fe6ebe807b9d | 293 | lcd.refresh(); |
el15pjt | 8:fe6ebe807b9d | 294 | @endcode |
el15pjt | 8:fe6ebe807b9d | 295 | */ |
el15pjt | 7:14cfb0df30e6 | 296 | void lcdoutput(); |
el15pjt | 8:fe6ebe807b9d | 297 | |
el15pjt | 7:14cfb0df30e6 | 298 | /** Called to increment to brightness by 0.2 each time when at 1 resets back to 0.0 |
el15pjt | 7:14cfb0df30e6 | 299 | @param bright 0.0-1 |
el15pjt | 7:14cfb0df30e6 | 300 | @returns lcd.setbrightness |
el15pjt | 7:14cfb0df30e6 | 301 | @code |
el15pjt | 7:14cfb0df30e6 | 302 | if (bright == 1.0) { |
el15pjt | 7:14cfb0df30e6 | 303 | bright = 0; |
el15pjt | 7:14cfb0df30e6 | 304 | } else { |
el15pjt | 7:14cfb0df30e6 | 305 | bright += 0.2; |
el15pjt | 7:14cfb0df30e6 | 306 | } |
el15pjt | 7:14cfb0df30e6 | 307 | lcd.setBrightness(bright); |
el15pjt | 7:14cfb0df30e6 | 308 | @endcode |
el15pjt | 7:14cfb0df30e6 | 309 | */ |
el15pjt | 7:14cfb0df30e6 | 310 | void backlight(); |
el15pjt | 11:b64d123b9f4f | 311 | |
el15pjt | 11:b64d123b9f4f | 312 | /** |
el15pjt | 11:b64d123b9f4f | 313 | Sets up and initalizies switches, LEDs, Tickers and serial connection |
el15pjt | 11:b64d123b9f4f | 314 | @code |
el15pjt | 11:b64d123b9f4f | 315 | { |
el15pjt | 11:b64d123b9f4f | 316 | serial.baud(115200); // full-speed! |
el15pjt | 11:b64d123b9f4f | 317 | ticker.attach(&timer_isr_led,0.35); /// Attach the ticker for the flashig LEDs |
el15pjt | 11:b64d123b9f4f | 318 | ticker_srf02.attach(&timer_isr_srf02,0.2);/// Attach the ticker for collecting a range reading |
el15pjt | 11:b64d123b9f4f | 319 | ticker_standby.attach(&timer_isr_standby,5.0); |
el15pjt | 11:b64d123b9f4f | 320 | sw1.rise(&sw1_isr); /// sw1_isr called when button presed on the rising edge |
el15pjt | 11:b64d123b9f4f | 321 | sw2.rise(&sw2_isr); /// sw2_isr called when button presed on the rising edge |
el15pjt | 11:b64d123b9f4f | 322 | r_led = 1; //Onboard leds |
el15pjt | 11:b64d123b9f4f | 323 | b_led = 1; //Onboard leds |
el15pjt | 11:b64d123b9f4f | 324 | g_led = 1; //Onboard leds |
el15pjt | 11:b64d123b9f4f | 325 | rr_led = 0; //PCB LEDS |
el15pjt | 11:b64d123b9f4f | 326 | a_led = 0; //PCB LEDS |
el15pjt | 11:b64d123b9f4f | 327 | gg_led = 0; //PCB LEDS |
el15pjt | 11:b64d123b9f4f | 328 | sw2.mode(PullDown); //Turns on use of the pulldown resistors for use with the PCB buttons |
el15pjt | 11:b64d123b9f4f | 329 | sw1.mode(PullDown); //Turns on use of the pulldown resistors for use with the PCB buttons |
el15pjt | 11:b64d123b9f4f | 330 | } |
el15pjt | 11:b64d123b9f4f | 331 | @endcode |
el15pjt | 11:b64d123b9f4f | 332 | */ |
el15pjt | 7:14cfb0df30e6 | 333 | void setup(); |
el15pjt | 7:14cfb0df30e6 | 334 | |
el15pjt | 7:14cfb0df30e6 | 335 | /** A fuction used to determin the alert level given a range with the use of IF statments |
el15pjt | 7:14cfb0df30e6 | 336 | @param distance The distance read from sensor |
el15pjt | 7:14cfb0df30e6 | 337 | @param alert The level that distance falls with in 0 -7 |
el15pjt | 7:14cfb0df30e6 | 338 | @returns alert |
el15pjt | 7:14cfb0df30e6 | 339 | @code |
el15pjt | 7:14cfb0df30e6 | 340 | if (distance >= r6 && distance < r7) { // r6 150 and r7 200 |
el15pjt | 7:14cfb0df30e6 | 341 | alert = 1; /// alert 1 distance between preset 150Cm to 200Cm |
el15pjt | 7:14cfb0df30e6 | 342 | } else if (distance >= r5 && distance < r6) { |
el15pjt | 7:14cfb0df30e6 | 343 | alert = 2; /// alert 2 when between preset 90Cm to 150Cm |
el15pjt | 7:14cfb0df30e6 | 344 | } else if (distance >= r4 && distance < r5) { |
el15pjt | 7:14cfb0df30e6 | 345 | alert = 3; /// alert 3 when distance between 60Cm to 90Cm |
el15pjt | 7:14cfb0df30e6 | 346 | } else if (distance >= r3 && distance < r4) { |
el15pjt | 7:14cfb0df30e6 | 347 | alert = 4; /// alert 4 when distance between 40Cm and 60Cm |
el15pjt | 7:14cfb0df30e6 | 348 | } else if ( distance > r2 && distance < r3) { |
el15pjt | 7:14cfb0df30e6 | 349 | alert = 5; ///alert 5 when distance between 20Cm and 40m |
el15pjt | 7:14cfb0df30e6 | 350 | } else if (distance > r1 && distance <= r2) { //r1 3 and r2 20 |
el15pjt | 7:14cfb0df30e6 | 351 | alert = 6; ///alert 6 when distance between 1 and 20 |
el15pjt | 7:14cfb0df30e6 | 352 | } else if (distance <=r1) { |
el15pjt | 7:14cfb0df30e6 | 353 | alert = 7; ///alert 7 when distance below 1Cm |
el15pjt | 7:14cfb0df30e6 | 354 | } else { |
el15pjt | 7:14cfb0df30e6 | 355 | alert = 0; /// alert 0 all else |
el15pjt | 7:14cfb0df30e6 | 356 | } |
el15pjt | 7:14cfb0df30e6 | 357 | } |
el15pjt | 7:14cfb0df30e6 | 358 | @endcode |
el15pjt | 7:14cfb0df30e6 | 359 | */ |
el15pjt | 7:14cfb0df30e6 | 360 | void setalert(); |
el15pjt | 7:14cfb0df30e6 | 361 | |
el15pjt | 11:b64d123b9f4f | 362 | /** Function for controlling the LED outputs |
el15pjt | 11:b64d123b9f4f | 363 | @para alert changes to element array and so output controlls |
el15pjt | 7:14cfb0df30e6 | 364 | @code |
el15pjt | 11:b64d123b9f4f | 365 | { |
el15pjt | 11:b64d123b9f4f | 366 | int flash = 0; ///Variable to toggle LEDs high low |
el15pjt | 11:b64d123b9f4f | 367 | if (g_timer_flag_led) { |
el15pjt | 11:b64d123b9f4f | 368 | g_timer_flag_led = 0; |
el15pjt | 11:b64d123b9f4f | 369 | flash = !flash; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 370 | } |
el15pjt | 11:b64d123b9f4f | 371 | if(Alertlevel[alert].fa_led == HIGH) { |
el15pjt | 11:b64d123b9f4f | 372 | a_led = flash; |
el15pjt | 11:b64d123b9f4f | 373 | } else { |
el15pjt | 11:b64d123b9f4f | 374 | a_led = Alertlevel[alert].sa_led; |
el15pjt | 11:b64d123b9f4f | 375 | } |
el15pjt | 11:b64d123b9f4f | 376 | if (Alertlevel[alert].frr_led == HIGH) { |
el15pjt | 11:b64d123b9f4f | 377 | rr_led = flash; |
el15pjt | 11:b64d123b9f4f | 378 | } else { |
el15pjt | 11:b64d123b9f4f | 379 | rr_led = Alertlevel[alert].srr_led; |
el15pjt | 11:b64d123b9f4f | 380 | } |
el15pjt | 11:b64d123b9f4f | 381 | if(Alertlevel[alert].fgg_led == HIGH) { |
el15pjt | 11:b64d123b9f4f | 382 | gg_led = flash; |
el15pjt | 11:b64d123b9f4f | 383 | } else { |
el15pjt | 11:b64d123b9f4f | 384 | gg_led = Alertlevel[alert].sgg_led; |
el15pjt | 11:b64d123b9f4f | 385 | } |
el15pjt | 11:b64d123b9f4f | 386 | } |
el15pjt | 11:b64d123b9f4f | 387 | @endcode |
el15pjt | 11:b64d123b9f4f | 388 | */ |
el15pjt | 11:b64d123b9f4f | 389 | void setleds(); |
el15pjt | 7:14cfb0df30e6 | 390 | |
el15pjt | 11:b64d123b9f4f | 391 | /** |
el15pjt | 11:b64d123b9f4f | 392 | @code |
el15pjt | 11:b64d123b9f4f | 393 | { |
el15pjt | 11:b64d123b9f4f | 394 | |
el15pjt | 11:b64d123b9f4f | 395 | control the PWM to drive the buzzer |
el15pjt | 11:b64d123b9f4f | 396 | @param buzzer.period frequncy 1KHz |
el15pjt | 11:b64d123b9f4f | 397 | @param buzzer duty cycle equal on/off max volume |
el15pjt | 11:b64d123b9f4f | 398 | @param Alertlevel[alert].toneon controls how long the tone will last depending on alert |
el15pjt | 11:b64d123b9f4f | 399 | */ |
el15pjt | 11:b64d123b9f4f | 400 | buzzer.period (1.0/1000.0); |
el15pjt | 11:b64d123b9f4f | 401 | buzzer = 0.5; |
el15pjt | 11:b64d123b9f4f | 402 | buzzoff.attach(&flip, Alertlevel[alert].toneon); |
el15pjt | 7:14cfb0df30e6 | 403 | } |
el15pjt | 11:b64d123b9f4f | 404 | @endcode |
el15pjt | 11:b64d123b9f4f | 405 | */ |
el15pjt | 7:14cfb0df30e6 | 406 | void setbuzzer(); |
el15pjt | 7:14cfb0df30e6 | 407 | |
el15pjt | 7:14cfb0df30e6 | 408 | |
el15pjt | 11:b64d123b9f4f | 409 | /** |
el15pjt | 11:b64d123b9f4f | 410 | Function used to call and navigate Main menu and change settings |
el15pjt | 11:b64d123b9f4f | 411 | @code |
el15pjt | 11:b64d123b9f4f | 412 | { |
el15pjt | 11:b64d123b9f4f | 413 | while(1) { |
el15pjt | 7:14cfb0df30e6 | 414 | if (g_sw1_flag) { |
el15pjt | 7:14cfb0df30e6 | 415 | g_sw1_flag = 0; |
el15pjt | 11:b64d123b9f4f | 416 | page++; // Moves page |
el15pjt | 7:14cfb0df30e6 | 417 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 418 | } |
el15pjt | 7:14cfb0df30e6 | 419 | switch (page) { |
el15pjt | 7:14cfb0df30e6 | 420 | case 0: |
el15pjt | 7:14cfb0df30e6 | 421 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 422 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 423 | backlight(); |
el15pjt | 7:14cfb0df30e6 | 424 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 425 | } |
el15pjt | 11:b64d123b9f4f | 426 | int lightbar = bright*84; |
el15pjt | 11:b64d123b9f4f | 427 | sprintf(buffer2,"%.0f%%",bright*100); |
el15pjt | 11:b64d123b9f4f | 428 | lcd.drawRect(0,26,lightbar,7,1); // move bar up!!!!!!!!!!!!!!!! |
el15pjt | 11:b64d123b9f4f | 429 | lcd.printString("BACKLIGHT",0,1); |
el15pjt | 11:b64d123b9f4f | 430 | lcd.printString(buffer2,0,2); |
el15pjt | 11:b64d123b9f4f | 431 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 432 | lcd.refresh(); |
el15pjt | 7:14cfb0df30e6 | 433 | break; |
el15pjt | 7:14cfb0df30e6 | 434 | case 1: |
el15pjt | 7:14cfb0df30e6 | 435 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 436 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 437 | if (offset == 20) { |
el15pjt | 7:14cfb0df30e6 | 438 | offset = 0; |
el15pjt | 11:b64d123b9f4f | 439 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 440 | } else { |
el15pjt | 7:14cfb0df30e6 | 441 | offset += 1; |
el15pjt | 7:14cfb0df30e6 | 442 | } |
el15pjt | 7:14cfb0df30e6 | 443 | } |
el15pjt | 11:b64d123b9f4f | 444 | sprintf(buffer2,"%i",offset); |
el15pjt | 11:b64d123b9f4f | 445 | lcd.printString("OFFSET",0,1); |
el15pjt | 11:b64d123b9f4f | 446 | sprintf(buffer4,"NEXT ADJ"); |
el15pjt | 11:b64d123b9f4f | 447 | lcd.printString(buffer4,0,5); |
el15pjt | 7:14cfb0df30e6 | 448 | break; |
el15pjt | 7:14cfb0df30e6 | 449 | case 2: |
el15pjt | 7:14cfb0df30e6 | 450 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 451 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 9:bc259fc22fa2 | 452 | if (units == 1) { |
el15pjt | 9:bc259fc22fa2 | 453 | units = 0; |
el15pjt | 11:b64d123b9f4f | 454 | c = 0.3937; |
el15pjt | 7:14cfb0df30e6 | 455 | } else { |
el15pjt | 9:bc259fc22fa2 | 456 | units = 1; |
el15pjt | 11:b64d123b9f4f | 457 | c = 1; |
el15pjt | 11:b64d123b9f4f | 458 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 459 | } |
el15pjt | 7:14cfb0df30e6 | 460 | } |
el15pjt | 11:b64d123b9f4f | 461 | if (units == 0) { |
el15pjt | 11:b64d123b9f4f | 462 | sprintf(buffer2,"IMPERIAL"); |
el15pjt | 7:14cfb0df30e6 | 463 | } else { |
el15pjt | 11:b64d123b9f4f | 464 | sprintf(buffer2,"METRIC"); |
el15pjt | 11:b64d123b9f4f | 465 | } |
el15pjt | 11:b64d123b9f4f | 466 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 467 | lcd.printString("UNITS",0,1); |
el15pjt | 11:b64d123b9f4f | 468 | break; |
el15pjt | 11:b64d123b9f4f | 469 | case 3: |
el15pjt | 11:b64d123b9f4f | 470 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 471 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 472 | check_flag =0; |
el15pjt | 11:b64d123b9f4f | 473 | lcd.clear(); |
el15pjt | 11:b64d123b9f4f | 474 | } |
el15pjt | 11:b64d123b9f4f | 475 | if (check_flag == 0) { |
el15pjt | 11:b64d123b9f4f | 476 | sprintf(buffer2,"COLLISION"); |
el15pjt | 11:b64d123b9f4f | 477 | lcd.printString("NO",0,1); |
el15pjt | 11:b64d123b9f4f | 478 | sprintf(buffer4,"NEXT "); |
el15pjt | 11:b64d123b9f4f | 479 | } else { |
el15pjt | 11:b64d123b9f4f | 480 | sprintf(buffer2,"COLLISION"); |
el15pjt | 11:b64d123b9f4f | 481 | lcd.printString("CLEAR",0,1); |
el15pjt | 11:b64d123b9f4f | 482 | sprintf(buffer4,"NEXT CLEAR"); |
el15pjt | 7:14cfb0df30e6 | 483 | } |
el15pjt | 7:14cfb0df30e6 | 484 | |
el15pjt | 11:b64d123b9f4f | 485 | lcd.printString(buffer4,0,5); |
el15pjt | 7:14cfb0df30e6 | 486 | break; |
el15pjt | 11:b64d123b9f4f | 487 | case 4: |
el15pjt | 11:b64d123b9f4f | 488 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 489 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 490 | bright = 1.0; |
el15pjt | 11:b64d123b9f4f | 491 | offset = 0; |
el15pjt | 11:b64d123b9f4f | 492 | units = 1; |
el15pjt | 11:b64d123b9f4f | 493 | r1 = 03;// Upper limit of alert 1 |
el15pjt | 11:b64d123b9f4f | 494 | r2 = 10;// Upper limit of alert 2 |
el15pjt | 11:b64d123b9f4f | 495 | r3 = 20;// Upper limit of alert 3 |
el15pjt | 11:b64d123b9f4f | 496 | r4 = 30;// Upper limit of alert 4 |
el15pjt | 11:b64d123b9f4f | 497 | r5 = 50;// Upper limit of alert 5 |
el15pjt | 11:b64d123b9f4f | 498 | r6 = 60;// Upper limit of alert 6 |
el15pjt | 11:b64d123b9f4f | 499 | r7 = 80;// Upper limit of alert 7 |
el15pjt | 11:b64d123b9f4f | 500 | lcd.clear(); |
el15pjt | 11:b64d123b9f4f | 501 | lcd.printString("SETTINGS",0,1); |
el15pjt | 11:b64d123b9f4f | 502 | lcd.printString("RESET",0,2); |
el15pjt | 11:b64d123b9f4f | 503 | wait(1); |
el15pjt | 11:b64d123b9f4f | 504 | return; |
el15pjt | 11:b64d123b9f4f | 505 | } |
el15pjt | 11:b64d123b9f4f | 506 | sprintf(buffer2,"SETTINGS"); |
el15pjt | 11:b64d123b9f4f | 507 | lcd.printString("RESET",0,1); |
el15pjt | 11:b64d123b9f4f | 508 | lcd.printString("NEXT RESET",0,5); |
el15pjt | 11:b64d123b9f4f | 509 | break; |
el15pjt | 11:b64d123b9f4f | 510 | case 5: |
el15pjt | 7:14cfb0df30e6 | 511 | if (g_sw2_flag) { |
el15pjt | 7:14cfb0df30e6 | 512 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 7:14cfb0df30e6 | 513 | submenu(); |
el15pjt | 7:14cfb0df30e6 | 514 | } |
el15pjt | 11:b64d123b9f4f | 515 | sprintf(buffer2,"PARAMETERS"); |
el15pjt | 11:b64d123b9f4f | 516 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 517 | lcd.printString("EXIT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 518 | break; |
el15pjt | 11:b64d123b9f4f | 519 | default: |
el15pjt | 11:b64d123b9f4f | 520 | lcd.clear(); |
el15pjt | 11:b64d123b9f4f | 521 | save (); |
el15pjt | 11:b64d123b9f4f | 522 | lcd.printString(" SAVING ",0,2); |
el15pjt | 11:b64d123b9f4f | 523 | lcd.printString(" SETTINGS ",0,3); |
el15pjt | 11:b64d123b9f4f | 524 | wait (1); |
el15pjt | 11:b64d123b9f4f | 525 | return; |
el15pjt | 11:b64d123b9f4f | 526 | }// switch bracket |
el15pjt | 11:b64d123b9f4f | 527 | lcd.printString(buffer2,0,2); |
el15pjt | 11:b64d123b9f4f | 528 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 529 | lcd.refresh(); |
el15pjt | 11:b64d123b9f4f | 530 | }//while braket |
el15pjt | 11:b64d123b9f4f | 531 | }//functon bracket |
el15pjt | 11:b64d123b9f4f | 532 | @endcode |
el15pjt | 11:b64d123b9f4f | 533 | */ |
el15pjt | 11:b64d123b9f4f | 534 | void menu(); |
el15pjt | 7:14cfb0df30e6 | 535 | |
el15pjt | 7:14cfb0df30e6 | 536 | |
el15pjt | 11:b64d123b9f4f | 537 | /** |
el15pjt | 11:b64d123b9f4f | 538 | Function for submenu Controlling the range peramiters |
el15pjt | 11:b64d123b9f4f | 539 | @code |
el15pjt | 11:b64d123b9f4f | 540 | { |
el15pjt | 11:b64d123b9f4f | 541 | while(1) { |
el15pjt | 11:b64d123b9f4f | 542 | /// interupt used to shift page |
el15pjt | 11:b64d123b9f4f | 543 | if (g_sw1_flag) { |
el15pjt | 11:b64d123b9f4f | 544 | g_sw1_flag = 0; |
el15pjt | 11:b64d123b9f4f | 545 | subpage++; |
el15pjt | 11:b64d123b9f4f | 546 | } |
el15pjt | 11:b64d123b9f4f | 547 | switch (subpage) { ///interupt used to adjust range |
el15pjt | 11:b64d123b9f4f | 548 | case 0: |
el15pjt | 11:b64d123b9f4f | 549 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 550 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 551 | if (r2 == r3) { |
el15pjt | 11:b64d123b9f4f | 552 | r2 = 3; |
el15pjt | 11:b64d123b9f4f | 553 | } else { |
el15pjt | 11:b64d123b9f4f | 554 | r2 = r2+1; |
el15pjt | 11:b64d123b9f4f | 555 | } |
el15pjt | 11:b64d123b9f4f | 556 | } |
el15pjt | 11:b64d123b9f4f | 557 | sprintf(buffer4,"1Cm to %iCm",r2); |
el15pjt | 11:b64d123b9f4f | 558 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 559 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 560 | lcd.printString("PARAMETERS",0,2); |
el15pjt | 11:b64d123b9f4f | 561 | lcd.printString(buffer4,0,3); |
el15pjt | 11:b64d123b9f4f | 562 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 7:14cfb0df30e6 | 563 | break; |
el15pjt | 11:b64d123b9f4f | 564 | case 1: |
el15pjt | 11:b64d123b9f4f | 565 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 566 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 567 | if (r3 == r4) { |
el15pjt | 11:b64d123b9f4f | 568 | r3 = r2; |
el15pjt | 11:b64d123b9f4f | 569 | } else { |
el15pjt | 11:b64d123b9f4f | 570 | r3 += 1; |
el15pjt | 11:b64d123b9f4f | 571 | } |
el15pjt | 11:b64d123b9f4f | 572 | } |
el15pjt | 11:b64d123b9f4f | 573 | sprintf(buffer4,"%iCm to %iCm",r2,r3); |
el15pjt | 11:b64d123b9f4f | 574 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 575 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 576 | lcd.printString("PARAMETERS",0,2); |
el15pjt | 11:b64d123b9f4f | 577 | lcd.printString(buffer4,0,3); |
el15pjt | 11:b64d123b9f4f | 578 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 579 | break; |
el15pjt | 11:b64d123b9f4f | 580 | case 2: |
el15pjt | 11:b64d123b9f4f | 581 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 582 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 583 | if (r4 == r5) { |
el15pjt | 11:b64d123b9f4f | 584 | r4 = r3; |
el15pjt | 11:b64d123b9f4f | 585 | } else { |
el15pjt | 11:b64d123b9f4f | 586 | r4 += 1; |
el15pjt | 11:b64d123b9f4f | 587 | } |
el15pjt | 11:b64d123b9f4f | 588 | } |
el15pjt | 11:b64d123b9f4f | 589 | sprintf(buffer4,"%iCm to %iCm",r3,r4); |
el15pjt | 11:b64d123b9f4f | 590 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 591 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 592 | lcd.printString("PARAMETERS",0,2); |
el15pjt | 11:b64d123b9f4f | 593 | lcd.printString(buffer4,0,3); |
el15pjt | 11:b64d123b9f4f | 594 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 595 | break; |
el15pjt | 11:b64d123b9f4f | 596 | case 3: |
el15pjt | 11:b64d123b9f4f | 597 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 598 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 599 | if (r5 == r6) { |
el15pjt | 11:b64d123b9f4f | 600 | r5 = r4; |
el15pjt | 11:b64d123b9f4f | 601 | } else { |
el15pjt | 11:b64d123b9f4f | 602 | r5 += 1; |
el15pjt | 11:b64d123b9f4f | 603 | } |
el15pjt | 11:b64d123b9f4f | 604 | } |
el15pjt | 11:b64d123b9f4f | 605 | sprintf(buffer4,"%iCm to %iCm",r4,r5); |
el15pjt | 11:b64d123b9f4f | 606 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 607 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 608 | lcd.printString("PARAMETERS",0,2); |
el15pjt | 11:b64d123b9f4f | 609 | lcd.printString(buffer4,0,3); |
el15pjt | 11:b64d123b9f4f | 610 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 611 | break; |
el15pjt | 11:b64d123b9f4f | 612 | case 4: |
el15pjt | 11:b64d123b9f4f | 613 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 614 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 615 | if (r6 == r7) { |
el15pjt | 11:b64d123b9f4f | 616 | r6 = r5; |
el15pjt | 11:b64d123b9f4f | 617 | } else { |
el15pjt | 11:b64d123b9f4f | 618 | r6 += 1; |
el15pjt | 11:b64d123b9f4f | 619 | } |
el15pjt | 11:b64d123b9f4f | 620 | } |
el15pjt | 11:b64d123b9f4f | 621 | sprintf(buffer4,"%iCm to %iCm",r5,r6); |
el15pjt | 11:b64d123b9f4f | 622 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 623 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 624 | lcd.printString("PARAMETERS",0,2); |
el15pjt | 11:b64d123b9f4f | 625 | lcd.printString(buffer4,0,3); |
el15pjt | 11:b64d123b9f4f | 626 | lcd.printString("NEXT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 627 | break; |
el15pjt | 11:b64d123b9f4f | 628 | case 5: |
el15pjt | 11:b64d123b9f4f | 629 | if (g_sw2_flag) { |
el15pjt | 11:b64d123b9f4f | 630 | g_sw2_flag = 0; // if it has, clear the flag |
el15pjt | 11:b64d123b9f4f | 631 | if (r7 == 300) { |
el15pjt | 11:b64d123b9f4f | 632 | r7 = r6; |
el15pjt | 11:b64d123b9f4f | 633 | } else { |
el15pjt | 11:b64d123b9f4f | 634 | r7 += 1; |
el15pjt | 11:b64d123b9f4f | 635 | } |
el15pjt | 11:b64d123b9f4f | 636 | } |
el15pjt | 11:b64d123b9f4f | 637 | sprintf(buffer4,"%iCm to %iCm",r6,r7); |
el15pjt | 11:b64d123b9f4f | 638 | lcd.printString("*****MENU*****",0,0); |
el15pjt | 11:b64d123b9f4f | 639 | lcd.printString("RANGE",0,1); |
el15pjt | 11:b64d123b9f4f | 640 | lcd.printString("PARAMETERS",0,2); |
el15pjt | 11:b64d123b9f4f | 641 | lcd.printString(buffer4,0,3); |
el15pjt | 11:b64d123b9f4f | 642 | lcd.printString("EXIT ADJ",0,5); |
el15pjt | 11:b64d123b9f4f | 643 | break; |
el15pjt | 7:14cfb0df30e6 | 644 | default: |
el15pjt | 7:14cfb0df30e6 | 645 | lcd.clear(); |
el15pjt | 7:14cfb0df30e6 | 646 | return; |
el15pjt | 11:b64d123b9f4f | 647 | }//switch breaket |
el15pjt | 11:b64d123b9f4f | 648 | }//while bracket |
el15pjt | 11:b64d123b9f4f | 649 | }//function bracket |
el15pjt | 11:b64d123b9f4f | 650 | @endcode |
el15pjt | 11:b64d123b9f4f | 651 | */ |
el15pjt | 11:b64d123b9f4f | 652 | void submenu(); |
el15pjt | 7:14cfb0df30e6 | 653 | |
el15pjt | 11:b64d123b9f4f | 654 | /** |
el15pjt | 11:b64d123b9f4f | 655 | Save function saving settings |
el15pjt | 11:b64d123b9f4f | 656 | @param bright - Backlight setting |
el15pjt | 11:b64d123b9f4f | 657 | @param units - Metric or Imperial settings |
el15pjt | 11:b64d123b9f4f | 658 | @param offset - offest distance setting |
el15pjt | 11:b64d123b9f4f | 659 | @param check_flag - Saves a collision alert |
el15pjt | 11:b64d123b9f4f | 660 | @param r1 - upper limit for alert 1 |
el15pjt | 11:b64d123b9f4f | 661 | @param r2 - upper limit for alert 2 |
el15pjt | 11:b64d123b9f4f | 662 | @param r3 - upper limit for alert 3 |
el15pjt | 11:b64d123b9f4f | 663 | @param r4 - upper limit for alert 4 |
el15pjt | 11:b64d123b9f4f | 664 | @param r5 - upper limit for alert 5 |
el15pjt | 11:b64d123b9f4f | 665 | @param r6 - upper limit for alert 6 |
el15pjt | 11:b64d123b9f4f | 666 | @param r7 - upper limit for alert 7 |
el15pjt | 11:b64d123b9f4f | 667 | @code |
el15pjt | 11:b64d123b9f4f | 668 | { |
el15pjt | 11:b64d123b9f4f | 669 | fp = fopen("/sd/settings.txt", "w"); |
el15pjt | 11:b64d123b9f4f | 670 | if (fp == NULL) { // if it can't open the file then print error message |
el15pjt | 11:b64d123b9f4f | 671 | serial.printf("Error! Unable to open file!\n"); |
el15pjt | 11:b64d123b9f4f | 672 | } else { // opened file so can write |
el15pjt | 11:b64d123b9f4f | 673 | serial.printf("Writing to file...."); |
el15pjt | 11:b64d123b9f4f | 674 | fprintf(fp, "%f,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i",bright,units,offset,check_flag,r1,r2,r3,r4,r5,r6,r7); // ensure data type matches |
el15pjt | 11:b64d123b9f4f | 675 | serial.printf("Done.\n"); |
el15pjt | 11:b64d123b9f4f | 676 | fclose(fp); // ensure you close the file after writing |
el15pjt | 7:14cfb0df30e6 | 677 | } |
el15pjt | 8:fe6ebe807b9d | 678 | } |
el15pjt | 11:b64d123b9f4f | 679 | @endcode |
el15pjt | 11:b64d123b9f4f | 680 | */ |
el15pjt | 11:b64d123b9f4f | 681 | void save(); |
el15pjt | 11:b64d123b9f4f | 682 | |
el15pjt | 11:b64d123b9f4f | 683 | /** |
el15pjt | 11:b64d123b9f4f | 684 | Inturupt flag for button 2 |
el15pjt | 11:b64d123b9f4f | 685 | @code |
el15pjt | 11:b64d123b9f4f | 686 | { |
el15pjt | 11:b64d123b9f4f | 687 | g_sw2_flag = 1; //set flag in ISR by button 2 @param g_sw2_flag 0 or 1 |
el15pjt | 8:fe6ebe807b9d | 688 | } |
el15pjt | 8:fe6ebe807b9d | 689 | @endcode |
el15pjt | 8:fe6ebe807b9d | 690 | */ |
el15pjt | 11:b64d123b9f4f | 691 | void sw2_isr(); |
el15pjt | 11:b64d123b9f4f | 692 | |
el15pjt | 11:b64d123b9f4f | 693 | /** |
el15pjt | 11:b64d123b9f4f | 694 | Inturupt flag for button 1 |
el15pjt | 11:b64d123b9f4f | 695 | @code |
el15pjt | 11:b64d123b9f4f | 696 | { |
el15pjt | 11:b64d123b9f4f | 697 | g_sw1_flag = 1; //set flag in ISR by button 2 @param g_sw1_flag 0 or 1 |
el15pjt | 11:b64d123b9f4f | 698 | } |
el15pjt | 11:b64d123b9f4f | 699 | @endcode |
el15pjt | 11:b64d123b9f4f | 700 | */ |
el15pjt | 11:b64d123b9f4f | 701 | void sw1_isr(); |
el15pjt | 11:b64d123b9f4f | 702 | |
el15pjt | 11:b64d123b9f4f | 703 | /** |
el15pjt | 11:b64d123b9f4f | 704 | Flag used with ticker for flashing of LEDs |
el15pjt | 11:b64d123b9f4f | 705 | @code |
el15pjt | 11:b64d123b9f4f | 706 | { |
el15pjt | 11:b64d123b9f4f | 707 | g_timer_flag_led = 1; // set flag in ISR by timer_isr_led @param g_timer_flag_led 0 or 1 |
el15pjt | 11:b64d123b9f4f | 708 | } |
el15pjt | 11:b64d123b9f4f | 709 | @endcode |
el15pjt | 11:b64d123b9f4f | 710 | */ |
el15pjt | 11:b64d123b9f4f | 711 | void timer_isr_led(); |
el15pjt | 11:b64d123b9f4f | 712 | |
el15pjt | 11:b64d123b9f4f | 713 | /** |
el15pjt | 11:b64d123b9f4f | 714 | Flag used for Ticker controlling SRF02 sensor reading |
el15pjt | 11:b64d123b9f4f | 715 | @code |
el15pjt | 11:b64d123b9f4f | 716 | { |
el15pjt | 11:b64d123b9f4f | 717 | g_timer_flag_srf02 = 1; // set flag in ISR by ticker_srf02 @param g_timer_flag_srf02 0 or 1 |
el15pjt | 11:b64d123b9f4f | 718 | } |
el15pjt | 11:b64d123b9f4f | 719 | @endcode |
el15pjt | 11:b64d123b9f4f | 720 | */ |
el15pjt | 11:b64d123b9f4f | 721 | void timer_isr_srf02(); |
el15pjt | 11:b64d123b9f4f | 722 | |
el15pjt | 11:b64d123b9f4f | 723 | /** |
el15pjt | 11:b64d123b9f4f | 724 | Flag raised for incrementing standby level |
el15pjt | 11:b64d123b9f4f | 725 | @code |
el15pjt | 11:b64d123b9f4f | 726 | { |
el15pjt | 11:b64d123b9f4f | 727 | g_timer_flag_standby = 1; // set flag in ISR by ticker_tone @param g_timer_flag_tone 0 or 1 |
el15pjt | 11:b64d123b9f4f | 728 | }# |
el15pjt | 11:b64d123b9f4f | 729 | @endcode |
el15pjt | 11:b64d123b9f4f | 730 | */ |
el15pjt | 11:b64d123b9f4f | 731 | void timer_isr_standby(); |
el15pjt | 7:14cfb0df30e6 | 732 | |
el15pjt | 7:14cfb0df30e6 | 733 | #endif |