![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed
main.cpp@24:02c61793f90b, 2015-11-29 (annotated)
- Committer:
- dreamselec
- Date:
- Sun Nov 29 01:05:42 2015 +0000
- Revision:
- 24:02c61793f90b
- Parent:
- 23:db91aaa43a9e
- Child:
- 25:792540d69c49
Both break-beam and servo test modes working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreamselec | 0:fe5cb0a8fc5a | 1 | #include "mbed.h" |
dreamselec | 0:fe5cb0a8fc5a | 2 | #include "WattBob_TextLCD.h" |
dreamselec | 0:fe5cb0a8fc5a | 3 | #include "TCS3472_I2C.h" |
dreamselec | 0:fe5cb0a8fc5a | 4 | #include "MCP23017.h" |
dreamselec | 0:fe5cb0a8fc5a | 5 | #include <string> |
dreamselec | 1:92a2a5ef65a8 | 6 | #include <time.h> |
dreamselec | 2:7a55cb10259f | 7 | //#include <future> |
dreamselec | 2:7a55cb10259f | 8 | #include "globals.h" |
dreamselec | 2:7a55cb10259f | 9 | #include "commander.h" |
dreamselec | 3:843b830ee8bd | 10 | #include "fpga.h" |
dreamselec | 0:fe5cb0a8fc5a | 11 | |
dreamselec | 0:fe5cb0a8fc5a | 12 | #define BACKLIGHT_ON(INTERFACE) INTERFACE->write_bit(1, 4); |
dreamselec | 0:fe5cb0a8fc5a | 13 | #define BACKLIGHT_OFF(INTERFACE) INTERFACE->write_bit(0, 4); |
dreamselec | 0:fe5cb0a8fc5a | 14 | |
dreamselec | 0:fe5cb0a8fc5a | 15 | #define LCDFL() lcd->locate(0,0); |
dreamselec | 0:fe5cb0a8fc5a | 16 | #define LCDSL() lcd->locate(1,0); |
dreamselec | 2:7a55cb10259f | 17 | #define D_LEDS_OFF() i2cport->write_bit(0, 12); i2cport->write_bit(0, 13); i2cport->write_bit(0, 14); i2cport->write_bit(0, 15); |
dreamselec | 2:7a55cb10259f | 18 | #define U_LEDS_OFF() myLED1 = 0; myLED2 = 0; myLED3 = 0; myLED4 = 0; |
dreamselec | 0:fe5cb0a8fc5a | 19 | |
dreamselec | 2:7a55cb10259f | 20 | DigitalOut myLED1(LED1); |
dreamselec | 2:7a55cb10259f | 21 | DigitalOut myLED2(LED2); |
dreamselec | 2:7a55cb10259f | 22 | DigitalOut myLED3(LED3); |
dreamselec | 2:7a55cb10259f | 23 | DigitalOut myLED4(LED4); |
dreamselec | 0:fe5cb0a8fc5a | 24 | |
dreamselec | 0:fe5cb0a8fc5a | 25 | MCP23017 *i2cport; |
dreamselec | 0:fe5cb0a8fc5a | 26 | WattBob_TextLCD *lcd; |
dreamselec | 10:16ba52f8e025 | 27 | TCS3472_I2C rgbSensor(p28, p27); |
dreamselec | 2:7a55cb10259f | 28 | Serial pc(USBTX, USBRX); |
dreamselec |
8:e1da2ae62885 | 29 | uint8_t rxBuffer[kSmallBufferSize + 1]; |
dreamselec |
8:e1da2ae62885 | 30 | int rxIndex = 0; |
dreamselec | 21:60c4fe94d79c | 31 | float percentageError[3]; |
dreamselec | 21:60c4fe94d79c | 32 | float adjustedValues[3]; |
dreamselec | 2:7a55cb10259f | 33 | |
dreamselec |
6:98fe30430194 | 34 | Commander _commander = Commander(); |
dreamselec |
6:98fe30430194 | 35 | Commander *commander = &_commander; |
dreamselec |
6:98fe30430194 | 36 | FPGA _fpga = FPGA(); |
dreamselec | 9:dc8f155b71c8 | 37 | extern FPGA *fpga = &_fpga; |
dreamselec |
6:98fe30430194 | 38 | |
dreamselec | 20:4e0f0944f28f | 39 | Block defualtHazBlock = Block(); |
dreamselec |
6:98fe30430194 | 40 | extern Block _HazBlock; |
dreamselec |
6:98fe30430194 | 41 | Block *HazBlock = &_HazBlock; |
dreamselec |
6:98fe30430194 | 42 | |
dreamselec |
18:44a1c1a30166 | 43 | extern PCModes currentMode; |
dreamselec |
18:44a1c1a30166 | 44 | |
dreamselec |
6:98fe30430194 | 45 | void initInternal(); |
dreamselec | 7:b6e31bfdb2af | 46 | void initPort(int baudRate=kDefaultBaudRate); |
dreamselec |
6:98fe30430194 | 47 | void printPCDetectedText(); |
dreamselec |
6:98fe30430194 | 48 | void Rx_interrupt(); |
dreamselec |
18:44a1c1a30166 | 49 | bool checkColour(int colourValues[]); |
dreamselec | 10:16ba52f8e025 | 50 | void runInServoTestMode(); |
dreamselec | 15:777390eb5afd | 51 | void displayWaitingLine(); |
dreamselec | 15:777390eb5afd | 52 | void displayPCStatus(); |
dreamselec |
18:44a1c1a30166 | 53 | bool waitForBlock(); |
dreamselec |
18:44a1c1a30166 | 54 | void sortBlock(); |
dreamselec |
23:db91aaa43a9e | 55 | void runInBreakBeamTestMode(); |
dreamselec |
23:db91aaa43a9e | 56 | void turnOffTopLEDs(); |
dreamselec |
23:db91aaa43a9e | 57 | void turnOffBottomLEDs(); |
dreamselec |
6:98fe30430194 | 58 | |
dreamselec |
6:98fe30430194 | 59 | int main() |
dreamselec |
6:98fe30430194 | 60 | { |
dreamselec |
23:db91aaa43a9e | 61 | initInternal(); |
dreamselec |
23:db91aaa43a9e | 62 | initPort(); |
dreamselec |
23:db91aaa43a9e | 63 | srand((unsigned)time(NULL)); |
dreamselec |
23:db91aaa43a9e | 64 | U_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 65 | lcd->cls(); |
dreamselec | 15:777390eb5afd | 66 | |
dreamselec |
23:db91aaa43a9e | 67 | rgbSensor.enablePowerAndRGBC(); |
dreamselec |
23:db91aaa43a9e | 68 | rgbSensor.setIntegrationTime(3); |
dreamselec |
6:98fe30430194 | 69 | |
dreamselec |
23:db91aaa43a9e | 70 | // Create a serial intereput for RxIrq so when PC is connected it sends '$' to tell MBED it's there. |
dreamselec |
23:db91aaa43a9e | 71 | // https://developer.mbed.org/cookbook/Serial-Interrupts |
dreamselec |
23:db91aaa43a9e | 72 | pc.attach(&Rx_interrupt, Serial::RxIrq); |
dreamselec |
6:98fe30430194 | 73 | |
dreamselec |
23:db91aaa43a9e | 74 | for (;;) { |
dreamselec |
23:db91aaa43a9e | 75 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 76 | i2cport->write_bit(1, 12); |
dreamselec |
23:db91aaa43a9e | 77 | lcd->printf("1: Start sorting."); |
dreamselec |
23:db91aaa43a9e | 78 | LCDSL(); |
dreamselec |
23:db91aaa43a9e | 79 | i2cport->write_bit(1,13); |
dreamselec |
23:db91aaa43a9e | 80 | lcd->printf("2: Connect to PC"); |
dreamselec | 15:777390eb5afd | 81 | |
dreamselec |
23:db91aaa43a9e | 82 | fpga->moveStoppingServo(Stop); |
dreamselec |
23:db91aaa43a9e | 83 | fpga->moveSortingServo(NonHaz); |
dreamselec | 24:02c61793f90b | 84 | |
dreamselec | 24:02c61793f90b | 85 | pc.printf(":<pc>connect;"); |
dreamselec | 24:02c61793f90b | 86 | // wait(0.03); |
dreamselec | 10:16ba52f8e025 | 87 | |
dreamselec |
23:db91aaa43a9e | 88 | int selection = 0; |
dreamselec |
23:db91aaa43a9e | 89 | do { |
dreamselec |
23:db91aaa43a9e | 90 | myLED4 = selection; |
dreamselec |
23:db91aaa43a9e | 91 | selection = readSwitches(); |
dreamselec |
23:db91aaa43a9e | 92 | } while (selection != 1 && selection != 2 && connectedToPC == false); |
dreamselec |
23:db91aaa43a9e | 93 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 94 | if (selection == 1) { |
dreamselec |
23:db91aaa43a9e | 95 | // User selected op 1: Start sorting autonomously. |
dreamselec |
23:db91aaa43a9e | 96 | i2cport->write_bit(1, 12); |
dreamselec |
23:db91aaa43a9e | 97 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 98 | LCDFL(); |
dreamselec |
23:db91aaa43a9e | 99 | lcd->printf("Starting sorting"); |
dreamselec |
23:db91aaa43a9e | 100 | wait(0.5); |
dreamselec |
23:db91aaa43a9e | 101 | D_LEDS_OFF(); |
dreamselec | 19:61b21ac4896e | 102 | |
dreamselec |
23:db91aaa43a9e | 103 | for(;;) { |
dreamselec |
23:db91aaa43a9e | 104 | displayWaitingLine(); |
dreamselec |
23:db91aaa43a9e | 105 | lcd->printf("for block."); |
dreamselec | 10:16ba52f8e025 | 106 | |
dreamselec |
23:db91aaa43a9e | 107 | i2cport->write_bit(1, 15); |
dreamselec | 10:16ba52f8e025 | 108 | |
dreamselec |
23:db91aaa43a9e | 109 | // Break and return to main menu i.e. Start Op, or Connect to PC. |
dreamselec |
23:db91aaa43a9e | 110 | if (waitForBlock() == false) { |
dreamselec |
23:db91aaa43a9e | 111 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 112 | break; |
dreamselec |
23:db91aaa43a9e | 113 | } else { |
dreamselec |
23:db91aaa43a9e | 114 | sortBlock(); |
dreamselec |
23:db91aaa43a9e | 115 | } |
dreamselec |
23:db91aaa43a9e | 116 | } |
dreamselec |
23:db91aaa43a9e | 117 | } |
dreamselec |
23:db91aaa43a9e | 118 | |
dreamselec |
23:db91aaa43a9e | 119 | if (selection == 2 || connectedToPC == true) { |
dreamselec |
23:db91aaa43a9e | 120 | for (;;) { |
dreamselec |
23:db91aaa43a9e | 121 | displayPCStatus(); |
dreamselec | 10:16ba52f8e025 | 122 | |
dreamselec |
23:db91aaa43a9e | 123 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 124 | int abortOperation = false; |
dreamselec |
23:db91aaa43a9e | 125 | if (connectedToPC == false) |
dreamselec |
23:db91aaa43a9e | 126 | pc.printf(":<pc>connect;"); |
dreamselec |
23:db91aaa43a9e | 127 | while (connectedToPC == false && abortOperation == false) { |
dreamselec |
23:db91aaa43a9e | 128 | abortOperation = readSwitches() == 4; |
dreamselec |
23:db91aaa43a9e | 129 | } |
dreamselec | 19:61b21ac4896e | 130 | |
dreamselec |
23:db91aaa43a9e | 131 | if (abortOperation == true) { |
dreamselec |
23:db91aaa43a9e | 132 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 133 | break; |
dreamselec |
23:db91aaa43a9e | 134 | } |
dreamselec |
18:44a1c1a30166 | 135 | |
dreamselec |
23:db91aaa43a9e | 136 | displayPCStatus(); |
dreamselec | 15:777390eb5afd | 137 | |
dreamselec |
23:db91aaa43a9e | 138 | while (abortOperation == false && connectedToPC == true) { |
dreamselec |
23:db91aaa43a9e | 139 | if (currentMode == Maintanence) { |
dreamselec | 24:02c61793f90b | 140 | displayPCStatus(); |
dreamselec | 24:02c61793f90b | 141 | while (currentMode == Maintanence){ |
dreamselec |
23:db91aaa43a9e | 142 | if (runServoTest == true) |
dreamselec |
23:db91aaa43a9e | 143 | runInServoTestMode(); |
dreamselec |
23:db91aaa43a9e | 144 | else if (runBreakBeamTest == true) |
dreamselec |
23:db91aaa43a9e | 145 | runInBreakBeamTestMode(); |
dreamselec | 24:02c61793f90b | 146 | } |
dreamselec |
23:db91aaa43a9e | 147 | } else if (currentMode == Normal) { |
dreamselec |
23:db91aaa43a9e | 148 | displayPCStatus(); |
dreamselec |
23:db91aaa43a9e | 149 | while (currentMode == Normal) { |
dreamselec |
23:db91aaa43a9e | 150 | if (currentState == Pause) { |
dreamselec |
23:db91aaa43a9e | 151 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 152 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 153 | lcd->printf("Sorting Paused."); |
dreamselec |
23:db91aaa43a9e | 154 | lcd->locate(1,0); |
dreamselec |
23:db91aaa43a9e | 155 | lcd->printf("1: Start"); |
dreamselec |
23:db91aaa43a9e | 156 | int button = 0; |
dreamselec |
23:db91aaa43a9e | 157 | i2cport->write_bit(1, 12); |
dreamselec |
23:db91aaa43a9e | 158 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 159 | while (currentState == Pause && currentMode == Normal) { |
dreamselec |
23:db91aaa43a9e | 160 | button = readSwitches(); |
dreamselec |
23:db91aaa43a9e | 161 | if (button == 1) { |
dreamselec |
23:db91aaa43a9e | 162 | pc.printf("state:start\n"); |
dreamselec |
23:db91aaa43a9e | 163 | currentState = Start; |
dreamselec |
23:db91aaa43a9e | 164 | } else if (button == 4) { |
dreamselec |
23:db91aaa43a9e | 165 | currentMode = None; |
dreamselec |
23:db91aaa43a9e | 166 | // goto setModeNone; |
dreamselec |
23:db91aaa43a9e | 167 | break; |
dreamselec |
23:db91aaa43a9e | 168 | } |
dreamselec |
23:db91aaa43a9e | 169 | } |
dreamselec |
23:db91aaa43a9e | 170 | } |
dreamselec |
23:db91aaa43a9e | 171 | if (currentState == Start) { |
dreamselec |
23:db91aaa43a9e | 172 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 173 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 174 | lcd->printf("Sorting mode..."); |
dreamselec |
23:db91aaa43a9e | 175 | while (currentState == Start && currentMode == Normal) { |
dreamselec |
23:db91aaa43a9e | 176 | if (waitForBlock() == false) { |
dreamselec |
23:db91aaa43a9e | 177 | if (connectedToPC == true) { |
dreamselec |
23:db91aaa43a9e | 178 | // TODO: Tell PC to update UI if aborted from MBED. |
dreamselec |
23:db91aaa43a9e | 179 | pc.printf("state:pause\n"); |
dreamselec |
23:db91aaa43a9e | 180 | currentState = Pause; |
dreamselec |
23:db91aaa43a9e | 181 | continue; |
dreamselec |
23:db91aaa43a9e | 182 | } else if (connectedToPC == false) { |
dreamselec |
23:db91aaa43a9e | 183 | currentMode = None; |
dreamselec |
23:db91aaa43a9e | 184 | abortOperation = true; |
dreamselec |
23:db91aaa43a9e | 185 | } |
dreamselec |
23:db91aaa43a9e | 186 | } else { |
dreamselec |
23:db91aaa43a9e | 187 | sortBlock(); |
dreamselec |
23:db91aaa43a9e | 188 | } |
dreamselec |
23:db91aaa43a9e | 189 | } |
dreamselec |
23:db91aaa43a9e | 190 | } |
dreamselec |
23:db91aaa43a9e | 191 | } |
dreamselec |
23:db91aaa43a9e | 192 | } else if (currentMode == None) { |
dreamselec |
23:db91aaa43a9e | 193 | setModeNone: |
dreamselec |
23:db91aaa43a9e | 194 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 195 | i2cport->write_bit(1,15); |
dreamselec |
23:db91aaa43a9e | 196 | displayPCStatus(); |
dreamselec |
23:db91aaa43a9e | 197 | while (currentMode == None && abortOperation == false && connectedToPC == true) { |
dreamselec |
23:db91aaa43a9e | 198 | if (i2cport->read_bit(11)) { |
dreamselec |
23:db91aaa43a9e | 199 | abortOperation = displayAbortDialog(); |
dreamselec |
23:db91aaa43a9e | 200 | // Cancel the Abort |
dreamselec |
23:db91aaa43a9e | 201 | if (abortOperation == false) { |
dreamselec |
23:db91aaa43a9e | 202 | displayPCStatus(); |
dreamselec |
23:db91aaa43a9e | 203 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 204 | } |
dreamselec |
23:db91aaa43a9e | 205 | } |
dreamselec |
23:db91aaa43a9e | 206 | } |
dreamselec |
23:db91aaa43a9e | 207 | } |
dreamselec |
23:db91aaa43a9e | 208 | } |
dreamselec | 15:777390eb5afd | 209 | |
dreamselec |
23:db91aaa43a9e | 210 | if (abortOperation == true ) { |
dreamselec |
23:db91aaa43a9e | 211 | connectedToPC = false; |
dreamselec |
23:db91aaa43a9e | 212 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 213 | break; |
dreamselec |
23:db91aaa43a9e | 214 | } |
dreamselec |
23:db91aaa43a9e | 215 | } |
dreamselec |
23:db91aaa43a9e | 216 | } |
dreamselec | 19:61b21ac4896e | 217 | |
dreamselec |
23:db91aaa43a9e | 218 | } |
dreamselec |
18:44a1c1a30166 | 219 | } |
dreamselec |
8:e1da2ae62885 | 220 | |
dreamselec |
18:44a1c1a30166 | 221 | // Waits until detects block. |
dreamselec |
18:44a1c1a30166 | 222 | // true if block detected, false if cancelled/connected to PC. |
dreamselec | 19:61b21ac4896e | 223 | bool waitForBlock() |
dreamselec | 19:61b21ac4896e | 224 | { |
dreamselec |
23:db91aaa43a9e | 225 | myLED4 = 0; |
dreamselec |
23:db91aaa43a9e | 226 | myLED1 = 1; |
dreamselec |
23:db91aaa43a9e | 227 | if (connectedToPC == false) { |
dreamselec |
23:db91aaa43a9e | 228 | bool abortOperation = false; |
dreamselec |
23:db91aaa43a9e | 229 | int blockInserted = 0; |
dreamselec |
23:db91aaa43a9e | 230 | // Wait until a block is breaking the beam, or button 4 is pressed to abort. |
dreamselec |
23:db91aaa43a9e | 231 | do { |
dreamselec |
23:db91aaa43a9e | 232 | blockInserted = fpga->getBeamValue(Top); |
dreamselec |
23:db91aaa43a9e | 233 | myLED4 = blockInserted; |
dreamselec |
23:db91aaa43a9e | 234 | if (i2cport->read_bit(11)) { |
dreamselec |
23:db91aaa43a9e | 235 | abortOperation = displayAbortDialog(); |
dreamselec |
23:db91aaa43a9e | 236 | // Cancel the Abort |
dreamselec |
23:db91aaa43a9e | 237 | if (abortOperation == false) { |
dreamselec |
23:db91aaa43a9e | 238 | displayWaitingLine(); |
dreamselec |
23:db91aaa43a9e | 239 | lcd->printf("for block"); |
dreamselec |
23:db91aaa43a9e | 240 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 241 | } |
dreamselec |
23:db91aaa43a9e | 242 | } |
dreamselec |
23:db91aaa43a9e | 243 | } while (abortOperation == false && blockInserted != 1 && connectedToPC == false); |
dreamselec |
18:44a1c1a30166 | 244 | |
dreamselec |
23:db91aaa43a9e | 245 | if (abortOperation == true || connectedToPC == true) |
dreamselec |
23:db91aaa43a9e | 246 | return false; |
dreamselec |
23:db91aaa43a9e | 247 | else |
dreamselec |
23:db91aaa43a9e | 248 | return true; |
dreamselec |
23:db91aaa43a9e | 249 | } else if (connectedToPC == true) { |
dreamselec |
23:db91aaa43a9e | 250 | bool abortOperation = false; |
dreamselec |
23:db91aaa43a9e | 251 | int blockInserted = 0; |
dreamselec |
23:db91aaa43a9e | 252 | // Wait until a block is breaking the beam, or button 4 is pressed to abort. |
dreamselec |
23:db91aaa43a9e | 253 | do { |
dreamselec |
23:db91aaa43a9e | 254 | blockInserted = fpga->getBeamValue(Top); |
dreamselec |
23:db91aaa43a9e | 255 | myLED4 = blockInserted; |
dreamselec |
23:db91aaa43a9e | 256 | if (i2cport->read_bit(11)) { |
dreamselec |
23:db91aaa43a9e | 257 | abortOperation = displayAbortDialog(); |
dreamselec |
23:db91aaa43a9e | 258 | // Cancel the Abort |
dreamselec |
23:db91aaa43a9e | 259 | if (abortOperation == false) { |
dreamselec |
23:db91aaa43a9e | 260 | displayWaitingLine(); |
dreamselec |
23:db91aaa43a9e | 261 | lcd->printf("for block"); |
dreamselec |
23:db91aaa43a9e | 262 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 263 | } |
dreamselec |
23:db91aaa43a9e | 264 | } |
dreamselec |
23:db91aaa43a9e | 265 | } while (abortOperation == false && blockInserted != 1 && connectedToPC == true && currentState == Start && currentMode == Normal); |
dreamselec | 19:61b21ac4896e | 266 | |
dreamselec |
23:db91aaa43a9e | 267 | if (abortOperation == true || connectedToPC == false || currentState == Pause || currentMode == Maintanence) |
dreamselec |
23:db91aaa43a9e | 268 | return false; |
dreamselec |
23:db91aaa43a9e | 269 | else |
dreamselec |
23:db91aaa43a9e | 270 | return true; |
dreamselec |
23:db91aaa43a9e | 271 | } |
dreamselec |
18:44a1c1a30166 | 272 | } |
dreamselec |
14:cf2f255b5560 | 273 | |
dreamselec | 19:61b21ac4896e | 274 | void sortBlock() |
dreamselec | 19:61b21ac4896e | 275 | { |
dreamselec |
23:db91aaa43a9e | 276 | myLED1 = 0; |
dreamselec |
23:db91aaa43a9e | 277 | myLED2 = 1; |
dreamselec |
23:db91aaa43a9e | 278 | // Cannot Abort any longer. Block is inserted. |
dreamselec |
23:db91aaa43a9e | 279 | // Detach rx interrupt until block processed. |
dreamselec |
23:db91aaa43a9e | 280 | NVIC_DisableIRQ(UART1_IRQn); |
dreamselec |
23:db91aaa43a9e | 281 | fpga->moveSortingServo(Haz); |
dreamselec |
23:db91aaa43a9e | 282 | fpga->moveStoppingServo(Go); |
dreamselec | 21:60c4fe94d79c | 283 | |
dreamselec |
23:db91aaa43a9e | 284 | int colourValues[4]; |
dreamselec |
23:db91aaa43a9e | 285 | int averageColourValues[4] = {0, 0, 0, 0}; |
dreamselec |
23:db91aaa43a9e | 286 | for (int i = 0; i < 3; i++){ |
dreamselec |
23:db91aaa43a9e | 287 | rgbSensor.getAllColors(colourValues); |
dreamselec |
23:db91aaa43a9e | 288 | for (int j = 0; j < 4; j++){ |
dreamselec |
23:db91aaa43a9e | 289 | averageColourValues[j] += colourValues[j]; |
dreamselec |
23:db91aaa43a9e | 290 | } |
dreamselec |
23:db91aaa43a9e | 291 | } |
dreamselec |
23:db91aaa43a9e | 292 | for (int i = 0; i < 4; i++){ |
dreamselec |
23:db91aaa43a9e | 293 | averageColourValues[i] = averageColourValues[i] / 3; |
dreamselec |
23:db91aaa43a9e | 294 | } |
dreamselec |
18:44a1c1a30166 | 295 | |
dreamselec |
23:db91aaa43a9e | 296 | bool haz = false; |
dreamselec |
23:db91aaa43a9e | 297 | haz = checkColour(colourValues); |
dreamselec |
23:db91aaa43a9e | 298 | |
dreamselec |
23:db91aaa43a9e | 299 | if (!haz) { |
dreamselec |
23:db91aaa43a9e | 300 | fpga->moveSortingServo(NonHaz); |
dreamselec |
23:db91aaa43a9e | 301 | } |
dreamselec | 22:993821a4c396 | 302 | int blockSize; |
dreamselec |
23:db91aaa43a9e | 303 | while (fpga->checkForBlock() == 0) { } |
dreamselec |
23:db91aaa43a9e | 304 | blockSize = fpga->checkForSize(); |
dreamselec |
23:db91aaa43a9e | 305 | if (blockSize == HazBlock->size && haz) { |
dreamselec |
23:db91aaa43a9e | 306 | // fpga->moveSortingServo(Haz); |
dreamselec |
23:db91aaa43a9e | 307 | // fpga->moveStoppingServo(Go); |
dreamselec |
23:db91aaa43a9e | 308 | // blockSize = HazBlock->size; |
dreamselec |
23:db91aaa43a9e | 309 | while(fpga->getBeamValue(Bottom) == 1) {} |
dreamselec |
23:db91aaa43a9e | 310 | wait(kServoWait); |
dreamselec |
23:db91aaa43a9e | 311 | fpga->moveStoppingServo(Stop); |
dreamselec |
23:db91aaa43a9e | 312 | } else { |
dreamselec |
23:db91aaa43a9e | 313 | haz = false; |
dreamselec |
23:db91aaa43a9e | 314 | } |
dreamselec |
23:db91aaa43a9e | 315 | fpga->moveSortingServo(NonHaz); |
dreamselec |
23:db91aaa43a9e | 316 | while(fpga->checkForSize()) {} |
dreamselec | 20:4e0f0944f28f | 317 | |
dreamselec |
23:db91aaa43a9e | 318 | if (connectedToPC) { |
dreamselec |
23:db91aaa43a9e | 319 | for (int i = 0; i < 3; i++) { |
dreamselec |
23:db91aaa43a9e | 320 | pc.printf("DEBUG:Percentage Error: %.5f.\n", percentageError[i]); |
dreamselec |
23:db91aaa43a9e | 321 | if ((percentageError[i] < 0 && std::abs(percentageError[i]) < kMinError[i] * 2) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < kMaxError[i] * 2)) |
dreamselec |
23:db91aaa43a9e | 322 | pc.printf("DEBUG:%i.\n", i); |
dreamselec |
23:db91aaa43a9e | 323 | } |
dreamselec |
23:db91aaa43a9e | 324 | pc.printf("BLOCK:Size:%i,Red:%.3f,Green:%.3f,Blue:%.3f,Haz:%i, Offsetred:%.3f, Offsetgreen:%.3f, Offsetblue:%.3f;", blockSize, adjustedValues[0], adjustedValues[1], adjustedValues[2], haz, percentageError[0], percentageError[1], percentageError[2]); |
dreamselec |
23:db91aaa43a9e | 325 | // pc.printf("VALUE:Size:%i,Red:%i,Green:%i,Blue:%i,Clear:%i\n:VALUE", blockSize, colourValues[0], colourValues[1], colourValues[2], colourValues[3], haz); |
dreamselec |
23:db91aaa43a9e | 326 | } |
dreamselec |
18:44a1c1a30166 | 327 | |
dreamselec |
23:db91aaa43a9e | 328 | // Re-Attach rx interrupt |
dreamselec |
23:db91aaa43a9e | 329 | NVIC_EnableIRQ(UART1_IRQn); |
dreamselec |
23:db91aaa43a9e | 330 | myLED3 = 0; |
dreamselec |
23:db91aaa43a9e | 331 | myLED4 = 1; |
dreamselec |
23:db91aaa43a9e | 332 | return; |
dreamselec |
6:98fe30430194 | 333 | } |
dreamselec |
6:98fe30430194 | 334 | |
dreamselec |
6:98fe30430194 | 335 | /// Called every-time it receives an char from PC. |
dreamselec | 10:16ba52f8e025 | 336 | void Rx_interrupt() |
dreamselec | 10:16ba52f8e025 | 337 | { |
dreamselec |
23:db91aaa43a9e | 338 | char interruptChar = pc.getc(); |
dreamselec |
23:db91aaa43a9e | 339 | // Uncomment to Echo to USB serial to watch data flow |
dreamselec |
23:db91aaa43a9e | 340 | // pc.putc(interruptChar); |
dreamselec |
6:98fe30430194 | 341 | |
dreamselec |
23:db91aaa43a9e | 342 | NVIC_DisableIRQ(UART1_IRQn); |
dreamselec |
8:e1da2ae62885 | 343 | |
dreamselec |
23:db91aaa43a9e | 344 | if (interruptChar == CommandTypeValue[Query]) { |
dreamselec |
23:db91aaa43a9e | 345 | commander->decodeCommand(Query); |
dreamselec |
23:db91aaa43a9e | 346 | } else if (interruptChar == CommandTypeValue[Set]) { |
dreamselec |
23:db91aaa43a9e | 347 | commander->decodeCommand(Set); |
dreamselec |
23:db91aaa43a9e | 348 | } else if (interruptChar== CommandTypeValue[Reply]) { |
dreamselec |
23:db91aaa43a9e | 349 | commander->decodeCommand(Reply); |
dreamselec |
23:db91aaa43a9e | 350 | } |
dreamselec |
8:e1da2ae62885 | 351 | |
dreamselec |
23:db91aaa43a9e | 352 | NVIC_EnableIRQ(UART1_IRQn); |
dreamselec |
6:98fe30430194 | 353 | } |
dreamselec | 3:843b830ee8bd | 354 | |
dreamselec | 4:4eebb4de22a7 | 355 | void initInternal() |
dreamselec | 4:4eebb4de22a7 | 356 | { |
dreamselec |
23:db91aaa43a9e | 357 | myLED1 = 1; |
dreamselec |
23:db91aaa43a9e | 358 | i2cport = new MCP23017(p9, p10, 0x40); |
dreamselec |
23:db91aaa43a9e | 359 | lcd = new WattBob_TextLCD(i2cport); |
dreamselec |
23:db91aaa43a9e | 360 | BACKLIGHT_ON(i2cport); |
dreamselec |
23:db91aaa43a9e | 361 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 362 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 363 | lcd->printf("Initilizing..."); |
dreamselec |
23:db91aaa43a9e | 364 | DefaultHazBlock(); |
dreamselec |
23:db91aaa43a9e | 365 | myLED2 = 1; |
dreamselec |
23:db91aaa43a9e | 366 | return; |
dreamselec | 3:843b830ee8bd | 367 | } |
dreamselec | 3:843b830ee8bd | 368 | |
dreamselec | 7:b6e31bfdb2af | 369 | void initPort(int baudRate) |
dreamselec | 4:4eebb4de22a7 | 370 | { |
dreamselec |
23:db91aaa43a9e | 371 | myLED3 = 1; |
dreamselec |
23:db91aaa43a9e | 372 | pc.baud(baudRate); |
dreamselec |
23:db91aaa43a9e | 373 | pc.format(8, SerialBase::None, gStopBits); |
dreamselec |
23:db91aaa43a9e | 374 | myLED4 = 1; |
dreamselec |
23:db91aaa43a9e | 375 | wait (0.1); |
dreamselec |
23:db91aaa43a9e | 376 | return; |
dreamselec | 3:843b830ee8bd | 377 | } |
dreamselec | 3:843b830ee8bd | 378 | |
dreamselec |
18:44a1c1a30166 | 379 | bool checkColour(int colourValues[]) |
dreamselec | 15:777390eb5afd | 380 | { |
dreamselec |
23:db91aaa43a9e | 381 | myLED2 = 0; |
dreamselec |
23:db91aaa43a9e | 382 | myLED3 = 1; |
dreamselec |
23:db91aaa43a9e | 383 | bool isHazColour[3] = {false, false, false }; |
dreamselec |
23:db91aaa43a9e | 384 | memset(adjustedValues, 0, sizeof(adjustedValues)); |
dreamselec |
23:db91aaa43a9e | 385 | memset(percentageError, 0, sizeof(percentageError)); |
dreamselec | 15:777390eb5afd | 386 | |
dreamselec |
23:db91aaa43a9e | 387 | for (int i = 0; i < 3; i++) { |
dreamselec |
23:db91aaa43a9e | 388 | adjustedValues[i] = (float)colourValues[i]/(float)colourValues[3]; |
dreamselec |
23:db91aaa43a9e | 389 | percentageError[i] = (adjustedValues[i] - kAverageRedBlock[i]) / kAverageRedBlock[i]; |
dreamselec | 20:4e0f0944f28f | 390 | |
dreamselec |
23:db91aaa43a9e | 391 | if ((percentageError[i] < 0 && std::abs(percentageError[i]) < kMinError[i] * 2) || percentageError[i] == 0 || (percentageError[i] > 0 && percentageError[i] < kMaxError[i] * 2)) { |
dreamselec |
23:db91aaa43a9e | 392 | isHazColour[i] = true; |
dreamselec |
23:db91aaa43a9e | 393 | } |
dreamselec |
23:db91aaa43a9e | 394 | } |
dreamselec | 15:777390eb5afd | 395 | |
dreamselec |
23:db91aaa43a9e | 396 | // for (int i = 0; i < 3; i++) { |
dreamselec |
23:db91aaa43a9e | 397 | // if (colourValues[i] < HazBlock->maxColour.components[i] && colourValues[i] > HazBlock->minColour.components[i]) { |
dreamselec |
23:db91aaa43a9e | 398 | // isHazColour[i] = true; |
dreamselec |
23:db91aaa43a9e | 399 | // } |
dreamselec |
23:db91aaa43a9e | 400 | // } |
dreamselec | 15:777390eb5afd | 401 | |
dreamselec |
23:db91aaa43a9e | 402 | bool isHazBlock = false; |
dreamselec | 15:777390eb5afd | 403 | |
dreamselec |
23:db91aaa43a9e | 404 | if (isHazColour[0] && isHazColour[1] && isHazColour[2]) { |
dreamselec |
23:db91aaa43a9e | 405 | isHazBlock = true; |
dreamselec |
23:db91aaa43a9e | 406 | } else { |
dreamselec |
23:db91aaa43a9e | 407 | isHazBlock = false; |
dreamselec |
23:db91aaa43a9e | 408 | } |
dreamselec |
23:db91aaa43a9e | 409 | |
dreamselec |
23:db91aaa43a9e | 410 | return isHazBlock; |
dreamselec | 3:843b830ee8bd | 411 | } |
dreamselec | 3:843b830ee8bd | 412 | |
dreamselec |
6:98fe30430194 | 413 | void printPCDetectedText() |
dreamselec | 4:4eebb4de22a7 | 414 | { |
dreamselec |
23:db91aaa43a9e | 415 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 416 | LCDFL(); |
dreamselec |
23:db91aaa43a9e | 417 | lcd->printf("Detected PC."); |
dreamselec |
23:db91aaa43a9e | 418 | LCDSL(); |
dreamselec |
23:db91aaa43a9e | 419 | lcd->printf("Connecting"); |
dreamselec |
23:db91aaa43a9e | 420 | initPort(); |
dreamselec | 10:16ba52f8e025 | 421 | } |
dreamselec | 10:16ba52f8e025 | 422 | |
dreamselec | 10:16ba52f8e025 | 423 | bool displayAbortDialog() |
dreamselec | 10:16ba52f8e025 | 424 | { |
dreamselec |
23:db91aaa43a9e | 425 | while (i2cport->read_bit(11) == 1) {} |
dreamselec |
23:db91aaa43a9e | 426 | i2cport->write_bit(1, 12); |
dreamselec | 10:16ba52f8e025 | 427 | |
dreamselec |
23:db91aaa43a9e | 428 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 429 | LCDFL(); |
dreamselec |
23:db91aaa43a9e | 430 | lcd->printf("Abort?"); |
dreamselec |
23:db91aaa43a9e | 431 | LCDSL(); |
dreamselec |
23:db91aaa43a9e | 432 | lcd->printf("1:Yes, 2,3,4:No"); |
dreamselec |
23:db91aaa43a9e | 433 | int reply = 0; |
dreamselec |
23:db91aaa43a9e | 434 | do { |
dreamselec |
23:db91aaa43a9e | 435 | reply = readSwitches(); |
dreamselec |
23:db91aaa43a9e | 436 | } while(reply == 0); |
dreamselec | 10:16ba52f8e025 | 437 | |
dreamselec |
23:db91aaa43a9e | 438 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 439 | if (reply == 1) { |
dreamselec |
23:db91aaa43a9e | 440 | // while (i2cport->read_bit(8)) { } |
dreamselec |
23:db91aaa43a9e | 441 | return true; |
dreamselec |
23:db91aaa43a9e | 442 | } else { |
dreamselec |
23:db91aaa43a9e | 443 | // while (i2cport->read_bit(9) || i2cport->read_bit(10) || i2cport->read_bit(11)) { } |
dreamselec |
23:db91aaa43a9e | 444 | return false; |
dreamselec |
23:db91aaa43a9e | 445 | } |
dreamselec | 3:843b830ee8bd | 446 | } |
dreamselec | 3:843b830ee8bd | 447 | |
dreamselec | 15:777390eb5afd | 448 | void printServoInfoOnLCD() |
dreamselec | 15:777390eb5afd | 449 | { |
dreamselec |
23:db91aaa43a9e | 450 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 451 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 452 | if (fpga->stoppingServoPosition == Stop) |
dreamselec | 24:02c61793f90b | 453 | lcd->printf("1: Top: Stop"); |
dreamselec |
23:db91aaa43a9e | 454 | else if (fpga->stoppingServoPosition == Go) |
dreamselec | 24:02c61793f90b | 455 | lcd->printf("1: Top: Go"); |
dreamselec |
23:db91aaa43a9e | 456 | |
dreamselec |
23:db91aaa43a9e | 457 | lcd->locate(1,0); |
dreamselec |
23:db91aaa43a9e | 458 | if (fpga->sortingServoPosition == NonHaz) |
dreamselec | 24:02c61793f90b | 459 | lcd->printf("2: Bottom: NonHaz"); |
dreamselec |
23:db91aaa43a9e | 460 | else if (fpga->sortingServoPosition == Haz) |
dreamselec | 24:02c61793f90b | 461 | lcd->printf("2: Bottom: Haz"); |
dreamselec |
23:db91aaa43a9e | 462 | } |
dreamselec |
23:db91aaa43a9e | 463 | |
dreamselec |
23:db91aaa43a9e | 464 | void printServoInfoOnPC() { |
dreamselec |
23:db91aaa43a9e | 465 | if (fpga->stoppingServoPosition == Stop) |
dreamselec |
23:db91aaa43a9e | 466 | pc.printf(":<servos>1=Stop;"); |
dreamselec |
23:db91aaa43a9e | 467 | else if (fpga->stoppingServoPosition == Go) |
dreamselec |
23:db91aaa43a9e | 468 | pc.printf(":<servos>1=Go;"); |
dreamselec |
23:db91aaa43a9e | 469 | |
dreamselec |
23:db91aaa43a9e | 470 | if (fpga->sortingServoPosition == NonHaz) |
dreamselec |
23:db91aaa43a9e | 471 | pc.printf(":<servos>2=NonHaz;"); |
dreamselec |
23:db91aaa43a9e | 472 | else if (fpga->sortingServoPosition == Haz) |
dreamselec |
23:db91aaa43a9e | 473 | pc.printf(":<servos>2=Haz;"); |
dreamselec | 10:16ba52f8e025 | 474 | } |
dreamselec | 10:16ba52f8e025 | 475 | |
dreamselec | 15:777390eb5afd | 476 | void runInServoTestMode() |
dreamselec | 15:777390eb5afd | 477 | { |
dreamselec |
23:db91aaa43a9e | 478 | pc.printf("VALUES:Testing servos.\n Stopping servo:\n\tStop:%i, Go: %i\n Sorting servo:\n\tHaz:%i, NonHaz:%i\n:VALUES", Stop, Go, Haz, NonHaz); |
dreamselec |
23:db91aaa43a9e | 479 | printServoInfoOnPC(); |
dreamselec |
23:db91aaa43a9e | 480 | printServoInfoOnLCD(); |
dreamselec |
23:db91aaa43a9e | 481 | |
dreamselec |
23:db91aaa43a9e | 482 | i2cport->write_bit(1, 12); |
dreamselec |
23:db91aaa43a9e | 483 | i2cport->write_bit(1, 13); |
dreamselec |
23:db91aaa43a9e | 484 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 485 | int button = 0; |
dreamselec |
23:db91aaa43a9e | 486 | bool finished = false; |
dreamselec |
23:db91aaa43a9e | 487 | do { |
dreamselec |
23:db91aaa43a9e | 488 | button = readSwitches(); |
dreamselec |
23:db91aaa43a9e | 489 | if (button == 1) { |
dreamselec |
23:db91aaa43a9e | 490 | fpga->toggleStoppingServo(); |
dreamselec |
23:db91aaa43a9e | 491 | printServoInfoOnLCD(); |
dreamselec |
23:db91aaa43a9e | 492 | printServoInfoOnPC(); |
dreamselec |
23:db91aaa43a9e | 493 | wait(kServoWait); |
dreamselec |
23:db91aaa43a9e | 494 | } else if (button == 2) { |
dreamselec |
23:db91aaa43a9e | 495 | fpga->toggleSortingServo(); |
dreamselec |
23:db91aaa43a9e | 496 | printServoInfoOnLCD(); |
dreamselec |
23:db91aaa43a9e | 497 | printServoInfoOnPC(); |
dreamselec |
23:db91aaa43a9e | 498 | wait(kServoWait); |
dreamselec |
23:db91aaa43a9e | 499 | } |
dreamselec |
23:db91aaa43a9e | 500 | finished = button == 4; |
dreamselec |
23:db91aaa43a9e | 501 | button = 0; |
dreamselec |
23:db91aaa43a9e | 502 | } while (finished == false && runServoTest == true); |
dreamselec |
23:db91aaa43a9e | 503 | |
dreamselec |
23:db91aaa43a9e | 504 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 505 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 506 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 507 | lcd->printf("Done servo test"); |
dreamselec |
23:db91aaa43a9e | 508 | if (runServoTest == true){ |
dreamselec |
23:db91aaa43a9e | 509 | pc.printf(":<servos>test=pause;"); |
dreamselec |
23:db91aaa43a9e | 510 | runServoTest = false; |
dreamselec |
23:db91aaa43a9e | 511 | } |
dreamselec |
23:db91aaa43a9e | 512 | wait(0.5); |
dreamselec |
23:db91aaa43a9e | 513 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 514 | return; |
dreamselec |
23:db91aaa43a9e | 515 | } |
dreamselec | 15:777390eb5afd | 516 | |
dreamselec |
23:db91aaa43a9e | 517 | void printBeamInfoOnLCD(){ |
dreamselec |
23:db91aaa43a9e | 518 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 519 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 520 | lcd->printf("Top:L1 Btm: L2"); |
dreamselec |
23:db91aaa43a9e | 521 | lcd->locate(1,0); |
dreamselec |
23:db91aaa43a9e | 522 | lcd->printf("On:High, Off:Low"); |
dreamselec |
23:db91aaa43a9e | 523 | } |
dreamselec |
23:db91aaa43a9e | 524 | |
dreamselec |
23:db91aaa43a9e | 525 | void printBeamInfoOnPC(int topBeam, int bottomBeam){ |
dreamselec |
23:db91aaa43a9e | 526 | pc.printf(":<break_beam>1=%i,2=%i;", topBeam, bottomBeam); |
dreamselec |
23:db91aaa43a9e | 527 | } |
dreamselec |
23:db91aaa43a9e | 528 | |
dreamselec |
23:db91aaa43a9e | 529 | void runInBreakBeamTestMode(){ |
dreamselec |
23:db91aaa43a9e | 530 | turnOffTopLEDs(); |
dreamselec |
23:db91aaa43a9e | 531 | i2cport->write_bit(1, 15); |
dreamselec |
23:db91aaa43a9e | 532 | |
dreamselec |
23:db91aaa43a9e | 533 | int topBeamValue = fpga->getBeamValue(1); |
dreamselec |
23:db91aaa43a9e | 534 | int bottomBeamValue = fpga->getBeamValue(2); |
dreamselec |
23:db91aaa43a9e | 535 | printBeamInfoOnPC(topBeamValue, bottomBeamValue); |
dreamselec |
23:db91aaa43a9e | 536 | printBeamInfoOnLCD(); |
dreamselec |
18:44a1c1a30166 | 537 | |
dreamselec |
23:db91aaa43a9e | 538 | int button = 0; |
dreamselec |
23:db91aaa43a9e | 539 | bool finished = false; |
dreamselec |
23:db91aaa43a9e | 540 | do{ |
dreamselec |
23:db91aaa43a9e | 541 | button = readSwitches(); |
dreamselec |
23:db91aaa43a9e | 542 | int currentTopBeamValue = fpga->getBeamValue(1); |
dreamselec |
23:db91aaa43a9e | 543 | int currentBottomBeamValue = fpga->getBeamValue(2); |
dreamselec | 24:02c61793f90b | 544 | |
dreamselec | 24:02c61793f90b | 545 | // For debugging, hold down both 1 and 3 or 2 and 3 |
dreamselec | 24:02c61793f90b | 546 | if (i2cport->read_bit(10) == 1){ |
dreamselec | 24:02c61793f90b | 547 | currentTopBeamValue = i2cport->read_bit(8) && i2cport->read_bit(10); |
dreamselec | 24:02c61793f90b | 548 | currentBottomBeamValue = i2cport->read_bit(9) && i2cport->read_bit(10); |
dreamselec | 24:02c61793f90b | 549 | } |
dreamselec |
23:db91aaa43a9e | 550 | myLED1 = currentTopBeamValue; |
dreamselec |
23:db91aaa43a9e | 551 | myLED2 = currentBottomBeamValue; |
dreamselec |
23:db91aaa43a9e | 552 | |
dreamselec |
23:db91aaa43a9e | 553 | if (currentTopBeamValue != topBeamValue || currentBottomBeamValue != bottomBeamValue ){ |
dreamselec |
23:db91aaa43a9e | 554 | topBeamValue = currentTopBeamValue; |
dreamselec |
23:db91aaa43a9e | 555 | bottomBeamValue = currentBottomBeamValue; |
dreamselec |
23:db91aaa43a9e | 556 | printBeamInfoOnPC(topBeamValue, bottomBeamValue); |
dreamselec |
23:db91aaa43a9e | 557 | } |
dreamselec |
23:db91aaa43a9e | 558 | finished = button == 4; |
dreamselec |
23:db91aaa43a9e | 559 | }while (runBreakBeamTest == true && finished == false); |
dreamselec |
23:db91aaa43a9e | 560 | |
dreamselec |
23:db91aaa43a9e | 561 | turnOffBottomLEDs(); |
dreamselec |
23:db91aaa43a9e | 562 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 563 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 564 | lcd->printf("Finished test"); |
dreamselec |
23:db91aaa43a9e | 565 | if (runBreakBeamTest == true){ |
dreamselec |
23:db91aaa43a9e | 566 | pc.printf(":<break_beam>test=pause;"); |
dreamselec |
23:db91aaa43a9e | 567 | runBreakBeamTest = false; |
dreamselec |
23:db91aaa43a9e | 568 | } |
dreamselec |
23:db91aaa43a9e | 569 | wait(0.5); |
dreamselec |
23:db91aaa43a9e | 570 | return; |
dreamselec | 2:7a55cb10259f | 571 | } |
dreamselec | 15:777390eb5afd | 572 | |
dreamselec | 15:777390eb5afd | 573 | void displayWaitingLine() |
dreamselec | 15:777390eb5afd | 574 | { |
dreamselec |
23:db91aaa43a9e | 575 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 576 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 577 | lcd->printf("Waiting..."); |
dreamselec |
23:db91aaa43a9e | 578 | lcd->locate(1,0); |
dreamselec | 15:777390eb5afd | 579 | } |
dreamselec | 15:777390eb5afd | 580 | |
dreamselec | 15:777390eb5afd | 581 | void displayPCStatus() |
dreamselec | 15:777390eb5afd | 582 | { |
dreamselec |
23:db91aaa43a9e | 583 | lcd->cls(); |
dreamselec |
23:db91aaa43a9e | 584 | lcd->locate(0,0); |
dreamselec |
23:db91aaa43a9e | 585 | if (connectedToPC) { |
dreamselec |
23:db91aaa43a9e | 586 | if (currentMode == Normal) |
dreamselec |
23:db91aaa43a9e | 587 | lcd->printf("Normal mode."); |
dreamselec |
23:db91aaa43a9e | 588 | else if (currentMode == Maintanence) |
dreamselec |
23:db91aaa43a9e | 589 | lcd->printf("Maintanence."); |
dreamselec |
23:db91aaa43a9e | 590 | else if (currentMode == None) |
dreamselec |
23:db91aaa43a9e | 591 | lcd->printf("Connected to PC"); |
dreamselec |
23:db91aaa43a9e | 592 | } else |
dreamselec |
23:db91aaa43a9e | 593 | lcd->printf("Waiting for PC.."); |
dreamselec | 15:777390eb5afd | 594 | |
dreamselec |
23:db91aaa43a9e | 595 | lcd->locate(1,0); |
dreamselec |
23:db91aaa43a9e | 596 | lcd->printf("4:Disconnect"); |
dreamselec |
23:db91aaa43a9e | 597 | D_LEDS_OFF(); |
dreamselec |
23:db91aaa43a9e | 598 | i2cport->write_bit(1,15); |
dreamselec |
18:44a1c1a30166 | 599 | } |
dreamselec |
23:db91aaa43a9e | 600 | |
dreamselec |
23:db91aaa43a9e | 601 | void turnOffTopLEDs(){ |
dreamselec |
23:db91aaa43a9e | 602 | myLED1 = 0; |
dreamselec |
23:db91aaa43a9e | 603 | myLED2 = 0; |
dreamselec |
23:db91aaa43a9e | 604 | myLED3 = 0; |
dreamselec |
23:db91aaa43a9e | 605 | myLED4 = 0; |
dreamselec |
23:db91aaa43a9e | 606 | } |
dreamselec |
23:db91aaa43a9e | 607 | |
dreamselec |
23:db91aaa43a9e | 608 | void turnOffBottomLEDs(){ |
dreamselec |
23:db91aaa43a9e | 609 | i2cport->write_bit(0, 12); |
dreamselec |
23:db91aaa43a9e | 610 | i2cport->write_bit(0, 13); |
dreamselec |
23:db91aaa43a9e | 611 | i2cport->write_bit(0, 14); |
dreamselec |
23:db91aaa43a9e | 612 | i2cport->write_bit(0, 15); |
dreamselec |
23:db91aaa43a9e | 613 | } |