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