MPM controlled 16ch RGB LED dimmer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

democode.c 5.3KB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /***************************************************************************
  2. * some RGB demo modes *
  3. * *
  4. * Copyright (C) 2011 - 2012 by Olaf Rempel *
  5. * razzor AT kopf MINUS tisch DOT de *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; version 2 of the License, *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, write to the *
  18. * Free Software Foundation, Inc., *
  19. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  20. ***************************************************************************/
  21. #include <stdint.h>
  22. #include <string.h>
  23. #include "rgb16mpm.h"
  24. struct dm001data {
  25. uint8_t color;
  26. uint8_t pos;
  27. };
  28. struct dm002data {
  29. uint16_t ramp;
  30. };
  31. struct dm003data {
  32. uint8_t pos;
  33. uint16_t ramp;
  34. uint8_t decay[16][3];
  35. };
  36. struct dm004data {
  37. uint8_t step;
  38. uint8_t pos[3];
  39. };
  40. union demodata {
  41. struct dm001data dm001;
  42. struct dm002data dm002;
  43. struct dm003data dm003;
  44. struct dm004data dm004;
  45. };
  46. static union demodata demo;
  47. static uint16_t demomode000(void)
  48. {
  49. return 0;
  50. }
  51. static uint16_t demomode001(void)
  52. {
  53. struct dm001data *dm = &demo.dm001;
  54. dm->pos = sequence_chase(dm->pos, nvram_data.channels);
  55. uint8_t pos = dm->pos & POS_MASK;
  56. uint8_t chan;
  57. for (chan = 0; chan < 16; chan++) {
  58. if (chan != pos) {
  59. chan_value[chan][COLOR_RED] = 0x00;
  60. chan_value[chan][COLOR_GREEN] = 0x00;
  61. chan_value[chan][COLOR_BLUE] = 0x00;
  62. } else {
  63. chan_value[chan][dm->color] = 0xFF;
  64. }
  65. }
  66. if (pos == 0) {
  67. dm->color++;
  68. if (dm->color == 3) {
  69. dm->color = 0;
  70. }
  71. }
  72. return 250;
  73. }
  74. static uint16_t demomode002(void)
  75. {
  76. struct dm002data *dm = &demo.dm002;
  77. uint8_t color[3];
  78. dm->ramp = color_ramp(dm->ramp +1, color);
  79. uint8_t chan;
  80. for (chan = 0; chan < 16; chan++) {
  81. chan_value[chan][COLOR_RED] = color[COLOR_RED];
  82. chan_value[chan][COLOR_GREEN] = color[COLOR_GREEN];
  83. chan_value[chan][COLOR_BLUE] = color[COLOR_BLUE];
  84. }
  85. return 50;
  86. }
  87. static uint16_t demomode003(void)
  88. {
  89. struct dm003data *dm = &demo.dm003;
  90. dm->pos = sequence_chase(dm->pos, nvram_data.channels);
  91. uint8_t pos = dm->pos & POS_MASK;
  92. dm->ramp = color_ramp(dm->ramp +8, chan_value[pos]);
  93. color_div(chan_value[pos], 8, dm->decay[pos]);
  94. uint8_t chan;
  95. for (chan = 0; chan < 16; chan++) {
  96. if (chan != pos) {
  97. color_sub(chan_value[chan], dm->decay[chan], chan_value[chan]);
  98. }
  99. }
  100. return 50;
  101. }
  102. static uint16_t demomode004(void)
  103. {
  104. struct dm004data *dm = &demo.dm004;
  105. uint8_t color;
  106. dm->step++;
  107. if (dm->step == 2) {
  108. dm->step = 0;
  109. }
  110. for (color = 0; color < 3; color++) {
  111. if (dm->step == 0) {
  112. dm->pos[color] = sequence_chase(dm->pos[color], nvram_data.channels);
  113. }
  114. uint8_t chan;
  115. for (chan = 0; chan < 16; chan++) {
  116. if (chan == (dm->pos[color] & POS_MASK)) {
  117. chan_value[chan][color] = 0xFF;
  118. } else if (chan_value[chan][color] > 16) {
  119. chan_value[chan][color] -= 16;
  120. } else {
  121. chan_value[chan][color] = 0;
  122. }
  123. }
  124. }
  125. return 50;
  126. }
  127. uint16_t (* demomode_run)(void) = demomode000;
  128. void demomode_init(uint8_t mode)
  129. {
  130. memset(&demo, 0x00, sizeof(union demodata));
  131. memset(chan_value, 0x00, sizeof(chan_value));
  132. switch (mode) {
  133. case 0x00:
  134. /* load initial values from eeprom */
  135. memcpy(chan_value, nvram_data.initialRGB, sizeof(chan_value));
  136. demomode_run = demomode000;
  137. break;
  138. case 0x01:
  139. demomode_run = demomode001;
  140. break;
  141. case 0x02:
  142. /* one color, all channes, rgb fader */
  143. demomode_run = demomode002;
  144. break;
  145. case 0x03:
  146. /* rgb chase */
  147. demo.dm003.pos = DIR_UP | 0;
  148. demomode_run = demomode003;
  149. break;
  150. case 0x04:
  151. /* three color chaser */
  152. demo.dm004.pos[COLOR_RED] = DIR_UP | 0;
  153. demo.dm004.pos[COLOR_GREEN] = DIR_UP | 9;
  154. demo.dm004.pos[COLOR_BLUE] = DIR_DOWN | 9;
  155. demomode_run = demomode004;
  156. break;
  157. default:
  158. /* stay black */
  159. demomode_run = demomode000;
  160. break;
  161. }
  162. }