Trackball based on the NXP LPC11U24 and the ADNS-9500

Dependencies:   ADNS9500 USBDevice mbed 25LCxxx_SPI

main.h

Committer:
xxann5
Date:
2013-01-06
Revision:
6:4cb2c9a3abcd
Parent:
5:c7056267daa7
Child:
7:d6ee49a89009

File content as of revision 6:4cb2c9a3abcd:

/* Copyright (c) 2012-2013 Chris Majoros(chris@majoros.us), MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "mbed.h"
#include "USBHID.h"
#include "USBMouse.h"

#include <math.h>
#include <stdint.h>


#define PINDETECT_PIN_ASSTERED  0    //setAssertValue
#define PINDETECT_SAMPLE_PERIOD 100 //setSampleFrequency
#define PINDETECT_ASSERT_COUNT  10    //setSamplesTillAssert
#define PINDETECT_HOLD_COUNT    500

#include "PinDetect.h"

#define ADNS9500_SROM_91

#define DEBUG

#include "adns9500.hpp"
#include "Ser25lcxxx.h"

#define CHAT_SET 0x01
#define CHAT_GET 0x02
    
#define CHAT_MOTION_DEFAULT_CPI 0x01
#define CHAT_MOTION_MAX_CPI     0x02
#define CHAT_MOTION_MIN_CPI     0x03
#define CHAT_MOTION_STEP_CPI    0x04
#define CHAT_Z_DEFAULT_CPI      0x05
#define CHAT_HR_DEFAULT_CPI     0x06
    
#define CHAT_VID                0x07
#define CHAT_PID                0x08
    
#define CHAT_ADNS_SROM          0x09

#define CHAT_LED_BEHAVIOR       0x0a

#define CHAT_BTN_TICKER_FREQ    0x0b
#define CHAT_BTN_ASSERT_COUNT   0x0c


  
//This report will contain data to be sent
HID_REPORT send_rep;
HID_REPORT recv_rep;

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

PinDetect btn_hr(p16);
PinDetect btn_z(p17);
DigitalIn btn_l(p18);
PinDetect btn_m(p19);
PinDetect btn_r(p20);


DigitalIn btn_program(p22);

adns9500::ADNS9500 *sensor;
USBMouse *mouse;

bool motion_triggered = false;
bool z_axis_active    = false;
bool high_rez_active  = false;

int default_motion_cpi = 1080;
int default_z_cpi      = 90;
int default_hirez_cpi  = 180;

void track();
void program();

void motionCallback( void );

void btn_hr_press( void );
void btn_hr_release( void );

void btn_z_press( void );
void btn_z_release( void );

void btn_l_press(void);
void btn_l_release( void );

void btn_m_press( void );
void btn_m_release( void );

void btn_r_press( void );
void btn_r_release( void );

void set( uint8_t attrib, uint8_t *val );
void get( uint8_t attrib);