static int get_player_control_flags(int player) { GameManager & m = manager; if (m.ignore_controls) return 0; int flags = 0; if (m.control_type == CONTROL_KEYBOARD) { if (is_key_pressed(m.up)) flags |= CONTROL_UP; if (is_key_pressed(m.down)) flags |= CONTROL_DOWN; if (is_key_pressed(m.left)) flags |= CONTROL_LEFT; if (is_key_pressed(m.right)) flags |= CONTROL_RIGHT; if (is_key_pressed(m.button1)) flags |= CONTROL_BUTTON1; if (is_key_pressed(m.button2)) flags |= CONTROL_BUTTON2; if (is_key_pressed(m.button3)) flags |= CONTROL_BUTTON3; if (is_key_pressed(m.button4)) flags |= CONTROL_BUTTON4; } else { flags |= get_joystick_direction_flags(player); if (is_joystick_pressed(player, JOYSTICK_BUTTON1)) flags |= CONTROL_BUTTON1; if (is_joystick_pressed(player, JOYSTICK_BUTTON2)) flags |= CONTROL_BUTTON2; if (is_joystick_pressed(player, JOYSTICK_BUTTON3)) flags |= CONTROL_BUTTON3; if (is_joystick_pressed(player, JOYSTICK_BUTTON4)) flags |= CONTROL_BUTTON4; } return flags; }
/*! * \brief Get the current joystick state. * * \param buf char buffer in which the joystick state is stored. * * \return true upon success, false if error. */ bool b_joystick_get_value( char* buf ) { // input is pulled up, if 1 : input is not active if ( !is_joystick_up() ) { Clr_bits(x_joystick, JS_EVENT_UP); } else { Set_bits(x_joystick, JS_EVENT_UP); } if ( !is_joystick_down() ) { Clr_bits(x_joystick, JS_EVENT_DOWN); } else { Set_bits(x_joystick, JS_EVENT_DOWN); } if ( !is_joystick_left() ) { Clr_bits(x_joystick, JS_EVENT_LEFT); } else { Set_bits(x_joystick, JS_EVENT_LEFT); } if ( !is_joystick_right() ) { Clr_bits(x_joystick, JS_EVENT_RIGHT); } else { Set_bits(x_joystick, JS_EVENT_RIGHT); } if ( !is_joystick_pressed() ) { Clr_bits(x_joystick, JS_EVENT_PUSH); } else { Set_bits(x_joystick, JS_EVENT_PUSH); } // Build the log string. sprintf( buf, "%s\r\n", (portCHAR *)acpc_js_events[x_joystick]); return true; }
//! //! @brief Looks for HID events. //! bool is_usb_hid_event(void) { static bool b_on_off = false; static bool b_prev = false; static bool b_next = false; static bool b_vol_up = false; static bool b_vol_dn = false; // Management of Play/Pause // if(is_joystick_pressed() && b_on_off==false) { b_on_off = true; key = HID_PLAY_PAUSE; et024006_PrintString("PLAY", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } if(!is_joystick_pressed() && b_on_off==true) { b_on_off = false; key = 0; et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } // Management of Prev // if (is_joystick_left() && b_prev == false) { b_prev = true; key = HID_PREV; et024006_PrintString("PREV", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } if (!is_joystick_left() && b_prev == true) { b_prev = false; key = 0; et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } // Management of Next // if (is_joystick_right() && b_next == false) { b_next = true; key = HID_NEXT; et024006_PrintString("NEXT", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } if (!is_joystick_right() && b_next == true) { b_next = false; key = 0; et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } // Management of Vol - // if (is_joystick_down() && b_vol_dn == false) { key = HID_VOL_DN; b_vol_dn = true; et024006_PrintString("VOL-", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } if (!is_joystick_down() && b_vol_dn == true) { b_vol_dn = false; key = 0; et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } // Management of Vol + // if (is_joystick_up() && b_vol_up == false) { key = HID_VOL_UP; b_vol_up = true; et024006_PrintString("VOL+", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } if (!is_joystick_up() && b_vol_up == true) { b_vol_up = false; key = 0; et024006_PrintString(" ", (const unsigned char *)&FONT8x8, 153, 70+4, BLUE, WHITE); return true; } return false; }
void device_audio_task(void) #endif { #if( BOARD!=EVK1105) || (DEFAULT_DACS!=AUDIO_MIXER_DAC_AIC23B) uint32_t i; #endif uint32_t fifo_cnt; int stream_status; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); LED_On(LED0); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_DAUDIO_PERIOD); // First, check the device enumeration state if (!Is_device_enumerated()) { mmi_state=0; continue; } #else // First, check the device enumeration state if (!Is_device_enumerated()) { mmi_state=0; return; } #endif // FREERTOS_USED mmi_display(); #if( BOARD!=EVK1105) || (DEFAULT_DACS!=AUDIO_MIXER_DAC_AIC23B) // Microphone emulation // if ( is_joystick_pressed() ) { if (Is_usb_write_enabled(EP_AUDIO_IN)) // Endpoint buffer free ? { Usb_reset_endpoint_fifo_access(EP_AUDIO_IN); for( i=0 ; i<EP_SIZE_IN ; i++ ) // Fill endpoint with sample raw { if(mute==false) { uint8_t sample; sample = sample_sound[dat_sample_index++]; LED_Set_Intensity(LED0, sample); Usb_write_endpoint_data(EP_AUDIO_IN, 8, sample); if (dat_sample_index >= SAMPLE_SOUND_LEN) { dat_sample_index=0; } } else { LED_Set_Intensity(LED0, 0); Usb_write_endpoint_data(EP_AUDIO_IN, 8, 0x00); } } Usb_ack_in_ready_send(EP_AUDIO_IN); } } #else // Handle input stream from microphone if( !b_microphone_started && (Is_usb_write_enabled(EP_AUDIO_IN)) && audio_mixer_dacs_input(NULL, 0) ) { // Start ADC conversion. This will launch the IRL in background... mic_buf_id = 0; mic_frame_id=2; microphone[mic_buf_id].size=45; audio_mixer_dacs_input(microphone[0].buffer, 45 /*microphone[mic_buf_id].size*/); audio_mixer_dacs_input(microphone[1].buffer, 45 /*microphone[mic_buf_id].size*/); b_microphone_started=true; } #endif // Handle incoming audio samples // if((Is_usb_out_received(EP_AUDIO_OUT) ) /*&& (Is_usb_stall(EP_AUDIO_OUT)==false)*/) { stream_status = usb_stream_input(USB_STREAM_DEVICE, EP_AUDIO_OUT, &fifo_cnt); Usb_ack_out_received_free(EP_AUDIO_OUT); mmi_activity_display(false, fifo_cnt); } #if USB_RESYNC_AUDIO_STREAM && (USB_RESYNC_AUDIO_STREAM==true) usb_stream_resync(); #endif #ifdef FREERTOS_USED } #endif }
inline int get_joystick_flag(int n, int button) { if (!is_joystick_pressed(n, button)) return 0; return 8 << button; }
//! //! @brief Looks for mouse events. //! bool is_usb_mouse_event( void ) { static uint8_t disp=1; static uint16_t count=0; #if BOARD != EVK1104 && BOARD != UC3C_EK && BOARD != EVK1105 static bool old_click_0=false; // false means released, true means pushed static bool old_click_1=false; // false means released, true means pushed #endif #if BOARD == EVK1100 static bool old_click_2=false; // false means released, true means pushed #endif bool b_activity; u8_report_buttons=0; u8_report_disp_x=0; u8_report_disp_y=0; u8_report_disp_wheel=0; b_activity=false; #if BOARD == EVK1101 signed int res; // Get accelerometer acquisition and process data acc_update(); // Look joystick activity for the Wheel events // input is pulled up, if 1 : input is not active if( is_joystick_up() ) u8_report_disp_wheel=disp, b_activity=true; if( is_joystick_down() ) u8_report_disp_wheel=-disp, b_activity=true; // Look accelerometer activity for the X and Y events if( 0!=(res=is_acc_abs_angle_x(40)) ) { if( res>0 ) u8_report_disp_x=-10*disp, b_activity=true; else if( res<0 ) u8_report_disp_x=10*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_x(30)) ) { if( res>0 ) u8_report_disp_x=-6*disp, b_activity=true; else if( res<0 ) u8_report_disp_x=6*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_x(20)) ) { if( res>0 ) u8_report_disp_x=-4*disp, b_activity=true; else if( res<0 ) u8_report_disp_x=4*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_x(15)) ) { if( res>0 ) u8_report_disp_x=-2*disp, b_activity=true; else if( res<0 ) u8_report_disp_x=2*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_x(10)) ) { if( res>0 ) u8_report_disp_x=-disp, b_activity=true; else if( res<0 ) u8_report_disp_x=disp, b_activity=true; } if( 0!=(res=is_acc_abs_angle_y(40)) ) { if( res>0 ) u8_report_disp_y=-10*disp, b_activity=true; else if( res<0 ) u8_report_disp_y=10*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_y(30)) ) { if( res>0 ) u8_report_disp_y=-6*disp, b_activity=true; else if( res<0 ) u8_report_disp_y=6*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_y(20)) ) { if( res>0 ) u8_report_disp_y=-4*disp, b_activity=true; else if( res<0 ) u8_report_disp_y=4*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_y(15)) ) { if( res>0 ) u8_report_disp_y=-2*disp, b_activity=true; else if( res<0 ) u8_report_disp_y=2*disp, b_activity=true; } else if( 0!=(res=is_acc_abs_angle_y(10)) ) { if( res>0 ) u8_report_disp_y=-disp, b_activity=true; else if( res<0 ) u8_report_disp_y=disp, b_activity=true; } #elif BOARD == EVK1100 // Look Joystick activity for the X and Y events // input is pulled up, if 1 : input is not active if (is_joystick_right()) u8_report_disp_x=disp, b_activity=true; if (is_joystick_left()) u8_report_disp_x=-disp, b_activity=true; if (is_joystick_down()) u8_report_disp_y=disp, b_activity=true; if (is_joystick_up()) u8_report_disp_y=-disp, b_activity=true; #elif BOARD == EVK1105 // Right if (is_touch_sensor_2()) u8_report_disp_x=disp, b_activity=true; // Left if (is_touch_sensor_3()) u8_report_disp_x=-disp, b_activity=true; // Down if (is_touch_sensor_1()) u8_report_disp_y=disp, b_activity=true; // Up if (is_touch_sensor_0()) u8_report_disp_y=-disp, b_activity=true; #elif BOARD == EVK1104 if (gpio_get_pin_value(GPIO_PUSH_BUTTON_SW2) == GPIO_PUSH_BUTTON_SW2_PRESSED) u8_report_disp_y=-disp, b_activity=true; #elif BOARD == UC3C_EK // mouse pointer down if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_0)) { u8_report_disp_y=disp, b_activity=true; } // mouse pointer up if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_1)) { u8_report_disp_y=-disp, b_activity=true; } #endif if( b_activity ) { count++; if( count >= DISP_LIMIT_HIGH ) disp=3; else if( count >= DISP_LIMIT_LOW ) disp=2; } else count=0, disp=1; // Look for button activity #if BOARD != EVK1104 && BOARD != UC3C_EK && BOARD != EVK1105 // input is pulled up, if 1 : input is not active if( (!gpio_get_pin_value(GPIO_PUSH_BUTTON_0)) || (is_joystick_pressed() ) ) { Set_bits(u8_report_buttons, BUTTON_0_EVENT_PUSH); if( old_click_0==false ) old_click_0=true, b_activity=true; } else if( old_click_0==true ) old_click_0=false, b_activity=true; if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_1) ) { Set_bits(u8_report_buttons, BUTTON_1_EVENT_PUSH); if( old_click_1==false ) old_click_1=true, b_activity=true; } else if( old_click_1==true ) old_click_1=false, b_activity=true; #endif #if BOARD == EVK1100 if( !gpio_get_pin_value(GPIO_PUSH_BUTTON_2) ) { Set_bits(u8_report_buttons, BUTTON_2_EVENT_PUSH); if( old_click_2==false ) old_click_2=true, b_activity=true; } else if( old_click_2==true ) old_click_2=false, b_activity=true; #endif if( b_activity ) return true; else return false; }