diodes.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #define LEDS_COUNT 5
  4. #define BITS_PER_SUBCOLOR 8
  5. #define BITS_PER_COLOR (BITS_PER_SUBCOLOR*3)
  6. // uncomment this line to reverse bit order
  7. //#define BIT_ORDER_REVERSE
  8. // Set only one subcolor
  9. void gen_cmd_setc(uint8_t *buf, char c)
  10. {
  11. uint8_t b = 1;
  12. #ifdef BIT_ORDER_REVERSE
  13. uint8_t *p = buf;
  14. #else
  15. uint8_t *p = &buf[BITS_PER_SUBCOLOR-1];
  16. #endif
  17. while (b) {
  18. *p = c&b ? 14 : 8; // Why "14" and "8"? I have no idea! Ask AMGladtsin ;)
  19. #ifdef BIT_ORDER_REVERSE
  20. p++;
  21. #else
  22. p--;
  23. #endif
  24. b <<= 1;
  25. }
  26. return;
  27. }
  28. // Sets three subcolors to buf
  29. void gen_cmd_setrgb(uint8_t *buf, char r, char g, char b)
  30. {
  31. gen_cmd_setc( buf, r);
  32. gen_cmd_setc(&buf[ BITS_PER_SUBCOLOR], g);
  33. gen_cmd_setc(&buf[2*BITS_PER_SUBCOLOR], b);
  34. return;
  35. }
  36. int main()
  37. {
  38. uint8_t cmd[LEDS_COUNT][BITS_PER_COLOR];
  39. int i=0;
  40. while (i<LEDS_COUNT)
  41. gen_cmd_setrgb(cmd[i++], 255, 1, 128);
  42. /*
  43. int r = blahblah_Transmit(&someWhere, (uint8_t *)cmd, sizeof(cmd));
  44. if (r != HAL_OK) {
  45. blink_alaRRM_leds();
  46. }
  47. */
  48. { // DELETE ME
  49. int i=0;
  50. while (i < sizeof(cmd))
  51. printf("% 3i", ((uint8_t *)cmd)[i++]);
  52. printf("\n");
  53. }
  54. return 0;
  55. }