void ui_init(void) { LED_On(LED0); LED_Off(LED1); }
void ui_process(uint16_t framenumber) { bool b_btn_state, success; static bool btn_last_state = false; static bool sequence_running = false; static uint8_t u8_sequence_pos = 0; uint8_t u8_value; static uint16_t cpt_sof = 0; if ((framenumber % 1000) == 0) { LED_On(LED0); } if ((framenumber % 1000) == 500) { LED_Off(LED0); } /* Scan process running each 2ms */ cpt_sof++; if ((cpt_sof % 2) == 0) { return; } /* Uses buttons to move mouse */ if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_1)) { udi_hid_mouse_moveY(-MOUSE_MOVE_RANGE); } /* SW0 down to send keys sequence */ b_btn_state = (!ioport_get_pin_level(GPIO_PUSH_BUTTON_1)); if (b_btn_state != btn_last_state) { btn_last_state = b_btn_state; sequence_running = true; } /* Sequence process running each period */ if (SEQUENCE_PERIOD > cpt_sof) { return; } cpt_sof = 0; if (sequence_running) { /* Send next key */ u8_value = ui_sequence[u8_sequence_pos].u8_value; if (u8_value!=0) { if (ui_sequence[u8_sequence_pos].b_modifier) { if (ui_sequence[u8_sequence_pos].b_down) { success = udi_hid_kbd_modifier_down(u8_value); } else { success = udi_hid_kbd_modifier_up(u8_value); } } else { if (ui_sequence[u8_sequence_pos].b_down) { success = udi_hid_kbd_down(u8_value); } else { success = udi_hid_kbd_up(u8_value); } } if (!success) { return; /* Retry it on next schedule */ } } /* Valid sequence position */ u8_sequence_pos++; if (u8_sequence_pos >= sizeof(ui_sequence) / sizeof(ui_sequence[0])) { u8_sequence_pos = 0; sequence_running = false; } } }
void ui_powerdown(void) { LED_Off(LED0_GPIO); LED_Off(LED1_GPIO); }
void ui_com_close(uint8_t port) { UNUSED(port); LED_Off(LED1); }
void ui_stop_read(void) { LED_Off(LED1); }
void ui_com_close(uint8_t port) { LED_Off(LED2); LED_Off(LED3); }
/** * @brief Main function of the coordinator application * * This function initializes the MAC, initiates a MLME reset request * (@ref wpan_mlme_reset_req()), and implements a the main loop. */ int main(void) { /* Initialize the board. * The board-specific conf_board.h file contains the configuration of * the board initialization. */ irq_initialize_vectors(); board_init(); sysclk_init(); sw_timer_init(); if(MAC_SUCCESS != wpan_init()) { app_alert(); } /* Initialize LEDs. */ LED_On(LED_START); // indicating application is started LED_Off(LED_NWK_SETUP); // indicating network is started LED_Off(LED_DATA); // indicating data transmission cpu_irq_enable(); #ifdef SIO_HUB /* Initialize the serial interface used for communication with terminal program. */ sio2host_init(); /* To make sure the Hyper Terminal Connected to the system*/ sio2host_getchar(); printf("\nBeacon_Application\r\n\n"); printf("\nCoordinator\r\n\n"); #endif /* SIO_HUB */ sw_timer_get_id(&APP_TIMER_INDIRECT_DATA); sw_timer_get_id(&APP_TIMER_BCN_PAYLOAD_UPDATE); sw_timer_get_id(&APP_TIMER_BC_DATA); /* * Reset the MAC layer to the default values. * This request will cause a mlme reset confirm message -> * usr_mlme_reset_conf */ wpan_mlme_reset_req(true); #ifdef GPIO_PUSH_BUTTON_0 dst_addr.AddrMode = 2; dst_addr.PANId = DEFAULT_PAN_ID; #endif //GPIO_PUSH_BUTTON_0 while (true) { wpan_task(); #ifdef GPIO_PUSH_BUTTON_0 if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) { delay_ms(DEBOUNCE_DELAY_MS); if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) { dst_addr.Addr.short_address = BROADCAST; wpan_mcps_data_req(FCF_SHORT_ADDR, &dst_addr, 14, (uint8_t *)"Broadcast Data", 1, WPAN_TXOPT_OFF); } } #endif //GPIO_PUSH_BUTTON_0 } }
void ui_init(void) { // Initialize LEDs LED_On(LED0_GPIO); LED_Off(LED1_GPIO); }
void ui_com_close(uint8_t port) { LED_Off(LED1_GPIO); }
void ui_stop_write(void) { LED_Off(LED2_GPIO); }
//Обрабатываем значения HoldingRegisters void ModbusSaver() { switch (usRegHoldingBuf[MB_OFFSET+MB_COMMAND]) { case 1: wdt_enable(WDTO_15MS); // enable watchdog while(1); // wait for watchdog to reset processor break; break; case 2: ADXL345_Calibrate(); break; } usRegHoldingBuf[MB_OFFSET+MB_COMMAND] = 0; if (usRegHoldingBuf[MB_OFFSET+MB_LED_BLUE]) { LED_On(LED_BLUE); } else { LED_Off(LED_BLUE); } if (usRegHoldingBuf[MB_OFFSET+MB_LED_GREEN]) { LED_On(LED_GREEN); } else { LED_Off(LED_GREEN); } if (bit_is_set(usRegHoldingBuf[MB_OFFSET+MB_SOUND], 0)) { Sound_On(); } else { Sound_Off(); } if (usRegHoldingBuf[MB_OFFSET+MB_ALL]<16000UL) { usRegHoldingBuf[MB_OFFSET+MB_ALL]=16000UL; } if (bit_is_set(usRegHoldingBuf[MB_OFFSET+MB_MANUAL], 4)) { float speeds[4]; speeds[FRONT_LEFT] = (float)usRegHoldingBuf[MB_OFFSET + MB_FRONT_LEFT]; speeds[FRONT_RIGHT] = (float)usRegHoldingBuf[MB_OFFSET + MB_FRONT_RIGHT]; speeds[REAR_LEFT] = (float)usRegHoldingBuf[MB_OFFSET + MB_REAR_LEFT]; speeds[REAR_RIGHT] = (float)usRegHoldingBuf[MB_OFFSET + MB_REAR_RIGHT]; SetMotors(speeds); } else { usRegHoldingBuf[MB_OFFSET + MB_FRONT_LEFT] = counter[FRONT_LEFT]; usRegHoldingBuf[MB_OFFSET + MB_FRONT_RIGHT] = counter[FRONT_RIGHT]; usRegHoldingBuf[MB_OFFSET + MB_REAR_LEFT] = counter[REAR_LEFT]; usRegHoldingBuf[MB_OFFSET + MB_REAR_RIGHT] = counter[REAR_RIGHT]; } //t_Ox.value = 0; //t_Oy.value = 0; t_Ox.array[0] = usRegHoldingBuf[2]; t_Ox.array[1] = usRegHoldingBuf[3]; t_Oy.array[0] = usRegHoldingBuf[4]; t_Oy.array[1] = usRegHoldingBuf[5]; t_Oz.array[0] = usRegHoldingBuf[6]; t_Oz.array[1] = usRegHoldingBuf[7]; ModbusEEPROMLoader(); }
void ui_stop_read(void) { LED_Off(LED1_GPIO); }
void ui_init(void) { LED_Off(LED0_GPIO); LED_Off(LED1_GPIO); }
void ui_process(uint16_t framenumber) { bool b_btn_state, success; static bool btn_last_state = false; static bool sequence_running = false; static uint8_t sequence_pos = 0; uint8_t value; static uint16_t cpt_sof = 0; if ((framenumber % 1000) == 0) { LED_On(LED0); } if ((framenumber % 1000) == 500) { LED_Off(LED0); } /* Scan process running each 2ms */ cpt_sof++; if ((cpt_sof % 2) == 0) { return; } /* Scan button on push button (SW0) to send keys sequence */ b_btn_state = !ioport_get_pin_level(GPIO_PUSH_BUTTON_1); if (b_btn_state != btn_last_state) { btn_last_state = b_btn_state; if (btn_wakeup) { if (!b_btn_state) { btn_wakeup = false; } } else { sequence_running = true; } } /* Sequence process running each period */ if (SEQUENCE_PERIOD > cpt_sof) { return; } cpt_sof = 0; if (sequence_running) { /* Send next key */ value = ui_sequence[sequence_pos].value; if (value!=0) { if (ui_sequence[sequence_pos].b_modifier) { if (ui_sequence[sequence_pos].b_down) { success = udi_hid_kbd_modifier_down(value); } else { success = udi_hid_kbd_modifier_up(value); } } else { if (ui_sequence[sequence_pos].b_down) { success = udi_hid_kbd_down(value); } else { success = udi_hid_kbd_up(value); } } if (!success) { return; /* Retry it on next schedule */ } } /* Valid sequence position */ sequence_pos++; if (sequence_pos >= sizeof(ui_sequence) / sizeof(ui_sequence[0])) { sequence_pos = 0; sequence_running = false; } } }
/** * \brief Application entry point for TWI EEPROM example. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint32_t i; twihs_options_t opt; twihs_packet_t packet_tx, packet_rx; /* Initialize the SAM system */ sysclk_init(); /* Initialize the board */ board_init(); /* Turn off LEDs */ LED_Off(LED0); /* Initialize the console UART */ configure_console(); /* Output example information */ puts(STRING_HEADER); /* Configure systick for 1 ms */ puts("Configure system tick to get 1ms tick period.\r"); if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("-E- Systick configuration error\r"); while (1) { /* Capture error */ } } /* Enable the peripheral clock for TWI */ pmc_enable_periph_clk(BOARD_ID_TWIHS_EEPROM); /* Configure the options of TWI driver */ opt.master_clk = sysclk_get_cpu_hz(); opt.speed = TWIHS_CLK; /* Configure the data packet to be transmitted */ packet_tx.chip = AT24C_ADDRESS; packet_tx.addr[0] = EEPROM_MEM_ADDR >> 8; packet_tx.addr[1] = EEPROM_MEM_ADDR; packet_tx.addr_length = EEPROM_MEM_ADDR_LENGTH; packet_tx.buffer = (uint8_t *) test_data_tx; packet_tx.length = TEST_DATA_LENGTH; /* Configure the data packet to be received */ packet_rx.chip = packet_tx.chip; packet_rx.addr[0] = packet_tx.addr[0]; packet_rx.addr[1] = packet_tx.addr[1]; packet_rx.addr_length = packet_tx.addr_length; packet_rx.buffer = gs_uc_test_data_rx; packet_rx.length = packet_tx.length; if (twihs_master_init(BOARD_BASE_TWIHS_EEPROM, &opt) != TWIHS_SUCCESS) { puts("-E-\tTWI master initialization failed.\r"); while (1) { /* Capture error */ } } /* Send test pattern to EEPROM */ if (twihs_master_write(BOARD_BASE_TWIHS_EEPROM, &packet_tx) != TWIHS_SUCCESS) { puts("-E-\tTWI master write packet failed.\r"); while (1) { /* Capture error */ } } puts("Write:\tOK!\n\r"); /* Wait at least 10 ms */ mdelay(WAIT_TIME); /* Get memory from EEPROM*/ if (twihs_master_read(BOARD_BASE_TWIHS_EEPROM, &packet_rx) != TWIHS_SUCCESS) { puts("-E-\tTWI master read packet failed.\r"); while (1) { /* Capture error */ } } puts("Read:\tOK!\r"); /* Compare the sent and the received */ for (i = 0; i < TEST_DATA_LENGTH; i++) { if (test_data_tx[i] != gs_uc_test_data_rx[i]) { /* No match */ puts("Data comparison:\tUnmatched!\r"); while (1) { /* Capture error */ } } } /* Match */ puts("Data comparison:\tMatched!\r"); LED_On(LED0); while (1) { } }
void ui_com_rx_stop(void) { LED_Off(LED3_GPIO); }
void LED_Init (void) { LED_Off(0); /* Turn off all of the LEDs */ }
void ui_com_tx_stop(void) { LED_Off(LED2_GPIO); }
void ui_com_rx_stop(void) { LED_Off(LED3); }
void ui_process(uint16_t framenumber) { bool b_btn_state, success; static bool btn_last_state = false; static bool sequence_running = false; static uint8_t u8_sequence_pos = 0; uint8_t u8_value; static uint16_t cpt_sof = 0; if ((framenumber % 1000) == 0) { LED_On(LED0); } if ((framenumber % 1000) == 500) { LED_Off(LED0); } // Scan process running each 2ms cpt_sof++; if ((cpt_sof % 2) == 0) { return; } // Buttons down to send keys sequence b_btn_state = (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)); if (b_btn_state != btn_last_state) { btn_last_state = b_btn_state; if (btn_wakeup) { if (!b_btn_state) { btn_wakeup = false; } } else { sequence_running = true; } } // Sequence process running each period if (SEQUENCE_PERIOD > cpt_sof) { return; } cpt_sof = 0; if (sequence_running) { // Send next key u8_value = ui_sequence[u8_sequence_pos].u8_value; if (u8_value!=0) { if (ui_sequence[u8_sequence_pos].b_modifier) { if (ui_sequence[u8_sequence_pos].b_down) { success = udi_hid_kbd_modifier_down(u8_value); } else { success = udi_hid_kbd_modifier_up(u8_value); } } else { if (ui_sequence[u8_sequence_pos].b_down) { success = udi_hid_kbd_down(u8_value); } else { success = udi_hid_kbd_up(u8_value); } } if (!success) { return; // Retry it on next schedule } } // Valid sequence position u8_sequence_pos++; if (u8_sequence_pos >= sizeof(ui_sequence) / sizeof(ui_sequence[0])) { u8_sequence_pos = 0; sequence_running = false; } } }
void ui_powerdown(void) { LED_Off(LED0); LED_Off(LED1); }
void device_full_custom_task(void) #endif { U32 time=0; bool startup=true; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DFC_PERIOD); if( startup ) { time+=configTSK_USB_DFC_PERIOD; #define STARTUP_LED_DELAY 100 if ( time== 1*STARTUP_LED_DELAY ) LED_On( LED_MONO0_GREEN ); else if( time== 2*STARTUP_LED_DELAY ) LED_On( LED_MONO1_GREEN ); else if( time== 3*STARTUP_LED_DELAY ) LED_On( LED_MONO2_GREEN ); else if( time== 4*STARTUP_LED_DELAY ) LED_On( LED_MONO3_GREEN ); else if( time== 5*STARTUP_LED_DELAY ) LED_Off( LED_MONO0_GREEN ); else if( time== 6*STARTUP_LED_DELAY ) LED_Off( LED_MONO1_GREEN ); else if( time== 7*STARTUP_LED_DELAY ) LED_Off( LED_MONO2_GREEN ); else if( time== 8*STARTUP_LED_DELAY ) LED_Off( LED_MONO3_GREEN ); else if( time== 9*STARTUP_LED_DELAY ) startup=false; } // First, check the device enumeration state if (!Is_device_enumerated()) continue; #else // First, check the device enumeration state if (!Is_device_enumerated()) return; #endif // FREERTOS_USED if(Is_usb_out_received(EP_FC_OUT)) { U32 nchar; Usb_reset_endpoint_fifo_access(EP_FC_OUT); memset(rxbuf, 0, RXBUF_SIZE); usb_read_ep_rxpacket(EP_FC_OUT, &rxbuf, RXBUF_SIZE, NULL); Usb_ack_out_received_free(EP_FC_OUT); //printf("Received %s\n\r", rxbuf); if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=temp") ) { // Temperature sensor nchar=build_answer(txbuf, "temp"); b_temperature_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=js") ) { // Joystick nchar=build_answer(txbuf, "js"); b_joystick_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb1") ) { // Push button 1 nchar=build_answer(txbuf, "pb1"); b_pushb1_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb2") ) { // Push button 2 nchar=build_answer(txbuf, "pb2"); b_pushb2_get_value( txbuf+nchar ); b_report_pending=true; } #if BOARD == EVK1100 else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=pb3") ) { // Push button 3 nchar=build_answer(txbuf, "pb3"); sprintf( txbuf+nchar, "RELEASE\r\n"); b_report_pending=true; } #endif else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=light") ) { // light U32 value; nchar=build_answer(txbuf, "light"); b_light_get_value( txbuf+nchar, &value ); e_ledm_refresh_intensity( value ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm1") ) { // led1 nchar=build_answer(txbuf, "ledm1"); b_ledm1_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm2") ) { // led2 nchar=build_answer(txbuf, "ledm2"); b_ledm2_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm3") ) { // led3 nchar=build_answer(txbuf, "ledm3"); b_ledm3_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_actuator_value actuator=ledm4") ) { // led4 nchar=build_answer(txbuf, "ledm4"); b_ledm4_get_value( txbuf+nchar ); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM1, strlen(STR_SET_LEDM1)) ) { // led1 nchar=build_answer(txbuf, "ledm1"); e_ledm1_set_value(rxbuf+strlen(STR_SET_LEDM1), txbuf+nchar); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM2, strlen(STR_SET_LEDM2)) ) { // led2 nchar=build_answer(txbuf, "ledm2"); e_ledm2_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM3, strlen(STR_SET_LEDM3)) ) { // led3 nchar=build_answer(txbuf, "ledm3"); e_ledm3_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar); b_report_pending=true; } else if( !strncmp((const char*)rxbuf, STR_SET_LEDM4, strlen(STR_SET_LEDM4)) ) { // led4 nchar=build_answer(txbuf, "ledm4"); e_ledm4_set_value(rxbuf+strlen(STR_SET_LEDM2), txbuf+nchar); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accx") ) { // accelerometer nchar=build_answer(txbuf, "accx"); accelerometer_measure(0, txbuf+nchar); b_report_pending=true; } else if( !strcmp((const char*)rxbuf, "get_sensor_value sensor=accy") ) { // accelerometer nchar=build_answer(txbuf, "accy"); accelerometer_measure(1, txbuf+nchar); b_report_pending=true; } } if( b_report_pending && Is_usb_in_ready(EP_FC_IN) ) { U8 data_to_transfer; char* ptr_cram=txbuf; //printf( "Sending %s", txbuf); #if 0 Usb_reset_endpoint_fifo_access(EP_FC_IN); usb_write_ep_txpacket(EP_FC_IN, &txbuf, TXBUF_SIZE, NULL); Usb_ack_in_ready_send(EP_FC_IN); #endif data_to_transfer = strlen(txbuf); while (data_to_transfer) { while (!Is_usb_in_ready(EP_FC_IN)); Usb_reset_endpoint_fifo_access(EP_FC_IN); data_to_transfer = usb_write_ep_txpacket(EP_FC_IN, ptr_cram, data_to_transfer, (const void**)&ptr_cram); Usb_ack_in_ready_send(EP_FC_IN); } b_report_pending=false; } #ifdef FREERTOS_USED } #endif }
void ui_com_tx_stop(void) { LED_Off(LED1); }
void ui_powerdown(void) { LED_Off(); }
void ui_stop_write(void) { LED_Off(LED1); }
void ui_com_tx_stop(void) { LED_Off(LED_BI1_GREEN); }
/** * \name Main user interface functions * @{ */ void ui_init(void) { /* Initialize LEDs */ LED_Off(LED0); }
void ui_com_rx_stop(void) { LED_Off(LED_BI0_GREEN); }
void ui_process(uint16_t framenumber) { bool b_btn_state, success; static bool btn_last_state = false; static bool sequence_running = false; static uint8_t sequence_pos = 0; uint8_t value; static uint16_t cpt_sof = 0; if ((framenumber % 1000) == 0) { LED_On(LED0_GPIO); } if ((framenumber % 1000) == 500) { LED_Off(LED0_GPIO); } // Scan process running each 2ms cpt_sof++; if ((cpt_sof % 2) == 0) { return; } // Scan buttons on switch 0 to send keys sequence b_btn_state = (!gpio_pin_is_high(GPIO_PUSH_BUTTON_1)) ? true : false; if (b_btn_state != btn_last_state) { btn_last_state = b_btn_state; sequence_running = true; } // Sequence process running each period if (SEQUENCE_PERIOD > cpt_sof) { return; } cpt_sof = 0; if (sequence_running) { // Send next key value = ui_sequence[sequence_pos].value; if (value!=0) { if (ui_sequence[sequence_pos].b_modifier) { if (ui_sequence[sequence_pos].b_down) { success = udi_hid_kbd_modifier_down(value); } else { success = udi_hid_kbd_modifier_up(value); } } else { if (ui_sequence[sequence_pos].b_down) { success = udi_hid_kbd_down(value); } else { success = udi_hid_kbd_up(value); } } if (!success) { return; // Retry it on next schedule } } // Valid sequence position sequence_pos++; if (sequence_pos >= sizeof(ui_sequence) / sizeof(ui_sequence[0])) { sequence_pos = 0; sequence_running = false; } } }
void ui_powerdown(void) { LED_Off(LED_0_PIN); }