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.
View.cpp@1:bb1507f0bb64, 2015-05-01 (annotated)
- Committer:
- tyleralt
- Date:
- Fri May 01 09:22:50 2015 +0000
- Revision:
- 1:bb1507f0bb64
- Parent:
- 0:ded79d89abdf
- Child:
- 2:891b3618be4f
everything but map 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 "View.h" |
tyleralt | 0:ded79d89abdf | 6 | #include "Point.h" |
tyleralt | 0:ded79d89abdf | 7 | #include "EuclidPoint.h" |
tyleralt | 1:bb1507f0bb64 | 8 | #include <math.h> |
tyleralt | 0:ded79d89abdf | 9 | |
tyleralt | 0:ded79d89abdf | 10 | //write to arm pins |
tyleralt | 0:ded79d89abdf | 11 | DigitalOut pushRegister(p24); |
tyleralt | 0:ded79d89abdf | 12 | DigitalOut pushBit(p23); |
tyleralt | 0:ded79d89abdf | 13 | |
tyleralt | 0:ded79d89abdf | 14 | DigitalOut dataArmOne(p15); |
tyleralt | 0:ded79d89abdf | 15 | DigitalOut dataArmTwo(p16); |
tyleralt | 0:ded79d89abdf | 16 | DigitalOut dataArmThree(p17); |
tyleralt | 0:ded79d89abdf | 17 | DigitalOut dataArmFour(p18); |
tyleralt | 0:ded79d89abdf | 18 | DigitalOut dataArmFive(p19); |
tyleralt | 0:ded79d89abdf | 19 | DigitalOut dataArmSix(p20); |
tyleralt | 0:ded79d89abdf | 20 | DigitalOut dataArmSeven(p21); |
tyleralt | 0:ded79d89abdf | 21 | DigitalOut dataArmEight(p22); |
tyleralt | 0:ded79d89abdf | 22 | |
tyleralt | 0:ded79d89abdf | 23 | View :: View(){ |
tyleralt | 0:ded79d89abdf | 24 | |
tyleralt | 0:ded79d89abdf | 25 | current_slice = 0; |
tyleralt | 0:ded79d89abdf | 26 | |
tyleralt | 0:ded79d89abdf | 27 | } |
tyleralt | 0:ded79d89abdf | 28 | void View :: pushData (char bits [16]){ |
tyleralt | 0:ded79d89abdf | 29 | for (int i = 8; i < 16; i ++){ |
tyleralt | 0:ded79d89abdf | 30 | dataArmOne = bits [i] & 0x01; |
tyleralt | 0:ded79d89abdf | 31 | dataArmTwo = bits [i] & 0x02; |
tyleralt | 0:ded79d89abdf | 32 | dataArmThree = bits [i]& 0x04; |
tyleralt | 0:ded79d89abdf | 33 | dataArmFour = bits [i]& 0x08; |
tyleralt | 0:ded79d89abdf | 34 | dataArmFive = bits [i] & 0x10; |
tyleralt | 0:ded79d89abdf | 35 | dataArmSix = bits [i] & 0x20; |
tyleralt | 0:ded79d89abdf | 36 | dataArmSeven = bits [i] & 0x40; |
tyleralt | 0:ded79d89abdf | 37 | dataArmEight = bits [i] & 0x80; |
tyleralt | 0:ded79d89abdf | 38 | |
tyleralt | 0:ded79d89abdf | 39 | pushBit = 1; |
tyleralt | 0:ded79d89abdf | 40 | pushBit = 0; |
tyleralt | 0:ded79d89abdf | 41 | } |
tyleralt | 0:ded79d89abdf | 42 | for (int i = 7; i >= 0; i --){ |
tyleralt | 0:ded79d89abdf | 43 | dataArmOne = bits [i] & 0x01; |
tyleralt | 0:ded79d89abdf | 44 | dataArmTwo = bits [i] & 0x02; |
tyleralt | 0:ded79d89abdf | 45 | dataArmThree = bits [i]& 0x04; |
tyleralt | 0:ded79d89abdf | 46 | dataArmFour = bits [i]& 0x08; |
tyleralt | 0:ded79d89abdf | 47 | dataArmFive = bits [i] & 0x10; |
tyleralt | 0:ded79d89abdf | 48 | dataArmSix = bits [i] & 0x20; |
tyleralt | 0:ded79d89abdf | 49 | dataArmSeven = bits [i] & 0x40; |
tyleralt | 0:ded79d89abdf | 50 | dataArmEight = bits [i] & 0x80; |
tyleralt | 0:ded79d89abdf | 51 | |
tyleralt | 0:ded79d89abdf | 52 | pushBit = 1; |
tyleralt | 0:ded79d89abdf | 53 | pushBit = 0; |
tyleralt | 0:ded79d89abdf | 54 | } |
tyleralt | 0:ded79d89abdf | 55 | |
tyleralt | 0:ded79d89abdf | 56 | pushRegister = 1; |
tyleralt | 0:ded79d89abdf | 57 | pushRegister = 0; |
tyleralt | 0:ded79d89abdf | 58 | } |
tyleralt | 0:ded79d89abdf | 59 | |
tyleralt | 0:ded79d89abdf | 60 | |
tyleralt | 0:ded79d89abdf | 61 | void View:: nextLedPush(){ |
tyleralt | 0:ded79d89abdf | 62 | if (current_slice < NUMBER_OF_SLICES){ |
tyleralt | 0:ded79d89abdf | 63 | pushData(slice_data[current_slice]); |
tyleralt | 0:ded79d89abdf | 64 | current_slice ++; |
tyleralt | 0:ded79d89abdf | 65 | } |
tyleralt | 0:ded79d89abdf | 66 | } |
tyleralt | 0:ded79d89abdf | 67 | |
tyleralt | 0:ded79d89abdf | 68 | void View :: resetCount(void){ |
tyleralt | 0:ded79d89abdf | 69 | current_slice = 0; |
tyleralt | 0:ded79d89abdf | 70 | } |
tyleralt | 0:ded79d89abdf | 71 | void View :: resetDisplay(void){ |
tyleralt | 0:ded79d89abdf | 72 | for (int i = 0; i < 360; i ++){ |
tyleralt | 0:ded79d89abdf | 73 | for (int j = 0; j < 16; j++){ |
tyleralt | 0:ded79d89abdf | 74 | slice_data [i][j] = 0x00; |
tyleralt | 0:ded79d89abdf | 75 | } |
tyleralt | 0:ded79d89abdf | 76 | } |
tyleralt | 0:ded79d89abdf | 77 | slice_data [1][1] = 0xFF; |
tyleralt | 0:ded79d89abdf | 78 | } |
tyleralt | 0:ded79d89abdf | 79 | void View :: addPoint(Point pointer){ |
tyleralt | 0:ded79d89abdf | 80 | int arrSlice = pointer.getArraySlice(); |
tyleralt | 0:ded79d89abdf | 81 | char c = pointer.getIdentifyingChar(); |
tyleralt | 0:ded79d89abdf | 82 | int distance = pointer.getPositionDistance(); |
tyleralt | 1:bb1507f0bb64 | 83 | slice_data[arrSlice][distance] |= c; |
tyleralt | 0:ded79d89abdf | 84 | } |
tyleralt | 0:ded79d89abdf | 85 | |
tyleralt | 1:bb1507f0bb64 | 86 | |
tyleralt | 0:ded79d89abdf | 87 | void View :: addEucPoint(EuclidPoint euc){ |
tyleralt | 1:bb1507f0bb64 | 88 | int x = euc.x; |
tyleralt | 1:bb1507f0bb64 | 89 | int y = euc.y; |
tyleralt | 1:bb1507f0bb64 | 90 | Point pointer = euc.getPoint(); |
tyleralt | 1:bb1507f0bb64 | 91 | int arrSlice = pointer.getArraySlice(); |
tyleralt | 1:bb1507f0bb64 | 92 | char c = pointer.getIdentifyingChar(); |
tyleralt | 1:bb1507f0bb64 | 93 | int distance = pointer.getPositionDistance(); |
tyleralt | 1:bb1507f0bb64 | 94 | |
tyleralt | 1:bb1507f0bb64 | 95 | |
tyleralt | 1:bb1507f0bb64 | 96 | slice_data[arrSlice][distance] |= c; |
tyleralt | 1:bb1507f0bb64 | 97 | |
tyleralt | 1:bb1507f0bb64 | 98 | int divider = 1 + ((distance)/ 4); |
tyleralt | 1:bb1507f0bb64 | 99 | int reach = rint((double)3 / divider); |
tyleralt | 1:bb1507f0bb64 | 100 | for (int i = 0 ; i < reach; i ++){ |
tyleralt | 1:bb1507f0bb64 | 101 | slice_data [(arrSlice + i)%360][distance] |= c; |
tyleralt | 1:bb1507f0bb64 | 102 | slice_data [(arrSlice - i)%360][distance] |= c; |
tyleralt | 0:ded79d89abdf | 103 | } |
tyleralt | 1:bb1507f0bb64 | 104 | |
tyleralt | 1:bb1507f0bb64 | 105 | |
tyleralt | 1:bb1507f0bb64 | 106 | |
tyleralt | 1:bb1507f0bb64 | 107 | /* |
tyleralt | 1:bb1507f0bb64 | 108 | int changeDeg = arrSlice; |
tyleralt | 1:bb1507f0bb64 | 109 | double deg = (double) changeDeg / 57.295; |
tyleralt | 1:bb1507f0bb64 | 110 | |
tyleralt | 1:bb1507f0bb64 | 111 | while ( ((sin (deg) * (distance + 1)) - y == 0 && (int) (cos (deg) * (distance + 1)) - x == 0)){ |
tyleralt | 1:bb1507f0bb64 | 112 | slice_data[change][distance] |= c; |
tyleralt | 1:bb1507f0bb64 | 113 | changeDeg ++; |
tyleralt | 1:bb1507f0bb64 | 114 | double deg = (double) changeDeg / 57.295; |
tyleralt | 1:bb1507f0bb64 | 115 | } |
tyleralt | 1:bb1507f0bb64 | 116 | |
tyleralt | 1:bb1507f0bb64 | 117 | |
tyleralt | 1:bb1507f0bb64 | 118 | |
tyleralt | 1:bb1507f0bb64 | 119 | changeDeg = arrSlice; |
tyleralt | 1:bb1507f0bb64 | 120 | deg = (double) changeDeg / 57.295; |
tyleralt | 1:bb1507f0bb64 | 121 | |
tyleralt | 1:bb1507f0bb64 | 122 | while ( (int) (sin (deg) * (distance + 1)) - y == 0 && (int) (cos (deg) * (distance + 1)) - x == 0){ |
tyleralt | 1:bb1507f0bb64 | 123 | slice_data[change][distance] |= c; |
tyleralt | 1:bb1507f0bb64 | 124 | changeDeg --; |
tyleralt | 1:bb1507f0bb64 | 125 | double deg = (double) changeDeg / 57.295; |
tyleralt | 1:bb1507f0bb64 | 126 | } |
tyleralt | 1:bb1507f0bb64 | 127 | while ( tan(arrSlice / 57.295) == ((double) y / x) || (int) tan(arrSlice / 57.295) == (int) ((double) -y / x)){ |
tyleralt | 1:bb1507f0bb64 | 128 | slice_data[change][distance] |= c; |
tyleralt | 1:bb1507f0bb64 | 129 | change ++; |
tyleralt | 1:bb1507f0bb64 | 130 | } |
tyleralt | 1:bb1507f0bb64 | 131 | change = arrSlice; |
tyleralt | 1:bb1507f0bb64 | 132 | //while ((int) (sin(change / 57.295) * distance) == x && (int)(cos (change / 57.295) * distance)== y){ |
tyleralt | 1:bb1507f0bb64 | 133 | while ( (int) tan(arrSlice / 57.295) == (int) ((double) y / x) || (int) tan(arrSlice / 57.295) == (int) ((double) -y / x)){ |
tyleralt | 1:bb1507f0bb64 | 134 | slice_data[change][distance] |= c; |
tyleralt | 1:bb1507f0bb64 | 135 | change --; |
tyleralt | 1:bb1507f0bb64 | 136 | } |
tyleralt | 1:bb1507f0bb64 | 137 | */ |
tyleralt | 1:bb1507f0bb64 | 138 | |
tyleralt | 0:ded79d89abdf | 139 | } |
tyleralt | 0:ded79d89abdf | 140 | |
tyleralt | 0:ded79d89abdf | 141 | |
tyleralt | 0:ded79d89abdf | 142 | |
tyleralt | 0:ded79d89abdf | 143 | |
tyleralt | 0:ded79d89abdf | 144 | |
tyleralt | 0:ded79d89abdf | 145 | |
tyleralt | 1:bb1507f0bb64 | 146 |