void terminal_operation(ringbuf_t *tx, char *op0, char *op1, char *op2, char *op3) { if (!strcmp(op0, "help") || !strcmp(op0, "?")) { ringbuf_put_str(tx, "\tprint_time(t)\n" "\tadjust_time(at) [hand:y,M,d,h,m,s] [value(decimal)]\n" "\tpwm [color:R,G,B,W] [value(%):0~100]\n" "\tpwm clear\n" "\tset time_sync_mode(sync)\n" "\tset ADC_mode(adc)\n" "\tRESET();\n" ); } terminal_time(tx, op0, op1, op2); if (!strcmp(op0, "RESET();")) { RESET(); } if (!strcmp(op0, "bootload")) { asm("goto 0x001C"); } if (!strcmp(op0, "set")) { if (!strcmp(op1, "sync")) { light_mode = TIME_SYNC_mode; } if (!strcmp(op1, "adc") || !strcmp(op1, "ADC")) { light_mode = ADC_mode; } } if (!strcmp(op0, "pwm") || !strcmp(op0, "PWM")) { if (!strcmp(op1, "r") || !strcmp(op1, "R")) { light_mode = COMMAND_mode; PWM_set(0, atoi(op2) * PR_VALUE / 100); } if (!strcmp(op1, "g") || !strcmp(op1, "G")) { light_mode = COMMAND_mode; PWM_set(1, atoi(op2) * PR_VALUE / 100); } if (!strcmp(op1, "b") || !strcmp(op1, "B")) { light_mode = COMMAND_mode; PWM_set(2, atoi(op2) * PR_VALUE / 100); } if (!strcmp(op1, "w") || !strcmp(op1, "W")) { light_mode = COMMAND_mode; PWM_set(3, atoi(op2) * PR_VALUE / 100); } if (!strcmp(op1, "clear")) { light_mode = COMMAND_mode; PWM_set(0, 0); PWM_set(1, 0); PWM_set(2, 0); PWM_set(3, 0); } } }
void display_set(uint8 channel,float value) { static float ch1,ch2,ch3; switch(channel) { case DISP_THURST: ch1 = value/98.1/3.3*65535; break; case DISP_PRESSURE: ch2 = value/3.3*65535; break; case DISP_TEMP: ch3 = value/100/3.3*65535; break; } if(!vtimer_ovf(decim)) return; PWM_set(1,(uint16)ch1); PWM_set(2,(uint16)ch2); PWM_set(3,(uint16)ch3); vtimer_set(decim,REFRESH_DELAY); }
void interrupt ISR(void) { USB_CDC_ISR(); if (INTCONbits.T0IF) { INTCONbits.T0IF = 0; } if (PIR1bits.TMR1IF) { PIR1bits.TMR1IF = 0; TMR1H = 0xC0; static uint8_t cnt = 0; switch (cnt) { case 0: PWM_set(RED, 255); PWM_set(GREEN, 0); PWM_set(BLUE, 0); cnt++; break; case 1: PWM_set(RED, 80); PWM_set(GREEN, 80); PWM_set(BLUE, 80); cnt++; break; case 2: PWM_set(RED, 0); PWM_set(GREEN, 0); PWM_set(BLUE, 255); cnt++; break; case 3: PWM_set(RED, 80); PWM_set(GREEN, 80); PWM_set(BLUE, 80); cnt = 0; break; } } if (PIR2bits.TMR3IF) { PIR2bits.TMR3IF = 0; button_timer_interrupt(&sw_R, !SWR); button_timer_interrupt(&sw_G, !SWG); button_timer_interrupt(&sw_B, !SWB); } }
void light_task(void) { if (time_change_flag) { time_change_flag = 0; RTCC_from_RTCC(&now); if (light_mode == TIME_SYNC_mode) { PWM_set(3, 0); uint16_t s = (epoch_t) (now.epoch % DAY) / (DAY / 1024); if (s < 256) { for (uint8_t i = 0; i < 3; i++) { PWM_set(i, 0); } } else if (s < 512) { for (uint8_t i = 0; i < 3; i++) { PWM_set(i, s - 256); } } else if (s < 768) { for (uint8_t i = 0; i < 3; i++) { PWM_set(i, 768 - s); } } else { for (uint8_t i = 0; i < 3; i++) { PWM_set(i, 0); } } } } if (sw_G.flag.press) { sw_G.flags = 0; light_mode = COMMAND_mode; static uint8_t n = 0; if (n >= 3) n = 0; else n++; uint8_t value = PR_VALUE / 3 * n; for (uint8_t i = 0; i < 3; i++) { PWM_set(i, value); } } if (sw_B.flag.press) { sw_B.flags = 0; light_mode = COMMAND_mode; static uint8_t n = 0; if (n >= 3) n = 0; else n++; uint8_t value = PR_VALUE / 3 * n; PWM_set(3, value); } if (sw_R.flag.press) { sw_R.flags = 0; light_mode = TIME_SYNC_mode; } // if (sw_R.flag.long_hold_1) { // sw_R.flags = 0; // light_mode = ADC_mode; // } // if (light_mode == ADC_mode && ADC_flag == 1) { // ADC_flag = 0; // for (i = 0; i < 3; i++) { // uint16_t scan = (ADC(i) >> 4) * PR_VALUE / 255; // static uint8_t prev_scan[3]; // if (scan != prev_scan[i]) { // prev_scan[i] = scan; // PWM_set(i, scan); // } // } // } }