Autor Tema: PIC18f2550__mouse_HID  (Leído 1238 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado jcamilo_net

  • PIC10
  • *
  • Mensajes: 1
PIC18f2550__mouse_HID
« en: 15 de Marzo de 2011, 20:56:45 »
hola compañer@s,
estoy haciendo un dispositivo HID tipo mouse y ya con este código de abajo puedo mover el mouse a mi antojo con los sw1-4, la pregunta es si alguien ha trabajado o me podría ayudar a colocar el sw5 como el botón del clic, deber ser con la función HIDTxReport() pero no se como
gracias por su tiempo, estamos hablando;

/** I N C L U D E S **********************************************************/
#include <p18cxxx.h>
#include <usart.h>
#include "system\typedefs.h"

#include "system\usb\usb.h"

#include "io_cfg.h"             // I/O pin mapping
#include "user\user_mouse.h"


//-------------------------pruebas
 
/** V A R I A B L E S ********************************************************/
#pragma udata
byte old_sw1, old_sw2, old_sw3, old_sw4, old_sw5;

BOOL emulate_mode;
//rom signed char dir_table[]={-4,-4,-4, 0, 4, 4, 4, 0};
byte movement_length;
byte vector = 0;
char buffert[3];

/** P R I V A T E  P R O T O T Y P E S ***************************************/
void BlinkUSBStatus(void);
BOOL Switch1IsPressed(void);
BOOL Switch2IsPressed(void);
BOOL Switch3IsPressed(void);
BOOL Switch4IsPressed(void);
BOOL Switch5IsPressed(void);

void Emulate_Mouse(void);

/** D E C L A R A T I O N S **************************************************/
#pragma code
void UserInit(void)
{
    mInitAllLEDs();
    mInitAllSwitches();
    old_sw1 = sw1;
    old_sw2 = sw2;
    old_sw3 = sw3;
    old_sw4 = sw4;
    old_sw5 = sw5;

    buffert[0]=0;
    buffert[1]=0;
    buffert[2]=0;
    buffert[3]=0;
   
    emulate_mode = TRUE; 
}//end UserInit

/******************************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user routines.
 *                  It is a mixture of both USB and non-USB tasks.
 *
 * Note:            None
 
 //3002689064
 *****************************************************************************/
void ProcessIO(void)
{   
    BlinkUSBStatus();
    // User Application USB tasks
    if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1)) return;

    //sla if(Switch3IsPressed())
    //sla    emulate_mode = !emulate_mode;
   
    Emulate_Mouse();
   
}//end ProcessIO

void Emulate_Mouse(void)
{
   
   
   //** prueba

   //hasta qui prueba
   
    if(emulate_mode == TRUE)
    {

      buffert[0] = 0;
      

      
      
      
      if(sw1==0) buffert[2] = -1;
      else if(sw2==0) buffert[2] = 1;
      else buffert[2] = 0;

      if(sw3==0) buffert[1] = 1;
      else if(sw4==0) buffert[1] = -1;
      else buffert[1] = 0;
      
   //   if(sw5==0) buffert[2] = 1;
         
    }
    else
        buffert[0] = buffert[1] = buffert[2] = 0;

    if(!mHIDTxIsBusy())
    {
        HIDTxReport(buffert,4);
       // movement_length=movement_length + 10;
       movement_length++;
    }//end if(mHIDIsPutReportReady())
   
   
   
}//end Emulate_Mouse

/******************************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs corresponding to
 *                  the USB device state.
 *
 * Note:            mLED macros can be found in io_cfg.h
 *                  usb_device_state is declared in usbmmap.c and is modified
 *                  in usbdrv.c, usbctrltrf.c, and usb9.c
 *****************************************************************************/
void BlinkUSBStatus(void)
{
   
   
    static word led_count=0;
   
    if(led_count == 0)led_count = 10000U;
    led_count--;

    #define mLED_Both_Off()         {mLED_1_Off();mLED_2_Off();}
    #define mLED_Both_On()          {mLED_1_On();mLED_2_On();}
    #define mLED_Only_1_On()        {mLED_1_On();mLED_2_Off();}
    #define mLED_Only_2_On()        {mLED_1_Off();mLED_2_On();}

    if(UCONbits.SUSPND == 1)
    {
        if(led_count==0)
        {
            mLED_1_Toggle();
            mLED_2 = mLED_1;        // Both blink at the same time
        }//end if
    }
    else
    {
        if(usb_device_state == DETACHED_STATE)
        {
            mLED_Both_Off();
        }
        else if(usb_device_state == ATTACHED_STATE)
        {
            mLED_Both_On();
        }
        else if(usb_device_state == POWERED_STATE)
        {
            mLED_Only_1_On();
        }
        else if(usb_device_state == DEFAULT_STATE)
        {
            mLED_Only_2_On();
        }
        else if(usb_device_state == ADDRESS_STATE)
        {
            if(led_count == 0)
            {
                mLED_1_Toggle();
                mLED_2_Off();
            }//end if
        }
        else if(usb_device_state == CONFIGURED_STATE)
        {
            if(led_count==0)
            {
                mLED_1_Toggle();
               mLED_2 = !mLED_1;       // Alternate blink               
            }//end if
        }//end if(...)
    }//end if(UCONbits.SUSPND...)

}//end BlinkUSBStatus


BOOL Switch1IsPressed(void)
{
    if(sw1 != old_sw1)
    {
        old_sw1 = sw1;                  // Save new value
        if(sw1 == 0)                    // If pressed
            return TRUE;                // Was pressed
    }//end if
    return FALSE;                       // Was not pressed
}//end Switch1IsPressed

BOOL Switch2IsPressed(void)
{
    if(sw2 != old_sw2)
    {
        old_sw2 = sw2;                  // Save new value
        if(sw2 == 0)                    // If pressed
            return TRUE;                // Was pressed
    }//end if
    return FALSE;                       // Was not pressed
}//end Switch2IsPressed

BOOL Switch3IsPressed(void)
{
    if(sw3 != old_sw3)
    {
        old_sw3 = sw3;                  // Save new value
        if(sw3 == 0)                    // If pressed
            return TRUE;                // Was pressed
    }//end if
    return FALSE;                       // Was not pressed
}//end Switch3IsPressed

BOOL Switch4IsPressed(void)
{
    if(sw4 != old_sw4)
    {
        old_sw4 = sw4;                  // Save new value
        if(sw4 == 0)                    // If pressed
            return TRUE;                // Was pressed
    }//end if
    return FALSE;                       // Was not pressed
}//end Switch4IsPressed



BOOL Switch5IsPressed(void)
{
    if(sw4 != old_sw5)
    {
        old_sw5 = sw5;                  // Save new value
        if(sw5 == 0)                    // If pressed
            return TRUE;                // Was pressed
    }//end if
    return FALSE;                       // Was not pressed
}//end Switch4IsPressed

/** EOF user_mouse.c *********************************************************/