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.
main.cpp@0:ded79d89abdf, 2015-05-01 (annotated)
- Committer:
- tyleralt
- Date:
- Fri May 01 05:33:50 2015 +0000
- Revision:
- 0:ded79d89abdf
- Child:
- 1:bb1507f0bb64
geting Frist crossing and second not working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tyleralt | 0:ded79d89abdf | 1 | #include "mbed.h" |
tyleralt | 0:ded79d89abdf | 2 | #include <vector> |
tyleralt | 0:ded79d89abdf | 3 | #define BUFFER_SIZE 16 |
tyleralt | 0:ded79d89abdf | 4 | #define NUMBER_OF_SLICES 360 |
tyleralt | 0:ded79d89abdf | 5 | #include "Point.h" |
tyleralt | 0:ded79d89abdf | 6 | #include "View.h" |
tyleralt | 0:ded79d89abdf | 7 | |
tyleralt | 0:ded79d89abdf | 8 | |
tyleralt | 0:ded79d89abdf | 9 | //hass sensor interupt |
tyleralt | 0:ded79d89abdf | 10 | InterruptIn hallSensor(p25); |
tyleralt | 0:ded79d89abdf | 11 | |
tyleralt | 0:ded79d89abdf | 12 | //Set Up Timer and ticker |
tyleralt | 0:ded79d89abdf | 13 | Timer rotationTime; |
tyleralt | 0:ded79d89abdf | 14 | Ticker updateLeds; |
tyleralt | 0:ded79d89abdf | 15 | |
tyleralt | 0:ded79d89abdf | 16 | //Declare global vars |
tyleralt | 0:ded79d89abdf | 17 | double slice_time; |
tyleralt | 0:ded79d89abdf | 18 | double rotate_time; |
tyleralt | 0:ded79d89abdf | 19 | int current_slice; |
tyleralt | 0:ded79d89abdf | 20 | bool firstTime; |
tyleralt | 0:ded79d89abdf | 21 | |
tyleralt | 0:ded79d89abdf | 22 | enum DisplayMode {lineDraw, map, eucDraw}; |
tyleralt | 0:ded79d89abdf | 23 | |
tyleralt | 0:ded79d89abdf | 24 | DisplayMode mode; |
tyleralt | 0:ded79d89abdf | 25 | |
tyleralt | 0:ded79d89abdf | 26 | Point pointer; |
tyleralt | 0:ded79d89abdf | 27 | EuclidPoint eucPointer; |
tyleralt | 0:ded79d89abdf | 28 | //the View |
tyleralt | 0:ded79d89abdf | 29 | View display; |
tyleralt | 0:ded79d89abdf | 30 | |
tyleralt | 0:ded79d89abdf | 31 | |
tyleralt | 0:ded79d89abdf | 32 | |
tyleralt | 0:ded79d89abdf | 33 | |
tyleralt | 0:ded79d89abdf | 34 | //serial port for pc and bluetooth |
tyleralt | 0:ded79d89abdf | 35 | Serial pc(USBTX, USBRX); // tx, rx |
tyleralt | 0:ded79d89abdf | 36 | Serial bt(p9, p10);// tx, rx |
tyleralt | 0:ded79d89abdf | 37 | |
tyleralt | 0:ded79d89abdf | 38 | void rotate_sense(){ |
tyleralt | 0:ded79d89abdf | 39 | if (firstTime){ |
tyleralt | 0:ded79d89abdf | 40 | rotationTime.reset(); |
tyleralt | 0:ded79d89abdf | 41 | rotationTime.start(); |
tyleralt | 0:ded79d89abdf | 42 | firstTime = false; |
tyleralt | 0:ded79d89abdf | 43 | display.current_slice = 180; |
tyleralt | 0:ded79d89abdf | 44 | return; |
tyleralt | 0:ded79d89abdf | 45 | } |
tyleralt | 0:ded79d89abdf | 46 | if(display.current_slice < NUMBER_OF_SLICES / 4){ |
tyleralt | 0:ded79d89abdf | 47 | return; |
tyleralt | 0:ded79d89abdf | 48 | } |
tyleralt | 0:ded79d89abdf | 49 | rotate_time = rotationTime.read_us(); |
tyleralt | 0:ded79d89abdf | 50 | rotationTime.reset(); |
tyleralt | 0:ded79d89abdf | 51 | rotationTime.start(); |
tyleralt | 0:ded79d89abdf | 52 | slice_time = (double) rotate_time/NUMBER_OF_SLICES; |
tyleralt | 0:ded79d89abdf | 53 | display.resetCount(); |
tyleralt | 0:ded79d89abdf | 54 | updateLeds.attach_us(&display, &View::nextLedPush, slice_time); |
tyleralt | 0:ded79d89abdf | 55 | } |
tyleralt | 0:ded79d89abdf | 56 | void moveUp(); |
tyleralt | 0:ded79d89abdf | 57 | void moveDown(); |
tyleralt | 0:ded79d89abdf | 58 | void rotateRight(); |
tyleralt | 0:ded79d89abdf | 59 | void rotateLeft(); |
tyleralt | 0:ded79d89abdf | 60 | void moveIn(); |
tyleralt | 0:ded79d89abdf | 61 | void moveOut(); |
tyleralt | 0:ded79d89abdf | 62 | |
tyleralt | 0:ded79d89abdf | 63 | void parseLineMode(char c){ |
tyleralt | 0:ded79d89abdf | 64 | switch(c){ |
tyleralt | 0:ded79d89abdf | 65 | case 'w': |
tyleralt | 0:ded79d89abdf | 66 | pointer.moveOut(); |
tyleralt | 0:ded79d89abdf | 67 | break; |
tyleralt | 0:ded79d89abdf | 68 | case 's': |
tyleralt | 0:ded79d89abdf | 69 | pointer.moveIn(); |
tyleralt | 0:ded79d89abdf | 70 | break; |
tyleralt | 0:ded79d89abdf | 71 | case 'a': |
tyleralt | 0:ded79d89abdf | 72 | pointer.rotateRight(); |
tyleralt | 0:ded79d89abdf | 73 | break; |
tyleralt | 0:ded79d89abdf | 74 | case 'd': |
tyleralt | 0:ded79d89abdf | 75 | pointer.rotateLeft(); |
tyleralt | 0:ded79d89abdf | 76 | break; |
tyleralt | 0:ded79d89abdf | 77 | case 'p': |
tyleralt | 0:ded79d89abdf | 78 | pointer.moveUp(); |
tyleralt | 0:ded79d89abdf | 79 | break; |
tyleralt | 0:ded79d89abdf | 80 | case 'l': |
tyleralt | 0:ded79d89abdf | 81 | pointer.moveDown(); |
tyleralt | 0:ded79d89abdf | 82 | break; |
tyleralt | 0:ded79d89abdf | 83 | default: return; |
tyleralt | 0:ded79d89abdf | 84 | } |
tyleralt | 0:ded79d89abdf | 85 | display.addPoint(pointer); |
tyleralt | 0:ded79d89abdf | 86 | } |
tyleralt | 0:ded79d89abdf | 87 | |
tyleralt | 0:ded79d89abdf | 88 | void parseMapMode(char c){ |
tyleralt | 0:ded79d89abdf | 89 | |
tyleralt | 0:ded79d89abdf | 90 | } |
tyleralt | 0:ded79d89abdf | 91 | void parseEucMode(char c){ |
tyleralt | 0:ded79d89abdf | 92 | bt.printf("parseing EucMode"); |
tyleralt | 0:ded79d89abdf | 93 | switch(c){ |
tyleralt | 0:ded79d89abdf | 94 | case 'w': |
tyleralt | 0:ded79d89abdf | 95 | eucPointer.moveAway(); |
tyleralt | 0:ded79d89abdf | 96 | break; |
tyleralt | 0:ded79d89abdf | 97 | case 's': |
tyleralt | 0:ded79d89abdf | 98 | eucPointer.moveTowards(); |
tyleralt | 0:ded79d89abdf | 99 | break; |
tyleralt | 0:ded79d89abdf | 100 | case 'a': |
tyleralt | 0:ded79d89abdf | 101 | eucPointer.moveLeft(); |
tyleralt | 0:ded79d89abdf | 102 | break; |
tyleralt | 0:ded79d89abdf | 103 | case 'd': |
tyleralt | 0:ded79d89abdf | 104 | eucPointer.moveRight(); |
tyleralt | 0:ded79d89abdf | 105 | break; |
tyleralt | 0:ded79d89abdf | 106 | case 'p': |
tyleralt | 0:ded79d89abdf | 107 | eucPointer.moveUp(); |
tyleralt | 0:ded79d89abdf | 108 | break; |
tyleralt | 0:ded79d89abdf | 109 | case 'l': |
tyleralt | 0:ded79d89abdf | 110 | eucPointer.moveDown(); |
tyleralt | 0:ded79d89abdf | 111 | break; |
tyleralt | 0:ded79d89abdf | 112 | default: return; |
tyleralt | 0:ded79d89abdf | 113 | } |
tyleralt | 0:ded79d89abdf | 114 | Point startPoint = eucPointer.getStartPoint(); |
tyleralt | 0:ded79d89abdf | 115 | Point endPoint = eucPointer.getEndPoint(); |
tyleralt | 0:ded79d89abdf | 116 | bt.printf("\r\n"); |
tyleralt | 0:ded79d89abdf | 117 | bt.printf("points%i , %i , %X \r\n", eucPointer.x, eucPointer.y,eucPointer.z); |
tyleralt | 0:ded79d89abdf | 118 | bt.printf("drawingEucPointer Starting %i , %i , %X \r\n", startPoint.getArraySlice(), startPoint.getPositionDistance(),startPoint.getIdentifyingChar()); |
tyleralt | 0:ded79d89abdf | 119 | bt.printf("drawingEucPointer Ending %i , %i , %X \r\n", endPoint.getArraySlice(), endPoint.getPositionDistance(),endPoint.getIdentifyingChar()); |
tyleralt | 0:ded79d89abdf | 120 | |
tyleralt | 0:ded79d89abdf | 121 | display.addEucPoint(eucPointer); |
tyleralt | 0:ded79d89abdf | 122 | } |
tyleralt | 0:ded79d89abdf | 123 | |
tyleralt | 0:ded79d89abdf | 124 | void parseBt(char c){ |
tyleralt | 0:ded79d89abdf | 125 | if (c == 'm'){ |
tyleralt | 0:ded79d89abdf | 126 | switch (c){ |
tyleralt | 0:ded79d89abdf | 127 | case(lineDraw):{ |
tyleralt | 0:ded79d89abdf | 128 | mode = eucDraw; |
tyleralt | 0:ded79d89abdf | 129 | bt.printf("we are drawing Euclidian"); |
tyleralt | 0:ded79d89abdf | 130 | break; |
tyleralt | 0:ded79d89abdf | 131 | } |
tyleralt | 0:ded79d89abdf | 132 | case(map):{ |
tyleralt | 0:ded79d89abdf | 133 | mode = lineDraw; |
tyleralt | 0:ded79d89abdf | 134 | bt.printf("we are drawing Radians"); |
tyleralt | 0:ded79d89abdf | 135 | break; |
tyleralt | 0:ded79d89abdf | 136 | } |
tyleralt | 0:ded79d89abdf | 137 | case(eucDraw):{ |
tyleralt | 0:ded79d89abdf | 138 | mode = map; |
tyleralt | 0:ded79d89abdf | 139 | bt.printf("we are on a Map"); |
tyleralt | 0:ded79d89abdf | 140 | break; |
tyleralt | 0:ded79d89abdf | 141 | } |
tyleralt | 0:ded79d89abdf | 142 | default: { |
tyleralt | 0:ded79d89abdf | 143 | return; |
tyleralt | 0:ded79d89abdf | 144 | } |
tyleralt | 0:ded79d89abdf | 145 | } |
tyleralt | 0:ded79d89abdf | 146 | return; |
tyleralt | 0:ded79d89abdf | 147 | } |
tyleralt | 0:ded79d89abdf | 148 | |
tyleralt | 0:ded79d89abdf | 149 | if (mode == lineDraw){ |
tyleralt | 0:ded79d89abdf | 150 | parseLineMode(c); |
tyleralt | 0:ded79d89abdf | 151 | } |
tyleralt | 0:ded79d89abdf | 152 | if (mode == map){ |
tyleralt | 0:ded79d89abdf | 153 | parseMapMode(c); |
tyleralt | 0:ded79d89abdf | 154 | } |
tyleralt | 0:ded79d89abdf | 155 | if (mode == eucDraw){ |
tyleralt | 0:ded79d89abdf | 156 | parseEucMode(c); |
tyleralt | 0:ded79d89abdf | 157 | } |
tyleralt | 0:ded79d89abdf | 158 | } |
tyleralt | 0:ded79d89abdf | 159 | |
tyleralt | 0:ded79d89abdf | 160 | |
tyleralt | 0:ded79d89abdf | 161 | |
tyleralt | 0:ded79d89abdf | 162 | int main() { |
tyleralt | 0:ded79d89abdf | 163 | pc.printf("started"); |
tyleralt | 0:ded79d89abdf | 164 | bt.printf("bluetooth started"); |
tyleralt | 0:ded79d89abdf | 165 | mode = eucDraw; |
tyleralt | 0:ded79d89abdf | 166 | firstTime = true; |
tyleralt | 0:ded79d89abdf | 167 | current_slice = 100; |
tyleralt | 0:ded79d89abdf | 168 | display.resetDisplay(); |
tyleralt | 0:ded79d89abdf | 169 | |
tyleralt | 0:ded79d89abdf | 170 | hallSensor.fall(&rotate_sense); |
tyleralt | 0:ded79d89abdf | 171 | |
tyleralt | 0:ded79d89abdf | 172 | while(true) { |
tyleralt | 0:ded79d89abdf | 173 | if (bt.readable()){ |
tyleralt | 0:ded79d89abdf | 174 | parseBt(bt.getc()); |
tyleralt | 0:ded79d89abdf | 175 | } |
tyleralt | 0:ded79d89abdf | 176 | } |
tyleralt | 0:ded79d89abdf | 177 | } |