//! @brief Send data report to Host
//!
void hid_report_in(void)
{

  int joy   =0;
  char* ptr_cram=txbuf;
  int data_to_transfer=0;

  if(!Is_usb_write_enabled(EP_HID_GENERIC_IN))
      return;                                // Not ready to send report

  // Build the Joystick report
  if(is_joystick_up()|| is_joystick_down() || is_joystick_right() || is_joystick_left() )                     //! Check for UP event
  {
    joy=0x01;
  }
  if(joy==last_joy) {
     return;                                // Same report then no send report
  }

  last_joy=joy;
  memset(txbuf, 0, RXBUF_SIZE);
  txbuf[0] = joy;

  // Send report
  data_to_transfer = sizeof(txbuf);
  while (data_to_transfer)
  {
       while (!Is_usb_in_ready(EP_HID_GENERIC_IN));

       Usb_reset_endpoint_fifo_access(EP_HID_GENERIC_IN);
       data_to_transfer = usb_write_ep_txpacket(EP_HID_GENERIC_IN, ptr_cram, data_to_transfer, (const void**)&ptr_cram);
       Usb_ack_in_ready_send(EP_HID_GENERIC_IN);
   }
}
Exemplo n.º 2
0
/*!
 *  \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;
}
Exemplo n.º 4
0
//!
//! @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;
}
Exemplo n.º 5
0
bool controller_playback_increase_volume(void)
{
  return is_joystick_up();
}
Exemplo n.º 6
0
bool controller_navigation_cursor_previous(void)
{
  return is_joystick_up();
}