int16_t spektrum_satellite_get_channel(uint8_t index) { int32_t i; if (time_keeper_get_millis()-last_update>20) { #ifdef KEYBOARD_ACTIVE get_keyboard_input(&joystick_axes); #endif get_joystick_status(joystick_filedescriptor, &joystick_axes, &joystick_buttons, 16, 16); for (i=0; i<16; i++) { if (joystick_axes[i]>joy_max[i]) joy_max[i]=joystick_axes[i]; if (joystick_axes[i]<joy_min[i]) joy_min[i]=joystick_axes[i]; } sat.channels[RC_ROLL] = joystick_axes[JOY_ROLL]*J_GAIN/ (joy_max[JOY_ROLL]-joy_min[JOY_ROLL]); sat.channels[RC_PITCH] = joystick_axes[JOY_PITCH]*J_GAIN/ (joy_max[JOY_PITCH]-joy_min[JOY_PITCH]); sat.channels[RC_YAW] = joystick_axes[JOY_YAW]*J_GAIN/ (joy_max[JOY_YAW]-joy_min[JOY_YAW]); sat.channels[RC_THROTTLE] = -joystick_axes[JOY_THROTTLE]*J_GAIN/ (joy_max[JOY_THROTTLE]-joy_min[JOY_THROTTLE]); sat.channels[RC_SAFETY] = joystick_axes[JOY_SAFETY] *J_GAIN/ (joy_max[JOY_SAFETY]-joy_min[JOY_SAFETY]); sat.channels[RC_ID_MODE] =joystick_axes[JOY_ID_MODE]*J_GAIN/ (joy_max[JOY_ID_MODE]-joy_min[JOY_ID_MODE]); last_update=time_keeper_get_millis(); } return sat.channels[index]; }
TJOYSTICK_EVENT test_joystick(){ TJOYSTICK_EVENT result; result = no_pressing; uint8_t j_status; j_status = get_joystick_status(); switch(j_status) //проверяем, что нажато { case UP_KEY_MASK: { if(joystick_key_pressing_duration.key_up>= SHORT_DURATION) { result=key_up_pressing; joystick_key_pressing_duration.key_up =0; joystick_key_pressing_duration.key_up_inc=0; } else { joystick_key_pressing_duration.key_up += joystick_key_pressing_duration.key_up_inc; result = joystick_event; } } break; case RIGHT_KEY_MASK: { if(joystick_key_pressing_duration.key_right>= SHORT_DURATION) { result=key_right_pressing; joystick_key_pressing_duration.key_right =0; joystick_key_pressing_duration.key_right_inc=0; } else { joystick_key_pressing_duration.key_right += joystick_key_pressing_duration.key_right_inc; result = joystick_event; } } break; case DOWN_KEY_MASK: { if(joystick_key_pressing_duration.key_down>= SHORT_DURATION) { result=key_down_pressing; joystick_key_pressing_duration.key_down =0; joystick_key_pressing_duration.key_down_inc=0; } else { joystick_key_pressing_duration.key_down += joystick_key_pressing_duration.key_down_inc; result = joystick_event; } } break; case LEFT_KEY_MASK: { if(joystick_key_pressing_duration.key_left>= SHORT_DURATION) { result=key_left_pressing; joystick_key_pressing_duration.key_left =0; joystick_key_pressing_duration.key_left_inc=0; } else { joystick_key_pressing_duration.key_left += joystick_key_pressing_duration.key_left_inc; result = joystick_event; } } break; case CENTRAL_KEY_MASK: { if(joystick_key_pressing_duration.key_central>= SHORT_DURATION) { result=key_central_pressing; joystick_key_pressing_duration.key_central =0; joystick_key_pressing_duration.key_central_inc=0; } else { joystick_key_pressing_duration.key_central += joystick_key_pressing_duration.key_central_inc; result = joystick_event; } } break; case 0: { init_joystick(); } break; default: { joystick_key_pressing_duration.key_up=0; joystick_key_pressing_duration.key_up_inc=0; joystick_key_pressing_duration.key_right=0; joystick_key_pressing_duration.key_right_inc=0; joystick_key_pressing_duration.key_down=0; joystick_key_pressing_duration.key_down_inc=0; joystick_key_pressing_duration.key_left=0; joystick_key_pressing_duration.key_left_inc=0; joystick_key_pressing_duration.key_central=0; joystick_key_pressing_duration.key_central_inc=0; } } return result; }
void level::playStick() { vector2D current_speed; current_speed=(playerShip->get_speed()); static wwvi_js_event js_state; static bool use_flag = false; static bool brake_flag = true; static bool boost_flag = true; js_state.button[9]=0; //start button if (get_joystick_status(&js_state)==0) { double out = 0; if (js_state.button[9]) { pauseResume(); } if (js_state.button[7]) { use_flag = true; playerShip->accelerate(); } else if (js_state.button[6]==1) { use_flag = true; playerShip->decelerate(); } else if (js_state.button[5] && boost_flag) { use_flag = true; playerShip->turbo_boost(); boost_flag = false; } else if (!js_state.button[5] && ! boost_flag) { use_flag = true; playerShip->e_brake(); boost_flag = true; } else if (js_state.button[4] && brake_flag) { use_flag = true; playerShip->e_brake(); brake_flag = false; } else if (!js_state.button[4] && ! brake_flag) { use_flag = true; playerShip->turbo_boost(); brake_flag = true; } else if (use_flag) { playerShip->release_acc(); } double newAngle=playerShip->get_angle(); double newX = (double) js_state.stick1_x; double newY = (double) js_state.stick1_y; if (newX != 0) { jX = newX; } if (newY != 0) { jY = -newY; } if (jX > 0) { newAngle = atan(jY/jX); playerShip->set_angle(newAngle); } else if (jX < 0 ) { newAngle = M_PI+atan(jY/jX); playerShip->set_angle(newAngle); } else { if (jY != 0) { newAngle = ((jY > 0) ? -1 : ((jY < 0) ? 1 : 0) )*atan(M_PI/2); playerShip->set_angle(newAngle); } } out = (double) js_state.stick2_x; if (out != 0) { mX = out; } out = (double) js_state.stick2_y; if (out != 0) { mY = -out; } } }