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@5:d7d16cb9c974, 2015-08-17 (annotated)
- Committer:
- tyleralt
- Date:
- Mon Aug 17 21:56:25 2015 +0000
- Revision:
- 5:d7d16cb9c974
- Parent:
- 4:f1e33a234a74
export commit;
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 | 5:d7d16cb9c974 | 3 | #define BUFFER_s 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 | 2:891b3618be4f | 9 | #include "Block.h" |
tyleralt | 0:ded79d89abdf | 10 | |
tyleralt | 0:ded79d89abdf | 11 | //write to arm pins |
tyleralt | 0:ded79d89abdf | 12 | DigitalOut pushRegister(p24); |
tyleralt | 0:ded79d89abdf | 13 | DigitalOut pushBit(p23); |
tyleralt | 0:ded79d89abdf | 14 | |
tyleralt | 0:ded79d89abdf | 15 | DigitalOut dataArmOne(p15); |
tyleralt | 0:ded79d89abdf | 16 | DigitalOut dataArmTwo(p16); |
tyleralt | 0:ded79d89abdf | 17 | DigitalOut dataArmThree(p17); |
tyleralt | 0:ded79d89abdf | 18 | DigitalOut dataArmFour(p18); |
tyleralt | 0:ded79d89abdf | 19 | DigitalOut dataArmFive(p19); |
tyleralt | 0:ded79d89abdf | 20 | DigitalOut dataArmSix(p20); |
tyleralt | 0:ded79d89abdf | 21 | DigitalOut dataArmSeven(p21); |
tyleralt | 0:ded79d89abdf | 22 | DigitalOut dataArmEight(p22); |
tyleralt | 0:ded79d89abdf | 23 | |
tyleralt | 0:ded79d89abdf | 24 | View :: View(){ |
tyleralt | 0:ded79d89abdf | 25 | |
tyleralt | 0:ded79d89abdf | 26 | current_slice = 0; |
tyleralt | 0:ded79d89abdf | 27 | |
tyleralt | 0:ded79d89abdf | 28 | } |
tyleralt | 0:ded79d89abdf | 29 | void View :: pushData (char bits [16]){ |
tyleralt | 0:ded79d89abdf | 30 | for (int i = 8; i < 16; i ++){ |
tyleralt | 0:ded79d89abdf | 31 | dataArmOne = bits [i] & 0x01; |
tyleralt | 0:ded79d89abdf | 32 | dataArmTwo = bits [i] & 0x02; |
tyleralt | 0:ded79d89abdf | 33 | dataArmThree = bits [i]& 0x04; |
tyleralt | 0:ded79d89abdf | 34 | dataArmFour = bits [i]& 0x08; |
tyleralt | 0:ded79d89abdf | 35 | dataArmFive = bits [i] & 0x10; |
tyleralt | 0:ded79d89abdf | 36 | dataArmSix = bits [i] & 0x20; |
tyleralt | 0:ded79d89abdf | 37 | dataArmSeven = bits [i] & 0x40; |
tyleralt | 0:ded79d89abdf | 38 | dataArmEight = bits [i] & 0x80; |
tyleralt | 0:ded79d89abdf | 39 | |
tyleralt | 0:ded79d89abdf | 40 | pushBit = 1; |
tyleralt | 0:ded79d89abdf | 41 | pushBit = 0; |
tyleralt | 0:ded79d89abdf | 42 | } |
tyleralt | 0:ded79d89abdf | 43 | for (int i = 7; i >= 0; i --){ |
tyleralt | 0:ded79d89abdf | 44 | dataArmOne = bits [i] & 0x01; |
tyleralt | 0:ded79d89abdf | 45 | dataArmTwo = bits [i] & 0x02; |
tyleralt | 0:ded79d89abdf | 46 | dataArmThree = bits [i]& 0x04; |
tyleralt | 0:ded79d89abdf | 47 | dataArmFour = bits [i]& 0x08; |
tyleralt | 0:ded79d89abdf | 48 | dataArmFive = bits [i] & 0x10; |
tyleralt | 0:ded79d89abdf | 49 | dataArmSix = bits [i] & 0x20; |
tyleralt | 0:ded79d89abdf | 50 | dataArmSeven = bits [i] & 0x40; |
tyleralt | 0:ded79d89abdf | 51 | dataArmEight = bits [i] & 0x80; |
tyleralt | 0:ded79d89abdf | 52 | |
tyleralt | 0:ded79d89abdf | 53 | pushBit = 1; |
tyleralt | 0:ded79d89abdf | 54 | pushBit = 0; |
tyleralt | 0:ded79d89abdf | 55 | } |
tyleralt | 0:ded79d89abdf | 56 | |
tyleralt | 0:ded79d89abdf | 57 | pushRegister = 1; |
tyleralt | 0:ded79d89abdf | 58 | pushRegister = 0; |
tyleralt | 0:ded79d89abdf | 59 | } |
tyleralt | 0:ded79d89abdf | 60 | |
tyleralt | 0:ded79d89abdf | 61 | |
tyleralt | 0:ded79d89abdf | 62 | void View:: nextLedPush(){ |
tyleralt | 0:ded79d89abdf | 63 | if (current_slice < NUMBER_OF_SLICES){ |
tyleralt | 0:ded79d89abdf | 64 | pushData(slice_data[current_slice]); |
tyleralt | 0:ded79d89abdf | 65 | current_slice ++; |
tyleralt | 0:ded79d89abdf | 66 | } |
tyleralt | 0:ded79d89abdf | 67 | } |
tyleralt | 0:ded79d89abdf | 68 | |
tyleralt | 0:ded79d89abdf | 69 | void View :: resetCount(void){ |
tyleralt | 0:ded79d89abdf | 70 | current_slice = 0; |
tyleralt | 0:ded79d89abdf | 71 | } |
tyleralt | 0:ded79d89abdf | 72 | void View :: resetDisplay(void){ |
tyleralt | 0:ded79d89abdf | 73 | for (int i = 0; i < 360; i ++){ |
tyleralt | 0:ded79d89abdf | 74 | for (int j = 0; j < 16; j++){ |
tyleralt | 0:ded79d89abdf | 75 | slice_data [i][j] = 0x00; |
tyleralt | 0:ded79d89abdf | 76 | } |
tyleralt | 0:ded79d89abdf | 77 | } |
tyleralt | 5:d7d16cb9c974 | 78 | //slice_data [1][1] = 0xFF; |
tyleralt | 0:ded79d89abdf | 79 | } |
tyleralt | 0:ded79d89abdf | 80 | void View :: addPoint(Point pointer){ |
tyleralt | 0:ded79d89abdf | 81 | int arrSlice = pointer.getArraySlice(); |
tyleralt | 0:ded79d89abdf | 82 | char c = pointer.getIdentifyingChar(); |
tyleralt | 0:ded79d89abdf | 83 | int distance = pointer.getPositionDistance(); |
tyleralt | 2:891b3618be4f | 84 | addValue(arrSlice, distance, c); |
tyleralt | 0:ded79d89abdf | 85 | } |
tyleralt | 0:ded79d89abdf | 86 | |
tyleralt | 2:891b3618be4f | 87 | void View :: addValue(int arrSlice, int distance, char c){ |
tyleralt | 4:f1e33a234a74 | 88 | if (distance >= 0 && distance < 16 && arrSlice < 360 && arrSlice >= 0){ |
tyleralt | 2:891b3618be4f | 89 | slice_data[arrSlice][distance] |= c; |
tyleralt | 2:891b3618be4f | 90 | } |
tyleralt | 2:891b3618be4f | 91 | } |
tyleralt | 1:bb1507f0bb64 | 92 | |
tyleralt | 5:d7d16cb9c974 | 93 | void View :: addFilledEucPoint(EuclidPoint euc){ |
tyleralt | 1:bb1507f0bb64 | 94 | int x = euc.x; |
tyleralt | 1:bb1507f0bb64 | 95 | int y = euc.y; |
tyleralt | 1:bb1507f0bb64 | 96 | Point pointer = euc.getPoint(); |
tyleralt | 1:bb1507f0bb64 | 97 | int arrSlice = pointer.getArraySlice(); |
tyleralt | 1:bb1507f0bb64 | 98 | char c = pointer.getIdentifyingChar(); |
tyleralt | 1:bb1507f0bb64 | 99 | int distance = pointer.getPositionDistance(); |
tyleralt | 1:bb1507f0bb64 | 100 | |
tyleralt | 2:891b3618be4f | 101 | addValue(arrSlice, distance, c); |
tyleralt | 5:d7d16cb9c974 | 102 | /* |
tyleralt | 5:d7d16cb9c974 | 103 | int degree = (atan2((double)y, (double)x)) * 57.295; |
tyleralt | 5:d7d16cb9c974 | 104 | if (degree < 0){ |
tyleralt | 5:d7d16cb9c974 | 105 | degree = 360 + degree; |
tyleralt | 5:d7d16cb9c974 | 106 | } |
tyleralt | 5:d7d16cb9c974 | 107 | double dradius = sqrt((double)(x * x ) + (double)(y * y)); |
tyleralt | 5:d7d16cb9c974 | 108 | int radius = rint(dradius) - 2; |
tyleralt | 5:d7d16cb9c974 | 109 | Point pointer = Point(degree, z, radius); |
tyleralt | 5:d7d16cb9c974 | 110 | return pointer; |
tyleralt | 5:d7d16cb9c974 | 111 | */ |
tyleralt | 5:d7d16cb9c974 | 112 | int orgDegree = pointer.getDegree(); |
tyleralt | 5:d7d16cb9c974 | 113 | int degree = orgDegree; |
tyleralt | 5:d7d16cb9c974 | 114 | int counter = 0; |
tyleralt | 5:d7d16cb9c974 | 115 | while (isAtPoint(distance + 2, degree, x, y) && counter < 15){ |
tyleralt | 5:d7d16cb9c974 | 116 | int newSlice = (arrSlice + counter) % 360; |
tyleralt | 5:d7d16cb9c974 | 117 | addValue(newSlice, distance, c); |
tyleralt | 5:d7d16cb9c974 | 118 | degree ++; |
tyleralt | 5:d7d16cb9c974 | 119 | counter ++; |
tyleralt | 5:d7d16cb9c974 | 120 | } |
tyleralt | 5:d7d16cb9c974 | 121 | degree = pointer.getDegree(); |
tyleralt | 5:d7d16cb9c974 | 122 | while (isAtPoint(distance + 2, degree, x, y) && counter > -15){ |
tyleralt | 5:d7d16cb9c974 | 123 | int newSlice = (arrSlice + counter) % 360; |
tyleralt | 5:d7d16cb9c974 | 124 | addValue(newSlice, distance, c); |
tyleralt | 5:d7d16cb9c974 | 125 | degree --; |
tyleralt | 5:d7d16cb9c974 | 126 | counter --; |
tyleralt | 5:d7d16cb9c974 | 127 | } |
tyleralt | 5:d7d16cb9c974 | 128 | /* |
tyleralt | 1:bb1507f0bb64 | 129 | int divider = 1 + ((distance)/ 4); |
tyleralt | 1:bb1507f0bb64 | 130 | int reach = rint((double)3 / divider); |
tyleralt | 1:bb1507f0bb64 | 131 | for (int i = 0 ; i < reach; i ++){ |
tyleralt | 2:891b3618be4f | 132 | addValue((arrSlice + i)%360, distance, c); |
tyleralt | 2:891b3618be4f | 133 | addValue((arrSlice - i)%360, distance, c); |
tyleralt | 0:ded79d89abdf | 134 | } |
tyleralt | 5:d7d16cb9c974 | 135 | */ |
tyleralt | 5:d7d16cb9c974 | 136 | } |
tyleralt | 5:d7d16cb9c974 | 137 | void View :: addEucPoint(EuclidPoint euc){ |
tyleralt | 5:d7d16cb9c974 | 138 | int x = euc.x; |
tyleralt | 5:d7d16cb9c974 | 139 | int y = euc.y; |
tyleralt | 5:d7d16cb9c974 | 140 | Point pointer = euc.getPoint(); |
tyleralt | 5:d7d16cb9c974 | 141 | int arrSlice = pointer.getArraySlice(); |
tyleralt | 5:d7d16cb9c974 | 142 | char c = pointer.getIdentifyingChar(); |
tyleralt | 5:d7d16cb9c974 | 143 | int distance = pointer.getPositionDistance(); |
tyleralt | 5:d7d16cb9c974 | 144 | addValue(arrSlice, distance, c); |
tyleralt | 5:d7d16cb9c974 | 145 | |
tyleralt | 5:d7d16cb9c974 | 146 | } |
tyleralt | 5:d7d16cb9c974 | 147 | |
tyleralt | 5:d7d16cb9c974 | 148 | bool View :: isAtPoint(int radius, int degree, int x, int y){ |
tyleralt | 5:d7d16cb9c974 | 149 | return (y == rint((double) radius * sin(degree/ 57.2957)) && x == rint((double) radius * cos(degree/57.2957))); |
tyleralt | 5:d7d16cb9c974 | 150 | |
tyleralt | 2:891b3618be4f | 151 | } |
tyleralt | 2:891b3618be4f | 152 | void View :: drawSquare (int x, int y, int z, int size){ |
tyleralt | 2:891b3618be4f | 153 | for(int i = 0; i < size; i++){ |
tyleralt | 2:891b3618be4f | 154 | addEucPoint(EuclidPoint(x + i, y , z )); |
tyleralt | 2:891b3618be4f | 155 | addEucPoint(EuclidPoint(x, y + i , z )); |
tyleralt | 2:891b3618be4f | 156 | addEucPoint(EuclidPoint(x + size , y + i , z )); |
tyleralt | 2:891b3618be4f | 157 | addEucPoint(EuclidPoint(x + i, y + size , z )); |
tyleralt | 1:bb1507f0bb64 | 158 | } |
tyleralt | 2:891b3618be4f | 159 | } |
tyleralt | 2:891b3618be4f | 160 | void View :: drawLine (int x, int y, int z, int size){ |
tyleralt | 2:891b3618be4f | 161 | for(int i = 0; i < size; i++){ |
tyleralt | 2:891b3618be4f | 162 | addEucPoint(EuclidPoint(x, y , z + i)); |
tyleralt | 1:bb1507f0bb64 | 163 | } |
tyleralt | 2:891b3618be4f | 164 | } |
tyleralt | 2:891b3618be4f | 165 | void View :: addBlock(Block block){ |
tyleralt | 2:891b3618be4f | 166 | drawSquare(block.x, block.y, block.z, block.size); |
tyleralt | 2:891b3618be4f | 167 | drawSquare(block.x, block.y, block.z + block.height, block.size ); |
tyleralt | 2:891b3618be4f | 168 | drawLine(block.x, block.y, block.z, block.height); |
tyleralt | 2:891b3618be4f | 169 | drawLine(block.x + block.size, block.y, block.z, block.height); |
tyleralt | 2:891b3618be4f | 170 | drawLine(block.x, block.y + block.size, block.z, block.height); |
tyleralt | 2:891b3618be4f | 171 | drawLine(block.x + block.size, block.y + block.size, block.z, block.height); |
tyleralt | 0:ded79d89abdf | 172 | } |
tyleralt | 0:ded79d89abdf | 173 | |
tyleralt | 0:ded79d89abdf | 174 | |
tyleralt | 0:ded79d89abdf | 175 | |
tyleralt | 0:ded79d89abdf | 176 | |
tyleralt | 0:ded79d89abdf | 177 | |
tyleralt | 0:ded79d89abdf | 178 | |
tyleralt | 1:bb1507f0bb64 | 179 |