1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include <stdio.h>
- #include <stdint.h>
- #define LEDS_COUNT 5
- #define BITS_PER_SUBCOLOR 8
- #define BITS_PER_COLOR (BITS_PER_SUBCOLOR*3)
- // uncomment this line to reverse bit order
- //#define BIT_ORDER_REVERSE
- // Set only one subcolor
- void gen_cmd_setc(uint8_t *buf, char c)
- {
- uint8_t b = 1;
- #ifdef BIT_ORDER_REVERSE
- uint8_t *p = buf;
- #else
- uint8_t *p = &buf[BITS_PER_SUBCOLOR-1];
- #endif
- while (b) {
- *p = c&b ? 14 : 8; // Why "14" and "8"? I have no idea! Ask AMGladtsin ;)
- #ifdef BIT_ORDER_REVERSE
- p++;
- #else
- p--;
- #endif
- b <<= 1;
- }
- return;
- }
- // Sets three subcolors to buf
- void gen_cmd_setrgb(uint8_t *buf, char r, char g, char b)
- {
- gen_cmd_setc( buf, r);
- gen_cmd_setc(&buf[ BITS_PER_SUBCOLOR], g);
- gen_cmd_setc(&buf[2*BITS_PER_SUBCOLOR], b);
- return;
- }
- int main()
- {
- uint8_t cmd[LEDS_COUNT][BITS_PER_COLOR];
- int i=0;
- while (i<LEDS_COUNT)
- gen_cmd_setrgb(cmd[i++], 255, 1, 128);
- /*
- int r = blahblah_Transmit(&someWhere, (uint8_t *)cmd, sizeof(cmd));
- if (r != HAL_OK) {
- blink_alaRRM_leds();
- }
- */
- { // DELETE ME
- int i=0;
- while (i < sizeof(cmd))
- printf("% 3i", ((uint8_t *)cmd)[i++]);
- printf("\n");
- }
- return 0;
- }
|