static void led_init_handle(void *inContext) { nearair_Context_t *airContent = inContext; static char color_count = 0; if( MODE_INIT != airContent->deviceStatus.mode ) { mico_stop_timer(&_led_init_timer); mico_deinit_timer(&_led_init_timer); } switch(color_count) { case 0: set_led_color(99,0,0); color_count = 1; break; case 1: set_led_color(99,50,0); color_count = 2; break; case 2: set_led_color(0,0,99); color_count = 0; break; default: break; } }
void rgb_fade_tick(void) { //Wenn der Fader gestartet wurde if (f_ctrl.state == fader_run) { //Differenz zu jedem Farbkanal ausrechnen uint8_t i; for(i=0; i<3; i++) { f_ctrl.diff[i] = fade_calc_diff(f_ctrl.from.rgb[i], f_ctrl.to.rgb[i]); } f_ctrl.max_count = f_ctrl.time; //Timer initialisieren (Anzahl der Ticks) //Schritte pro Farbkanal, pro Tick berechnen for(i=0; i<3;i++) { f_ctrl.step[i] = f_ctrl.max_count / f_ctrl.diff[i]; } //Faulheit verhindern for (i=0;i<3;i++) { if ((f_ctrl.from.rgb[i] != f_ctrl.to.rgb[i]) && (f_ctrl.step[i] == 0)) f_ctrl.step[i] = 1; } //Timer mit Prescaler 64 starten CTC-Mode TCCR3B |= (1<<CS31) | (1<<CS30) | (1<<WGM32); //Fader aktivieren f_ctrl.state = fader_running; } if (f_ctrl.state == fader_running) { //Wenn der Fader laeuft, werden hier die Farben aktualisiert. //Das spahrt Takte in der ISR set_led_color(&f_ctrl.from); } if (f_ctrl.state == fader_last) { f_ctrl.state = fader_idle; set_led_color(&f_ctrl.from); } }
void rainbow(uint8_t step) { uint8_t r=color_fade_func(step+169); uint8_t g=color_fade_func(step+85); uint8_t b=color_fade_func(step); set_led_color(r,g,b); }
static void led_sleep_handle(void *inContext) { nearair_Context_t *airContent = inContext; static uint8_t count = 0; static uint8_t R; uint8_t pluse_count = 0; if(MODE_SLEEP != airContent->deviceStatus.mode) { mico_stop_timer(&_led_sleep_timer); mico_deinit_timer(&_led_sleep_timer); } switch(airContent->sensorStatus.light) { case NIGHT: R = 130; break; case DAY: R = 100; break; default: break; } count += 1; if(count > 200) { count = 0; return; } if(count < 100) { pluse_count = R - (int)sqrt(R*R - count*count); } if(count > 100) { pluse_count = R - (int)sqrt(R*R - (200 - count)*(200 - count)); } if(pluse_count < 3)//避免灯灭导致闪烁感 return; set_led_color(0,0,pluse_count); /* switch(airContext->airStatus.airclass) { case AQ_GOOD: set_led_color(0,0,pluse_count); break; case AQ_SOSO: set_led_color(pluse_count,2+(int)(0.3*pluse_count),0); break; case AQ_BAD: set_led_color(pluse_count,0,0); break; default: break; }*/ }
//Kommunikation void command(uint8_t *buf) { uint8_t m_comand = buf[0]; struct rgb rgb_color; struct hsv hsv_color; switch (m_comand) { case mpxl_cmd_off: led_off(); break; case mpxl_cmd_on: led_on(); break; case mpxl_cmd_setRGB: rgb_color.Red = buf[1]; rgb_color.Green = buf[2]; rgb_color.Blue = buf[3]; set_led_color(&rgb_color); break; case mpxl_cmd_setHSV: hsv_color.hsv[0] = buf[1]; hsv_color.hsv[1] = buf[2]; hsv_color.saturation = buf[3]; hsv_color.value = buf[4]; hsv2rgb(&hsv_color,&rgb_color); set_led_color(&rgb_color); break; case mpxl_cmd_fade: rgb_color.Red = buf[1]; rgb_color.Green = buf[2]; rgb_color.Blue = buf[3]; rgb_fade_int(rgb_color, buf[4]); case mpxl_cmd_script: script_handler(buf); break; } }
int fade_test(void) { uint8_t i; while (1) { for(i = 0; i < 255; i++) { set_led_color(i, 0, 0); _delay_ms(20); } set_led_color(0, 0, 0); for(i = 0; i < 255; i++) { set_led_color(0, i, 0); _delay_ms(20); } set_led_color(0, 0, 0); for(i = 0; i < 255; i++) { set_led_color(0, 0, i); _delay_ms(20); } set_led_color(0, 0, 0); } return 0; }
void fade(uint8_t r1, uint8_t g1, uint8_t b1, uint8_t r2, uint8_t g2, uint8_t b2, uint8_t steps, uint8_t delay) { int16_t i; for(i = 0; i < steps; i++) { set_led_color((uint8_t)(r1 + (uint8_t)(((int16_t)(r2 - r1) * i) / steps)), (uint8_t)(g1 + (uint8_t)(((int16_t)(g2 - g1) * i) / steps)), (uint8_t)(b1 + (uint8_t)(((int16_t)(b2 - b1) * i) / steps))); _delay_ms(delay); } }
void flash_led(void) { uint8_t i; for(i = 0; i < 3; i++) { set_led_color(255, 0, 0); _delay_ms(50); set_led_color(0, 0, 0); _delay_ms(50); set_led_color(0, 255, 0); _delay_ms(50); set_led_color(0, 0, 0); _delay_ms(50); set_led_color(0, 0, 255); _delay_ms(50); set_led_color(0, 0, 0); _delay_ms(50); } }
void led_thread(void *inContext) { led_log_trace(); nearair_Context_t *airContext = inContext; char mode_old; char airclass_old; bsp_InitLed(); mode_old = airContext->deviceStatus.mode; airclass_old = airContext->airStatus.airclass; mico_init_timer(&_led_init_timer, 500,led_init_handle, inContext); mico_init_timer(&_led_sleep_timer,20, led_sleep_handle,inContext); while(1) { if(mode_old != airContext->deviceStatus.mode) { if(mode_old == MODE_INIT) mico_stop_timer(&_led_init_timer); if(mode_old == MODE_SLEEP) mico_stop_timer(&_led_sleep_timer); mode_old = airContext->deviceStatus.mode; switch(mode_old) { case MODE_CLOSE: set_led_color(0,0,0); break; case MODE_INIT: mico_start_timer(&_led_init_timer); break; case MODE_SMART: switch( airContext->airStatus.airclass ) { case AQ_GOOD: set_led_color(0,0,99); break; case AQ_SOSO: set_led_color(99,33,0); break; case AQ_BAD: set_led_color(99,0,0); break; default: break; } break; case MODE_SLEEP: mico_start_timer(&_led_sleep_timer); break; case MODE_FLY: set_led_color(0,99,0); break; default: break; } } if(mode_old == MODE_SMART) { if(airclass_old != airContext->airStatus.airclass) { airclass_old = airContext->airStatus.airclass; switch( airclass_old ) { case AQ_GOOD: set_led_color(0,0,99); break; case AQ_SOSO: set_led_color(99,33,0); break; case AQ_BAD: set_led_color(99,0,0); break; default: break; } } } if(airContext->setStatus.led_enable) { set_led_color(airContext->setStatus.led_r,airContext->setStatus.led_g,\ airContext->setStatus.led_b); } } }
ConfigDlg::ConfigDlg(QWidget *parent, struct configstruct *data,const char *name) : QDialog(parent, name) { configdata.background_color = black; configdata.led_color = green; configdata.tooltips = true; if(data){ configdata.background_color = data->background_color; configdata.led_color = data->led_color; configdata.tooltips = data->tooltips; } colors_changed = false; setCaption("Configure kscd"); box = new QGroupBox(this, "box"); box->setGeometry(10,10,320,260); label1 = new QLabel(this); label1->setGeometry(20,25,135,25); label1->setText(i18n("LED Color:")); qframe1 = new QFrame(this); qframe1->setGeometry(155,25,30,25); qframe1->setFrameStyle(QFrame::WinPanel | QFrame::Sunken); qframe1->setBackgroundColor(configdata.led_color); button1 = new QPushButton(this); button1->setGeometry(205,25,100,25); button1->setText(i18n("Change")); connect(button1,SIGNAL(clicked()),this,SLOT(set_led_color())); label2 = new QLabel(this); label2->setGeometry(20,65,135,25); label2->setText(i18n("Background Color:")); qframe2 = new QFrame(this); qframe2->setGeometry(155,65,30,25); qframe2->setFrameStyle(QFrame::WinPanel | QFrame::Sunken); qframe2->setBackgroundColor(configdata.background_color); button2 = new QPushButton(this); button2->setGeometry(205,65,100,25); button2->setText(i18n("Change")); connect(button2,SIGNAL(clicked()),this,SLOT(set_background_color())); button3 = new QPushButton(this); button3->setGeometry(205,175,100,25); button3->setText(i18n("Help")); connect(button3,SIGNAL(clicked()),this,SLOT(help())); ttcheckbox = new QCheckBox(i18n("Show Tool Tips"), this, "tooltipscheckbox"); ttcheckbox->setGeometry(30,110,135,25); ttcheckbox->setFixedSize( ttcheckbox->sizeHint() ); ttcheckbox->setChecked(configdata.tooltips); connect(ttcheckbox,SIGNAL(clicked()),this,SLOT(ttclicked())); }
inline void power_off() { power=0; set_led_color(0,0,0); PORTB=(1<<CS)|(power<<PWR_OUT); }