void device_led_default(struct ss_device * dev, uint32_t ctl) { if (dev->ledno) { DCC_LOG2(LOG_INFO, "dev=%d ctl=0x%x", dev->addr, ctl); /* Poll LED state */ if ((ctl & 0x5) == 0x5) { led_flash(dev->ledno - 1, 64); } else if ((ctl & 0x4) == 0x4) { led_on(dev->ledno - 1); } else led_off(dev->ledno - 1); } if ((ctl & 0x4) == 0x4) dev->led = 1; else dev->led = 0; }
void __attribute__((interrupt("IRQ"))) interrupt_handler(void) { static int lit = 0; /* Check that it was in fact a timer interrupt */ if (mmio_read(IRQ_BASIC_PENDING)&&0x1) { /* Clear the ARM Timer interrupt */ mmio_write(TIMER_IRQ_CLEAR, 0x1); /* Toggle the LED state */ if(lit) { led_off(); lit = 0; } else { led_on(); lit = 1; } } else printk("Other Interrupt \r\n"); }
/** * \brief This will start a sleep operation. * * \param val Used for remembering the new menu to display after a wakeup. */ void menu_run_sleep(uint8_t *val) { /* Turn off LED, LCD, ADC, Timer 1, SPI */ led_off(); lcd_deinit(); key_deinit(); PRR |= (1 << PRTIM1) | (1 << PRSPI); /* Tell the 1284P to turn off the radio and sleep */ sleep_count=0; uart_serial_send_frame(SEND_SLEEP, 1, (uint8_t *)&sleep_count); /* Turn off UART when transmission is complete */ while(!(UCSR0A & (1 << TXC0))); _delay_us(10000); //deinit trash clears done flag on 1284p uart_deinit(); /* Go to sleep until button is pushed */ sleep_now(0); /* Yawn, waking up, turn on LCD with Raven Logo */ lcd_init(); lcd_symbol_set(LCD_SYMBOL_RAVEN); /* Disable interrupts before powering everything up */ cli(); key_init(); PRR &= ~((1 << PRTIM1) | (1 << PRSPI)); uart_init(); /* Enable interrupts, Wake up 1284p and radio */ sei(); sleep_wakeup(); // uart_init();//flush receive buffer /* Wait for buttons up */ while (key_state_get() != KEY_NO_KEY) ; if (is_button()){ get_button(); } }
/* Fading test */ void fading(void) { int i; while (1) { for (i = 255; i > 5; i --) { led_on(GREEN); output(i); delay(30); } for (i = 5; i < 255; i ++) { led_off(GREEN); output(i); delay(30); } } }
int main(void) { target_init(); HAL_SET_PIN_DIRECTIONS(); wdt_disable(); //hal_init( NULL, NULL ); led_on( LED_ALL ); hal_delay( 500 ); led_off( LED_ALL ); dbo_open(0, 38400); // the parameter id can be 0-3 denoting timer hardware 0 to 3 timer_interrupt_driven_test( 0 ); // timer_query_driven_test( 2 ); while(1){} }
void send_data_loop(float temperature_sensor_value, int light_sensor_value) { if (LWiFi.status() == LWIFI_STATUS_DISCONNECTED) { Serial.println("Disconnected from WiFi"); while (0 == LWiFi.connect(ssid, LWiFiLoginInfo(WIFI_AUTH, key))){ Serial.println("Connecting to WiFi..."); delay(1000); } } LDateTime.getRtc(&rtc); if ((rtc - lrtc) >= per) { senddata(temperature_sensor_value, light_sensor_value); lrtc = rtc; } //Check for TCP socket command from MCS Server String tcpcmd=""; while (c.available()) { int v = c.read(); if (v != -1) { Serial.print((char)v); tcpcmd += (char)v; if (tcpcmd.indexOf("led on") >= 0) { Serial.print("Received actuator command: "); Serial.println(tcpcmd); Serial.println("Switching LED ON..."); led_on(); tcpcmd=""; }else if(tcpcmd.indexOf("led off") >= 0) { Serial.print("Received actuator command: "); Serial.println(tcpcmd); Serial.println("Switching LED OFF..."); led_off(); tcpcmd=""; } } } //Check for hearbeat interval LDateTime.getRtc(&rtc2); if ((rtc2 - lrtc2) >= per1) { heartBeat(); lrtc2 = rtc2; } }
static int __init led_init(void) { int error = 0; printk(KERN_ALERT "Init called\n"); /*if (!wmi_has_guid(DELL_LED_BIOS_GUID)) return -ENODEV; error = led_off(); if (error != 0) return -ENODEV; */ printk(KERN_ALERT "classdev_register return : %d\n",error); if(!(error = led_classdev_register(NULL, &led))){ led_on(); led_off(); } return 0; }
int main (void) { system_init (); led_init (); button_init (); while (1) { if (button_pressed_p ()) { led_on (); } else { led_off (); } } }
/** @brief: Function for handling the RTC0 interrupts. * Triggered on TICK and COMPARE0 match. */ static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { switch (int_type) { case CC_PERIODIC: periodic_task(); break; case CC_DEBOUNCE: btn_debounce(); break; case CC_BLINK: if (!g_btn_pressed) led_off(); rtc_cc_disable(CC_BLINK); break; default: ; } }
void main_thread() { printf_(OS_WELCOME_MESSAGE); u32 res = hmc5883_init(); while (1) { led_on(LED_1); hmc5883_read(); //printf_("%u : %i %i %i\n", res, g_hmc5883.mx, g_hmc5883.my, g_hmc5883.mz); printf_("%u : %i \n", res, g_hmc5883.mz); led_off(LED_1); timer_delay_ms(100); } robot_main(); }
// Handle hard faults static void __attribute__((naked)) HardFault_Handler(void) { u32 loops; while (1) { led_on(LED_1); loops = 10000000; while (loops--) __asm("nop"); led_off(LED_1); loops = 10000000; while (loops--) __asm("nop"); } while (1) __asm("nop"); }
void asv2_evolve( void * svcptr, TiEvent * e ) { TiAppService2 * svc = (TiAppService2 *)svcptr; switch (svc->state) { case 0: led_on( LED_GREEN ); svc->state = 1; break; case 1: led_off( LED_GREEN ); svc->state = 0; } if (svc->listener != NULL) { svc->listener( svc->lisowner, e ); } }
void tx_callback(Trans_Tx_Result result) { if(result == TransPacketSent) { #ifdef USE_LEDS led_off(3); #endif log_print_string("ACK SEND"); } else { #ifdef USE_LEDS led_toggle(2); #endif log_print_string("TX ACK CCA FAIL"); } // Restart channel scanning start_channel_scan = true; }
void hit_by(uint8_t who) { uint16_t respawn_timer; add_to_hitlist(who); Save(FLASH_HITLIST,(uint16_t*)&hitlist,HITLIST_SIZE); config.health --; Save(FLASH_CONFIG,(uint16_t*)&config, CONFIG_SIZE); play_song((uint16_t*)death_song,sizeof(death_song)/sizeof(uint16_t),60000,0); if(!config.health) { red_led_on(); super_dead_mode(); return; } respawn_timer = config.respawn_delay; while(respawn_timer) { respawn_timer--; red_led_on(); for(uint8_t i=0;i<50;i++) { handle_music(); delay_1_ms(); } if(respawn_timer < 30) { led_off(); } for(uint8_t i=0;i<50;i++) { handle_music(); delay_1_ms(); } } }
void IR_range_blast(uint16_t power) { delay_ms(POST_BROADCAST_DELAY); //uint32_t timer[20]; //timer[0] = get_16bit_time(); //Top of the function. uint16_t pre_sync_op = get_16bit_time(); for(uint8_t dir = 0; dir < 6; dir++) { set_ir_power(dir, power); } while((get_16bit_time() - pre_sync_op) < TIME_FOR_SET_IR_POWERS); //set_rgb(128,0,64); //_delay_ms(1); //led_off(); //_delay_ms(10); for(uint8_t dir = 0; dir < 6; dir++) { //IR_emit(dir, DELAY_BETWEEN_RB_MEASUREMENTS*NUMBER_OF_RB_MEASUREMENTS); //timer[(3*dir + 0) + 1] = get_16bit_time();//Top of the for loop. delay_ms((DELAY_BETWEEN_RB_MEASUREMENTS + TIME_FOR_GET_IR_VALS)*(NUMBER_PRE_MEASUREMENTS)); IR_emit(dir, (DELAY_BETWEEN_RB_MEASUREMENTS + TIME_FOR_GET_IR_VALS)*(NUMBER_OF_RB_MEASUREMENTS - (NUMBER_PRE_MEASUREMENTS + NUMBER_POST_MEASUREMENTS + 1))); //The -1 is 'cause we shouldn't count the baseline measurements. delay_ms((DELAY_BETWEEN_RB_MEASUREMENTS + TIME_FOR_GET_IR_VALS)*(NUMBER_POST_MEASUREMENTS)); //timer[(3*dir + 1) + 1] = get_16bit_time();//post emit set_green_led(100); delay_ms(DELAY_BETWEEN_RB_TRANSMISSIONS); led_off(); //timer[(3*dir + 2) + 1] = get_16bit_time();//bottom of the for loop. //_delay_ms(10); //IR_emit(1, DELAY_BETWEEN_RB_MEASUREMENTS*NUMBER_OF_RB_MEASUREMENTS-20); // strictly for debugging the timing //_delay_ms(DELAY_BETWEEN_RB_TRANSMISSIONS+10); } //timer[19] = get_16bit_time();//End of function. //debug_print_timer(timer); }
/** * \brief This will start a sleep with wakes for temperature measurement and web requests. * * \param val Used for remembering the new menu to display after a wakeup. */ void menu_run_doze(uint8_t *val) { /* Turn off LED, LCD */ led_off(); lcd_deinit(); /* Debounce */ while (key_state_get() != KEY_NO_KEY) ; /* Stay in doze loop until button is pressed*/ while (ENTER_PORT & (1<<ENTER_PIN)) { /* Tell 1284p to sleep for 4 seconds */ /* It will ignore the request if TCP/IP sessions are active */ /* Alter these timings as desired, or comment out to sleep only the 3290p */ sleep_count=4; uart_serial_send_frame(SEND_SLEEP, 1, (uint8_t *)&sleep_count); /* Wait for transmission complete, then sleep 3290p for 5 seconds */ while(!(UCSR0A & (1 << TXC0))); // uart_deinit(); sleep_now(sleep_count+1); // uart_init(); /* 1284p should be awake by now, update temperature and give it time to process */ menu_send_temp(); _delay_us(20000); } /* Wake LCD, turn on Raven logo */ lcd_init(); lcd_symbol_set(LCD_SYMBOL_RAVEN); sleep_wakeup(); /* Wait for buttons up */ while (key_state_get() != KEY_NO_KEY) ; if (is_button()){ get_button(); } }
//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; } }
void tx_callback(Trans_Tx_Result result) { counter++; if(result == TransPacketSent) { #ifdef USE_LEDS led_off(3); #endif log_print_string("TX OK"); } else { #ifdef USE_LEDS led_toggle(1); #endif log_print_string("TX CCA FAIL"); } tx = 0; }
/* blink leds */ void blink(void) { int i, times; short h; if ((input_line[5] == ' ') && (isdigit(input_line[6]))) times = 10 * (input_line[6] - '0'); else times = 1; for (i = 1; i <= times; i++) { for (h = 1; h <= 8; h++) led_on(h); usleep((int)(set_time / 2)); for (h = 1; h <= 8; h++) led_off(h); usleep((int)(set_time / 2)); } }
int test(void) { int i = 0; led_init(); buzzer_init(); k1_init(); while(1) { if(k1_is_down()) { buzzer_on(); led_on(i%4 + 1); delay(1); buzzer_off(); led_off(i%4 + 1); delay(1); i++; } } return 0; }
/** * Create a debug terminal for testing Bluetooth. */ void ksimpleterminal( void ) { int c; led_on(); for( ;; ) { c = kgetc( (void *)0 ); if( c != SYSERR ) kputc( (void *)0, c ); led_off(); if( c == 'q' ) break; } }
void launch_launcher(void) { if (launcher.state != launcher.last_state) { // if we are entering the state, do initialization stuff launcher.last_state = launcher.state; } if (!pin_read(launcher.load_sensor)) { launcher.loaded = 1; led_on(&led1); pin_clear(launcher.elevator_motor); } if (launcher.loaded) { pin_set(launcher.launch_motor); if (!pin_read(launcher.launch_sensor)) { limit_flag = 1; } if (pin_read(launcher.launch_sensor) && limit_flag) { limit_counter++; } if (limit_counter >= 100) { launcher.state = rest_launcher; } } else { if (launcher.over) { launcher.state = over_launcher; } } if (launcher.state != launcher.last_state) { // if we are leaving the state, do clean up stuff pin_clear(launcher.launch_motor); pin_set(launcher.elevator_motor); launcher.launch = 0; launcher.loaded = 0; led_off(&led1); limit_flag = 0; limit_counter = 0; } }
void jump_to_app() { const uint32_t *app_base = (const uint32_t *)APP_LOAD_ADDRESS; /* * We refuse to program the first word of the app until the upload is marked * complete by the host. So if it's not 0xffffffff, we should try booting it. */ if (app_base[0] == 0xffffffff) return; /* * The second word of the app is the entrypoint; it must point within the * flash area (or we have a bad flash). */ if (app_base[1] < APP_LOAD_ADDRESS) return; if (app_base[1] >= (APP_LOAD_ADDRESS + board_info.fw_size)) return; /* just for paranoia's sake */ flash_lock(); /* kill the systick interrupt */ systick_interrupt_disable(); systick_counter_disable(); /* and set a specific LED pattern */ led_off(LED_ACTIVITY); led_on(LED_BOOTLOADER); /* the interface */ cfini(); /* switch exception handlers to the application */ SCB_VTOR = APP_LOAD_ADDRESS; /* extract the stack and entrypoint from the app vector table and go */ do_jump(app_base[0], app_base[1]); }
int main(void) { /* USER CODE BEGIN 1 */ uint8_t i = 0; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ i = (i >= 3)? 0 : i + 1; led_on(LED_0 << i); HAL_Delay(500); led_off(LED_0 << i); HAL_Delay(500); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
static int board_button_irq(int irq, FAR void *context) { static struct timespec time_down; if (board_pwr_button_down()) { led_on(BOARD_LED_RED); clock_gettime(CLOCK_REALTIME, &time_down); } else { led_off(BOARD_LED_RED); struct timespec now; clock_gettime(CLOCK_REALTIME, &now); uint64_t tdown_ms = time_down.tv_sec * 1000 + time_down.tv_nsec / 1000000; uint64_t tnow_ms = now.tv_sec * 1000 + now.tv_nsec / 1000000; if (tdown_ms != 0 && (tnow_ms - tdown_ms) >= MS_PWR_BUTTON_DOWN) { led_on(BOARD_LED_BLUE); up_mdelay(200); stm32_pwr_enablebkp(true); /* XXX wow, this is evil - write a magic number into backup register zero */ *(uint32_t *)0x40002850 = 0xdeaddead; stm32_pwr_enablebkp(false); up_mdelay(50); up_systemreset(); while (1); } } return OK; }
/** * ggrbug mode * - simulate geiger counter sounds */ static void geiger(void) { uint8_t max = 200; uint8_t min = 10; static timer_t mytimer; static bool blink; if (mode_uninitialized) { init_leds(); music_setNote(NOTE_PAUSE, 0); mode_uninitialized = false; timer_set(&mytimer, 10); blink = false; }; if (timer_expired(&mytimer)) { if (!blink) { /*lets blink*/ int i = (rand() % 3); switch (i) { case 0: led_on(LED_L); break; case 1: led_on(LED_R); break; default: led_on(LED_L | LED_R); break; }; if (rand() % 10 > 8) set_motor(MOTOR_ON); music_setNote(NOTE_C, 5); timer_set(&mytimer, 2); blink = true; } else { /*stop blink*/ led_off(LED_L | LED_R); set_motor(MOTOR_OFF); music_setNote(NOTE_PAUSE, 0); timer_set(&mytimer, (rand() % (max - min)) + min); blink = false; } }//end if timer_expired }
static int board_button_irq(int irq, FAR void *context) { static struct timespec time_down; if (board_pwr_button_down()) { led_on(BOARD_LED_RED); clock_gettime(CLOCK_REALTIME, &time_down); power_state_notification(PWR_BUTTON_DOWN); } else { power_state_notification(PWR_BUTTON_UP); led_off(BOARD_LED_RED); struct timespec now; clock_gettime(CLOCK_REALTIME, &now); uint64_t tdown_ms = time_down.tv_sec * 1000 + time_down.tv_nsec / 1000000; uint64_t tnow_ms = now.tv_sec * 1000 + now.tv_nsec / 1000000; if (tdown_ms != 0 && (tnow_ms - tdown_ms) >= MS_PWR_BUTTON_DOWN) { led_on(BOARD_LED_BLUE); if (power_state_notification(PWR_BUTTON_REQUEST_SHUT_DOWN) == PWR_BUTTON_RESPONSE_SHUT_DOWN_NOW) { up_mdelay(200); board_shutdown(); } } else { power_state_notification(PWR_BUTTON_IDEL); } } return OK; }
/** * @brief Timer event handler for PWM. * * @param[in] p_context General purpose pointer. Will be passed to the time-out handler * when the timer expires. * */ static void pwm_timeout_handler(void * p_context) { ret_code_t err_code; uint8_t duty_cycle; low_power_pwm_t * p_pwm_instance = (low_power_pwm_t *)p_context; p_pwm_instance->pwm_state = NRF_DRV_STATE_INITIALIZED; if(p_pwm_instance->evt_type == LOW_POWER_PWM_EVENT_PERIOD) { if (p_pwm_instance->handler) { p_pwm_instance->handler(p_pwm_instance); } duty_cycle = p_pwm_instance->duty_cycle; if(duty_cycle == p_pwm_instance->period) // Process duty cycle 100% { led_on(p_pwm_instance); p_pwm_instance->timeout_ticks = p_pwm_instance->period + APP_TIMER_MIN_TIMEOUT_TICKS; } else if (duty_cycle == 0) // Process duty cycle 0% { led_off(p_pwm_instance); p_pwm_instance->timeout_ticks = p_pwm_instance->period + APP_TIMER_MIN_TIMEOUT_TICKS; } else // Process any other duty cycle than 0 or 100% { led_on(p_pwm_instance); p_pwm_instance->timeout_ticks = ((duty_cycle*p_pwm_instance->period)>>8) + APP_TIMER_MIN_TIMEOUT_TICKS; // setting next state p_pwm_instance->evt_type = LOW_POWER_PWM_EVENT_DUTY_CYCLE; } } else {
void usbModuleDisable(void) { wait_ms(100); led_off(); /* ==== Interrupt mask level change ==== */ set_imask(15); //(0x000000F0); /* USBコントローラディセーブル */ INTC.IPR10.BIT._USB = 0; /* Set USB interrupt level */ USB.SYSCFG.WORD = 0x0481; /* DPRUP off */ wait_ms(30); USB.SYSCFG.WORD = 0x0401; /* HSE off */ wait_ms(30); USB.SYSCFG.WORD = 0x0400; /* USB off */ wait_ms(30); USB.SYSCFG.WORD = 0x0; /* SCKE off */ usb_reset_module(); /* USBモジュール リセット */ wait_ms(1200); INTC.IBNR.WORD = 0x0000; /* レジスタバングディセーブル */ cache_disable(); }
void* led(void *data) { dev = open("/dev/led", O_WRONLY); if (dev != -1) { while(active_mode){ if (communicating == 1){ led_on(); usleep(50000); led_shuffle(); } else { led_off(); } } close(dev); } else { printf( "Device Open ERROR!\n"); exit(1); } }