Working version without LEDs
Voici le dernier schéma de cablage (version du 08/02/2020)
https://os.mbed.com/media/uploads/max_ence/schemarobot_fev2020.pdf
LED_WS2812/Pixel/PixelArray.cpp@1:69b5d8f0ba9c, 2020-05-30 (annotated)
- Committer:
- elab
- Date:
- Sat May 30 09:31:57 2020 +0000
- Revision:
- 1:69b5d8f0ba9c
- Parent:
- 0:0e577ce96b2f
pour eLab;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elab | 0:0e577ce96b2f | 1 | #include "PixelArray.h" |
elab | 0:0e577ce96b2f | 2 | |
elab | 0:0e577ce96b2f | 3 | PixelArray::PixelArray(int size) |
elab | 0:0e577ce96b2f | 4 | { |
elab | 0:0e577ce96b2f | 5 | pbufsize = size; |
elab | 0:0e577ce96b2f | 6 | pbuf = new int[pbufsize]; |
elab | 0:0e577ce96b2f | 7 | SetAll(0x0); // initialise memory to zeros |
elab | 0:0e577ce96b2f | 8 | |
elab | 0:0e577ce96b2f | 9 | } |
elab | 0:0e577ce96b2f | 10 | |
elab | 0:0e577ce96b2f | 11 | PixelArray::~PixelArray() |
elab | 0:0e577ce96b2f | 12 | { |
elab | 0:0e577ce96b2f | 13 | delete[] pbuf; |
elab | 0:0e577ce96b2f | 14 | } |
elab | 0:0e577ce96b2f | 15 | |
elab | 0:0e577ce96b2f | 16 | void PixelArray::SetAll(unsigned int value) |
elab | 0:0e577ce96b2f | 17 | { |
elab | 0:0e577ce96b2f | 18 | // for each pixel |
elab | 0:0e577ce96b2f | 19 | for (int i=0 ; i < pbufsize; i++) { |
elab | 0:0e577ce96b2f | 20 | __set_pixel(i,value); |
elab | 0:0e577ce96b2f | 21 | } |
elab | 0:0e577ce96b2f | 22 | } |
elab | 0:0e577ce96b2f | 23 | |
elab | 0:0e577ce96b2f | 24 | |
elab | 0:0e577ce96b2f | 25 | void PixelArray::SetAllI(unsigned char value) |
elab | 0:0e577ce96b2f | 26 | { |
elab | 0:0e577ce96b2f | 27 | // for each pixel |
elab | 0:0e577ce96b2f | 28 | for (int i=0 ; i < pbufsize; i++) { |
elab | 0:0e577ce96b2f | 29 | __set_pixel_component(i,3,value); |
elab | 0:0e577ce96b2f | 30 | } |
elab | 0:0e577ce96b2f | 31 | } |
elab | 0:0e577ce96b2f | 32 | |
elab | 0:0e577ce96b2f | 33 | |
elab | 0:0e577ce96b2f | 34 | |
elab | 0:0e577ce96b2f | 35 | void PixelArray::SetAllR(unsigned char value) |
elab | 0:0e577ce96b2f | 36 | { |
elab | 0:0e577ce96b2f | 37 | // for each pixel |
elab | 0:0e577ce96b2f | 38 | for (int i=0 ; i < pbufsize; i++) { |
elab | 0:0e577ce96b2f | 39 | __set_pixel_component(i,2,value); |
elab | 0:0e577ce96b2f | 40 | } |
elab | 0:0e577ce96b2f | 41 | } |
elab | 0:0e577ce96b2f | 42 | |
elab | 0:0e577ce96b2f | 43 | void PixelArray::SetAllG(unsigned char value) |
elab | 0:0e577ce96b2f | 44 | { |
elab | 0:0e577ce96b2f | 45 | // for each pixel |
elab | 0:0e577ce96b2f | 46 | for (int i=0 ; i < pbufsize; i++) { |
elab | 0:0e577ce96b2f | 47 | __set_pixel_component(i,1,value); |
elab | 0:0e577ce96b2f | 48 | } |
elab | 0:0e577ce96b2f | 49 | } |
elab | 0:0e577ce96b2f | 50 | |
elab | 0:0e577ce96b2f | 51 | void PixelArray::SetAllB(unsigned char value) |
elab | 0:0e577ce96b2f | 52 | { |
elab | 0:0e577ce96b2f | 53 | // for each pixel |
elab | 0:0e577ce96b2f | 54 | for (int i=0 ; i < pbufsize; i++) { |
elab | 0:0e577ce96b2f | 55 | __set_pixel_component(i,0,value); |
elab | 0:0e577ce96b2f | 56 | } |
elab | 0:0e577ce96b2f | 57 | } |
elab | 0:0e577ce96b2f | 58 | |
elab | 0:0e577ce96b2f | 59 | |
elab | 0:0e577ce96b2f | 60 | |
elab | 0:0e577ce96b2f | 61 | |
elab | 0:0e577ce96b2f | 62 | |
elab | 0:0e577ce96b2f | 63 | void PixelArray::Set(int i, unsigned int value) |
elab | 0:0e577ce96b2f | 64 | { |
elab | 0:0e577ce96b2f | 65 | if ((i >= 0) && (i < pbufsize)) { |
elab | 0:0e577ce96b2f | 66 | __set_pixel(i,value); |
elab | 0:0e577ce96b2f | 67 | } |
elab | 0:0e577ce96b2f | 68 | } |
elab | 0:0e577ce96b2f | 69 | |
elab | 0:0e577ce96b2f | 70 | |
elab | 0:0e577ce96b2f | 71 | |
elab | 0:0e577ce96b2f | 72 | void PixelArray::SetI(int i, unsigned char value) |
elab | 0:0e577ce96b2f | 73 | { |
elab | 0:0e577ce96b2f | 74 | if ((i >= 0) && (i < pbufsize)) { |
elab | 0:0e577ce96b2f | 75 | __set_pixel_component(i,3,value); |
elab | 0:0e577ce96b2f | 76 | } |
elab | 0:0e577ce96b2f | 77 | } |
elab | 0:0e577ce96b2f | 78 | |
elab | 0:0e577ce96b2f | 79 | |
elab | 0:0e577ce96b2f | 80 | void PixelArray::SetR(int i, unsigned char value) |
elab | 0:0e577ce96b2f | 81 | { |
elab | 0:0e577ce96b2f | 82 | if ((i >= 0) && (i < pbufsize)) { |
elab | 0:0e577ce96b2f | 83 | __set_pixel_component(i,2,value); |
elab | 0:0e577ce96b2f | 84 | } |
elab | 0:0e577ce96b2f | 85 | } |
elab | 0:0e577ce96b2f | 86 | |
elab | 0:0e577ce96b2f | 87 | void PixelArray::SetG(int i, unsigned char value) |
elab | 0:0e577ce96b2f | 88 | { |
elab | 0:0e577ce96b2f | 89 | if ((i >= 0) && (i < pbufsize)) { |
elab | 0:0e577ce96b2f | 90 | __set_pixel_component(i,1,value); |
elab | 0:0e577ce96b2f | 91 | } |
elab | 0:0e577ce96b2f | 92 | } |
elab | 0:0e577ce96b2f | 93 | |
elab | 0:0e577ce96b2f | 94 | void PixelArray::SetB(int i, unsigned char value) |
elab | 0:0e577ce96b2f | 95 | { |
elab | 0:0e577ce96b2f | 96 | if ((i >= 0) && (i < pbufsize)) { |
elab | 0:0e577ce96b2f | 97 | __set_pixel_component(i,0,value); |
elab | 0:0e577ce96b2f | 98 | } |
elab | 0:0e577ce96b2f | 99 | } |
elab | 0:0e577ce96b2f | 100 | |
elab | 0:0e577ce96b2f | 101 | |
elab | 0:0e577ce96b2f | 102 | unsigned int PixelArray::Get(int i) |
elab | 0:0e577ce96b2f | 103 | { |
elab | 0:0e577ce96b2f | 104 | return __get_pixel(i); |
elab | 0:0e577ce96b2f | 105 | } |
elab | 0:0e577ce96b2f | 106 | |
elab | 0:0e577ce96b2f | 107 | unsigned int PixelArray::GetI(int i) |
elab | 0:0e577ce96b2f | 108 | { |
elab | 0:0e577ce96b2f | 109 | return __get_pixel_component(i,3); |
elab | 0:0e577ce96b2f | 110 | } |
elab | 0:0e577ce96b2f | 111 | |
elab | 0:0e577ce96b2f | 112 | unsigned int PixelArray::GetR(int i) |
elab | 0:0e577ce96b2f | 113 | { |
elab | 0:0e577ce96b2f | 114 | return __get_pixel_component(i,2); |
elab | 0:0e577ce96b2f | 115 | } |
elab | 0:0e577ce96b2f | 116 | |
elab | 0:0e577ce96b2f | 117 | unsigned int PixelArray::GetG(int i) |
elab | 0:0e577ce96b2f | 118 | { |
elab | 0:0e577ce96b2f | 119 | return __get_pixel_component(i,1); |
elab | 0:0e577ce96b2f | 120 | } |
elab | 0:0e577ce96b2f | 121 | |
elab | 0:0e577ce96b2f | 122 | unsigned int PixelArray::GetB(int i) |
elab | 0:0e577ce96b2f | 123 | { |
elab | 0:0e577ce96b2f | 124 | return __get_pixel_component(i,0); |
elab | 0:0e577ce96b2f | 125 | } |
elab | 0:0e577ce96b2f | 126 | |
elab | 0:0e577ce96b2f | 127 | |
elab | 0:0e577ce96b2f | 128 | |
elab | 0:0e577ce96b2f | 129 | int* PixelArray::getBuf() |
elab | 0:0e577ce96b2f | 130 | { |
elab | 0:0e577ce96b2f | 131 | return (pbuf); |
elab | 0:0e577ce96b2f | 132 | } |
elab | 0:0e577ce96b2f | 133 | |
elab | 0:0e577ce96b2f | 134 | |
elab | 0:0e577ce96b2f | 135 | // set either the I,R,G,B value of specific pixel channel |
elab | 0:0e577ce96b2f | 136 | void PixelArray::__set_pixel_component(int index, int channel, int value) |
elab | 0:0e577ce96b2f | 137 | { |
elab | 0:0e577ce96b2f | 138 | |
elab | 0:0e577ce96b2f | 139 | // AND with 0x00 shifted to the right location to clear the bits |
elab | 0:0e577ce96b2f | 140 | pbuf[index] &= ~(0xFF << (8 * channel)); |
elab | 0:0e577ce96b2f | 141 | |
elab | 0:0e577ce96b2f | 142 | // Set the bits with an OR |
elab | 0:0e577ce96b2f | 143 | pbuf[index] |= (value << (8 * channel)); |
elab | 0:0e577ce96b2f | 144 | } |
elab | 0:0e577ce96b2f | 145 | |
elab | 0:0e577ce96b2f | 146 | |
elab | 0:0e577ce96b2f | 147 | // set either the I,R,G,B value of specific pixel channel |
elab | 0:0e577ce96b2f | 148 | void PixelArray::__set_pixel(int index, int value) |
elab | 0:0e577ce96b2f | 149 | { |
elab | 0:0e577ce96b2f | 150 | // AND with 0x00 shifted to the right location to clear the bits |
elab | 0:0e577ce96b2f | 151 | pbuf[index] = value; |
elab | 0:0e577ce96b2f | 152 | } |
elab | 0:0e577ce96b2f | 153 | |
elab | 0:0e577ce96b2f | 154 | |
elab | 0:0e577ce96b2f | 155 | // get specific pixel |
elab | 0:0e577ce96b2f | 156 | int PixelArray::__get_pixel(int index) |
elab | 0:0e577ce96b2f | 157 | { |
elab | 0:0e577ce96b2f | 158 | if ((index >= 0) && (index < pbufsize)) { |
elab | 0:0e577ce96b2f | 159 | return pbuf[index]; |
elab | 0:0e577ce96b2f | 160 | } else { |
elab | 0:0e577ce96b2f | 161 | return 0; |
elab | 0:0e577ce96b2f | 162 | } |
elab | 0:0e577ce96b2f | 163 | } |
elab | 0:0e577ce96b2f | 164 | |
elab | 0:0e577ce96b2f | 165 | |
elab | 0:0e577ce96b2f | 166 | // get specific pixel |
elab | 0:0e577ce96b2f | 167 | int PixelArray::__get_pixel_component(int index, int channel) |
elab | 0:0e577ce96b2f | 168 | { |
elab | 0:0e577ce96b2f | 169 | // AND with 0xFF shifted to the right location to get the bits |
elab | 0:0e577ce96b2f | 170 | return ( (__get_pixel(index) & (0xFF << (8 * channel))) >> (8*channel) ); |
elab | 0:0e577ce96b2f | 171 | } |
elab | 0:0e577ce96b2f | 172 | |
elab | 0:0e577ce96b2f | 173 |