DIGILIGHT
classic.c
См. документацию.
1 
11 #include <avr/io.h>
12 #include "../avr_helper.h"
13 #include <stdlib.h>
14 #include <avr/eeprom.h>
15 #include "../pixel.h"
16 #include "../global.h"
17 #include "../main_effect.h"
18 
22 static __flash const char _name[] = "CLASSIC";
23 static void _save(void);
24 
25 #define DIV 5
26 
27 #define FC (F_CNT/2)
28 #define LEN PIXEL_CNT / (FC)
29 #define PRESET_CNT 2
30 
31 typedef struct {
32  uint8_t f;
33  uint8_t r;
34  uint8_t g;
35  uint8_t b;
36  uint8_t lvl;
37  uint8_t fade1;
38  uint8_t fade2;
39 }preset_f_t;
40 
41 static int8_t id;
42 static __flash const preset_f_t preset[PRESET_CNT][FC] = {
43  {
44  {.f=1, .r=255, .g=0, .b=5, .lvl=50, .fade1=3, .fade2=2},
45  {.f=3, .r=255, .g=0, .b=0, .lvl=50, .fade1=2, .fade2=2},
46  {.f=5, .r=200, .g=50, .b=0, .lvl=50, .fade1=2, .fade2=2},
47  {.f=7, .r=255, .g=255, .b=0, .lvl=50, .fade1=1, .fade2=2},
48  {.f=9, .r=0, .g=255, .b=0, .lvl=50, .fade1=1, .fade2=2},
49  {.f=11, .r=0, .g=255, .b=50, .lvl=50, .fade1=1, .fade2=2},
50  {.f=13, .r=0, .g=255, .b=255, .lvl=50, .fade1=1, .fade2=2},
51  {.f=15, .r=0, .g=0, .b=255, .lvl=50, .fade1=1, .fade2=2}
52  },
53  {
54  {.f=1, .r=255, .g=0, .b=0, .lvl=70, .fade1=3, .fade2=1},
55  {.f=3, .r=255, .g=0, .b=0, .lvl=70, .fade1=2, .fade2=1},
56  {.f=5, .r=255, .g=0, .b=0, .lvl=70, .fade1=2, .fade2=1},
57  {.f=7, .r=0, .g=255, .b=0, .lvl=50, .fade1=1, .fade2=2},
58  {.f=9, .r=0, .g=255, .b=0, .lvl=50, .fade1=1, .fade2=2},
59  {.f=11, .r=0, .g=0, .b=255, .lvl=40, .fade1=1, .fade2=3},
60  {.f=13, .r=0, .g=0, .b=255, .lvl=40, .fade1=2, .fade2=3},
61  {.f=15, .r=0, .g=0, .b=255, .lvl=40, .fade1=3, .fade2=3}
62  }
63 };
64 
65 static uint8_t bright_f(uint8_t v){
66  uint16_t br = v * 2;
67  if(br > 255) br = 255;
68  return br;
69 }
70 
77 static void effect(signal_t *s){
78  static uint8_t div = DIV;
79  uint8_t br, px=0;
80 
81  if(--div) return;
82  div = DIV;
83 
84  for(uint8_t f=0; f < FC; f++){
85  br = (s->harmonics[preset[id][f].f] >> 1) > preset[id][f].lvl ? bright_f(s->peak_volume) : pixels[px+1].bright>>preset[id][f].fade1;
86  for(uint8_t i=0; i<LEN; i++){
87  bright_ctrl(px+i, br, preset[id][f].fade2);
88  set_rgb_color(px+i, preset[id][f].r, preset[id][f].g, preset[id][f].b);
89  }
90  px += LEN;
91  }
92 
93 /*
94  while(f <= F_3800_HZ){
95  for(uint8_t i=0; i<4; i++){
96  bright_ctrl(px+i, (s->harmonics[f] >> 1) > 50 ? bright_f(s->peak_volume) : pixels[px+1].bright>>1, 2);
97  set_fix_color(px+i, f/2);
98  }
99  px += 4;
100  f += 2;
101  }
102 */
103 }
104 
105 static preset_result_t _preset(int8_t d){
106  id += d;
107  if(id < 0) id = PRESET_CNT-1;
108  if(id >= PRESET_CNT) id = 0;
109  return id+1;
110 }
111 
112 static flash_effect_t effect_def = {
113  .name = _name,
114  .start = NULL,
115  .work = effect,
116  .stop = NULL,
117  .preset = _preset,
118  .save = _save
119 };
120 
121 static EEMEM uint8_t e_id;
122 
123 INIT(7){
124  // загрузить пресеты и настройки
125  id = eeprom_read_byte(&e_id);
126  _preset(0);
127  // регистрация эффекта
128  register_effect(FOREGROUND_EFFECT, &effect_def);
129 }
130 
131 static void _save(void){
132  // сохранить настройки
133  eeprom_update_byte(&e_id, id);
134 }
135 
void bright_ctrl(uint8_t id, uint8_t bright, int8_t delta)
Управление яркостью
Definition: pixel.c:95
void set_rgb_color(uint8_t pos, uint8_t r, uint8_t g, uint8_t b)
Пиксел произвольного цвета
Definition: pixel.c:107
const __flash effect_t flash_effect_t
тип описания эффекта, размещенного во FLASH.
Definition: main_effect.h:79
структура параметров звукового сигнала
Definition: global.h:72
uint16_t harmonics[F_CNT]
амплитуды всех гармоник сигнала
Definition: global.h:77
preset_result_t
результат функции смены пресета
Definition: main_effect.h:56
#define FOREGROUND_EFFECT
основной эффект
Definition: main_effect.h:50
volume_t peak_volume
пиковая громкость
Definition: global.h:73
pixel_t pixels[MAX_TOTAL_PIX]
Массив пикселей предельного размера
Definition: pixel.c:22
void register_effect(uint8_t toe, flash_effect_t *eff)
Регистрация эффекта в списках
Definition: main_effect.c:41
uint8_t bright
яркость пиксела
Definition: pixel.h:37