virtual Ice::Int activateLed(Ice::Int led, const Ice::Current&) { switch(led){ case 1: toggle_bit(api->led_state, CWIID_LED1_ON); set_led_state(wiimote, api->led_state); break; case 2: toggle_bit(api->led_state, CWIID_LED2_ON); set_led_state(wiimote, api->led_state); break; case 3: toggle_bit(api->led_state, CWIID_LED3_ON); set_led_state(wiimote, api->led_state); break; case 4: toggle_bit(api->led_state, CWIID_LED4_ON); set_led_state(wiimote, api->led_state); break; default: break; } return 1; }
int forget_wii_device(struct wiimoteglue_state* state, struct wii_device *dev) { if (dev == NULL) return -1; if (state->set_leds) { open_wii_device(state,dev); set_led_state(state,dev,dev->original_leds); } if (dev->xwii != NULL) close_wii_device(state,dev); struct wii_device_list *list = dev->main_list; if (list->prev) { list->prev->next = list->next; } if (list->next) { list->next->prev = list->prev; } if (dev->id != NULL) { free(dev->id); } if (dev->bluetooth_addr != NULL) { free(dev->bluetooth_addr); } udev_device_unref(dev->udev); free(dev->slot_list); free(dev); free(list); return 0; }
void ant_io_rx_event_handler(ant_evt_t * p_ant_evt) { ANT_MESSAGE * p_message = (ANT_MESSAGE*) p_ant_evt->msg.evt_buffer; switch(p_ant_evt->event) { case EVENT_RX: if(p_message->ANT_MESSAGE_aucPayload[0] == DIGITALIO_DATA_PID) { //Set LEDs according to Received Digital IO Data Page m_rx_input_pin_state = p_message->ANT_MESSAGE_aucPayload[7]; set_led_state(); } // Transmit the current state of the digital pins on the reverse direction handle_transmit(); break; case EVENT_TX: // Transmit data on the reverse direction every channel period handle_transmit(); break; default: break; } }
/** * @brief Sets the desired LED behaviour * * Led thread handle two functionalities: * - the led state, * - diagnostic button. * The led state service is driving from Proximetry agent. The led can be set to one of three state ON,OFF,BLINKING. * The diagnostic button service allows to determine the end node connection state without console inspection. * The diagnostic button distinguish three states: * - end node disconnected from BR - led blinking with 5Hz frequency for 5s, * - end node connected with BR only - led blinking with 2Hz frequency for 5s , * - end node agent connected to Cloud Serve - led is On for 5s. */ PROCESS_THREAD(led_process, ev, data) { UNUSED(data); UNUSED(ev); PROCESS_BEGIN(); timer_set(&led_timer, LED_TOGGLE_INTERVAL); while(1) { diagnostic_button_service(); if (diagnostic_button_service_is_active()) { diagnostic_button_led_service(); } else { if (!timer_expired(&led_timer)) goto end; timer_restart(&led_timer); switch (get_settings()->led0_state) { case LED_OFF: set_led_state(LED_OFF); break; case LED_ON: set_led_state(LED_ON); break; case LED_BLINK: led_toggle(); break; default: ; } } end: PROCESS_PAUSE(); } PROCESS_END(); }
void set_num_leds(cwiid_wiimote_t *wiimote, int cnt) { static int prev_cnt = -1; unsigned char led_state = 0; if (prev_cnt == cnt) return; if (cnt > 0) led_state |= CWIID_LED1_ON; if (cnt > 1) led_state |= CWIID_LED2_ON; if (cnt > 2) led_state |= CWIID_LED3_ON; if (cnt > 3) led_state |= CWIID_LED4_ON; set_led_state(wiimote, led_state); prev_cnt = cnt; }
static void hwnotify_conversation_updated(PurpleConversation *conv, PurpleConvUpdateType type) { if( type != PURPLE_CONV_UPDATE_UNSEEN ) { return; } gboolean unread, important; get_pending_events (&unread, &important); unsigned char state = get_led_state (); state = set_led (state, color_unread, unread); state = set_led (state, color_important, important); set_led_state (state); }
int8_t set_status_led(LedFlashState_t led_flash_state, int16_t flash_rate) { set_led_state(&status_led_state, led_flash_state, flash_rate); return 0; }
int main(void) { //disable interrupts cli(); //reset watchdog wdt_reset(); wdt_disable(); init_serial_port(9600); init_rf_module(); //TODO: set-up unused pins to avoid floating! //set direction registers ( 1 - output, 0 - input ) DDRB |= ( 1 << LED1_PIN ) | ( 1 << LED2_PIN ); set_led_state(1, 0); set_led_state(2, 0); //set up WDT interrupt _WD_CONTROL_REG = (1<<WDCE) | (1<<WDE); //Start watchdog timer with 8s prescaler _WD_CONTROL_REG = (1<<WDIE) | (1<<WDE) | (1<<WDP3) | (1<<WDP0); //Enable global interrupts sei(); for ( int i = 0; i < 3; i++ ) { set_led_state(1, 1); _delay_ms(100); set_led_state(1, 0); _delay_ms(350); } uint8_t cycle_count = 0; while ( 1 ) { cycle_count++; if ( cycle_count == 3 ) { for ( int i = 0; i < 2; i++ ) { set_led_state(2, 1); _delay_ms(200); set_led_state(2, 0); _delay_ms(200); } wdt_reset(); read_temperature_data(); cycle_count = 0; }else { set_led_state(1, 1); _delay_ms(1000); set_led_state(1, 0); } //wdt_reset(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sei(); sleep_mode(); } /* float temperature, humidity; while(1) { _delay_ms(1000); power_up_sensor(); _delay_ms(2500); temperature = 0.0; humidity = 0.0; read_data(&temperature, &humidity); _delay_ms(1500); power_down_sensor(); }*/ }
int main(int argc, char *argv[]) { cwiid_wiimote_t *wiimote; /* wiimote handle */ struct cwiid_state state; /* wiimote state */ bdaddr_t bdaddr; /* bluetooth device address */ unsigned char mesg = 0; unsigned char led_state = 0; unsigned char rpt_mode = 0; unsigned char rumble = 0; int exit = 0; cwiid_set_err(err); /* Connect to address given on command-line, if present */ if (argc > 1) { str2ba(argv[1], &bdaddr); } else { bdaddr = *BDADDR_ANY; } /* Connect to the wiimote */ printf("Put Wiimote in discoverable mode now (press 1+2)...\n"); if (!(wiimote = cwiid_open(&bdaddr, 0))) { fprintf(stderr, "Unable to connect to wiimote\n"); return -1; } if (cwiid_set_mesg_callback(wiimote, cwiid_callback)) { fprintf(stderr, "Unable to set message callback\n"); } printf("Note: To demonstrate the new API interfaces, wmdemo no longer " "enables messages by default.\n" "Output can be gathered through the new state-based interface (s), " "or by enabling the messages interface (c).\n"); /* Menu */ printf("%s", MENU); while (!exit) { switch (getchar()) { case '1': toggle_bit(led_state, CWIID_LED1_ON); set_led_state(wiimote, led_state); break; case '2': toggle_bit(led_state, CWIID_LED2_ON); set_led_state(wiimote, led_state); break; case '3': toggle_bit(led_state, CWIID_LED3_ON); set_led_state(wiimote, led_state); break; case '4': toggle_bit(led_state, CWIID_LED4_ON); set_led_state(wiimote, led_state); break; case '5': toggle_bit(rumble, 1); if (cwiid_set_rumble(wiimote, rumble)) { fprintf(stderr, "Error setting rumble\n"); } break; case 'a': toggle_bit(rpt_mode, CWIID_RPT_ACC); set_rpt_mode(wiimote, rpt_mode); break; case 'b': toggle_bit(rpt_mode, CWIID_RPT_BTN); set_rpt_mode(wiimote, rpt_mode); break; case 'e': /* CWIID_RPT_EXT is actually * CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC */ toggle_bit(rpt_mode, CWIID_RPT_EXT); set_rpt_mode(wiimote, rpt_mode); break; case 'i': /* libwiimote picks the highest quality IR mode available with the * other options selected (not including as-yet-undeciphered * interleaved mode */ toggle_bit(rpt_mode, CWIID_RPT_IR); set_rpt_mode(wiimote, rpt_mode); break; case 'm': if (!mesg) { if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) { fprintf(stderr, "Error enabling messages\n"); } else { mesg = 1; } } else { if (cwiid_disable(wiimote, CWIID_FLAG_MESG_IFC)) { fprintf(stderr, "Error disabling message\n"); } else { mesg = 0; } } break; case 'p': printf("%s", MENU); break; case 'r': if (cwiid_request_status(wiimote)) { fprintf(stderr, "Error requesting status message\n"); } break; case 's': if (cwiid_get_state(wiimote, &state)) { fprintf(stderr, "Error getting state\n"); } print_state(&state); break; case 't': toggle_bit(rpt_mode, CWIID_RPT_STATUS); set_rpt_mode(wiimote, rpt_mode); break; case 'x': exit = -1; break; case '\n': break; default: fprintf(stderr, "invalid option\n"); } } if (cwiid_close(wiimote)) { fprintf(stderr, "Error on wiimote disconnect\n"); return -1; } return 0; }
int main(int argc, char *argv[]) { cwiid_wiimote_t *wiimote; /* wiimote handle */ struct cwiid_state state; /* wiimote state */ bdaddr_t bdaddr; /* bluetooth device address */ unsigned char mesg = 0; unsigned char led_state = 0; unsigned char rpt_mode = 0; unsigned char rumble = 0; int exit = 0; deviceState.numButtons = NUM_BUTTONS; deviceState.numAxis = NUM_AXIS; deviceState.numSensors = NUM_SENSORS; deviceState.axisValues = NULL; deviceState.buttonValues = NULL; deviceState.sensorValues = new SensorData[NUM_SENSORS]; cwiid_set_err(err); if (argc < 2) { fprintf(stderr, "Usage: %s HOSTNAME\n\n", argv[0]); return 1; } // if // TODO: parse data from config file!!! /* Connect to address given on command-line, if present */ if (argc > 2) { str2ba(argv[2], &bdaddr); } else { bdaddr = *BDADDR_ANY; } /* Connect to the wiimote */ printf("Put Wiimote in discoverable mode now (press 1+2)...\n"); if (!(wiimote = cwiid_open(&bdaddr, 0))) { fprintf(stderr, "Unable to connect to wiimote\n"); return -1; } if (cwiid_set_mesg_callback(wiimote, cwiid_callback)) { fprintf(stderr, "Unable to set message callback\n"); } toggle_bit(led_state, CWIID_LED1_ON); set_led_state(wiimote, led_state); if (cwiid_get_state(wiimote, &state)) { fprintf(stderr, "Error getting state\n"); } print_state(&state); toggle_bit(rpt_mode, CWIID_RPT_IR); toggle_bit(rpt_mode, CWIID_RPT_BTN); // toggle_bit(rpt_mode, CWIID_RPT_ACC); set_rpt_mode(wiimote, rpt_mode); if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC)) { fprintf(stderr, "Error enabling messages\n"); } else { mesg = 1; } if (initNetwork(argv[1], CLIENTPORT)) { fprintf(stderr, "Error at network initialization\n"); return -1; } // if bool running = true; while (running) {sleep(1);} if (cwiid_close(wiimote)) { fprintf(stderr, "Error on wiimote disconnect\n"); return -1; } return 0; }