Here is the new ADNS2051.cpp
Code:
/*
ADNS2051.cpp - Part of optical mouse sensor library for Arduino
Copyright (c) 2008 Martijn The. All right reserved.
http://www.martijnthe.nl/
Conversion to Arduino 1.x by zapmaker (zapmaker.org)
Configuration command added by Jeff Pearson
Based on sketches by Benoît Rousseau.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/******************************************************************************
* Includes
******************************************************************************/
#include "Arduino.h"
#include "OptiMouse.h"
#include "ADNS2051.h"
/******************************************************************************
* Definitions
******************************************************************************/
#define Config 0x0a // added
#define Delta_Y 0x04
#define Delta_X 0x03
#define Motion_Status 0x02
#define Mask_Motion 0x80
#define Mask_DYOVF 0x10
#define Mask_DXOVF 0x08
/******************************************************************************
* Constructors
******************************************************************************/
ADNS2051::ADNS2051(uint8_t sclkPin, uint8_t sdioPin) : OptiMouse::OptiMouse(sclkPin, sdioPin)
{
}
/******************************************************************************
* User API
******************************************************************************/
signed char ADNS2051::config(void) // added
{ //
return (signed char) readRegister(Config); // for
} //
// configuration
void ADNS2051::writeConfig(signed char c) //
// command
writeRegister(Config, c); //
} // added
void ADNS2051::updateStatus(void)
{
_status = readRegister(Motion_Status);
}
signed char ADNS2051::dx(void)
{
return (signed char) readRegister(Delta_X);
}
signed char ADNS2051::dy(void)
{
return (signed char) readRegister(Delta_Y);
}
uint8_t ADNS2051::motion() const
{
return (uint8_t) (_status & Mask_Motion) == Mask_Motion;
}
uint8_t ADNS2051::dxOverflow() const
{
return (uint8_t) (_status & Mask_DXOVF) == Mask_DXOVF;
}
uint8_t ADNS2051::dyOverflow() const
{
return (uint8_t) (_status & Mask_DYOVF) == Mask_DYOVF;
}
// Private Methods /////////////////////////////////////////////////////////////
The new ADNS2051.h
Code:
/*
ADNS2051.h - Part of optical mouse sensor library for Arduino
Copyright (c) 2008 Martijn The. All right reserved.
http://www.martijnthe.nl/
Conversion to Arduino 1.x by zapmaker (zapmaker.org)
Configure command added by Jeff Pearson
Based on sketches by Benoît Rousseau.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ADNS2051_h
#define ADNS2051_h
#include <inttypes.h>
#include "OptiMouse.h"
class ADNS2051 : public OptiMouse
{
private:
uint8_t _status;
public:
ADNS2051(uint8_t, uint8_t);
signed char config(void); // added
void writeConfig(signed char c); // added
void updateStatus(void);
signed char dx(void);
signed char dy(void);
uint8_t motion() const;
uint8_t dxOverflow() const;
uint8_t dyOverflow() const;
};
#endif
And my Trackball sketch with Config command
Code:
// ADNS2051.h reads out ADNS-2051 the Optical Navigation Sensor
// It's used in many cheap optical mice
//
// Written by Martijn The -> post [at] martijnthe.nl
// Tutorial: http://www.martijnthe.nl/optimouse/
// Based on the sketches by Beno”t Rousseau
// Trackball part of Panther XL clone
#include "ADNS2051.h"
#include <Bounce.h> // Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
#define SCLK 0 // Serial clock pin on the Arduino
#define SDIO 1 // Serial data (I/O) pin on the Arduino
ADNS2051 Optical1 = ADNS2051(SCLK, SDIO); // Create an instance of the ADNS2051 object
Bounce button2 = Bounce(2, 10); // if a button is too "sensitive"
Bounce button3 = Bounce(3, 10); // to rapid touch, you can
Bounce button4 = Bounce(4, 10); // increase this time.
void setup()
{
Serial.begin(38400);
Optical1.begin(); // Resync (not really necessary?)
Optical1.writeConfig(B000101); // added command. set 800 CPI and always awake
// (B000100), set 800 CPI and auto sleep
// Default is 400 CPI and auto sleep
pinMode(2, INPUT_PULLUP); // Left Mouse Click
pinMode(3, INPUT_PULLUP); // Middle Mouse Click
pinMode(4, INPUT_PULLUP); // Right Mouse Click
}
void loop()
{
button2.update();
button3.update();
button4.update();
if (button2.fallingEdge()) {
Mouse.press(MOUSE_LEFT);
}
if (button2.risingEdge()) {
Mouse.release(MOUSE_LEFT);
}
if (button3.fallingEdge()) {
Mouse.press(MOUSE_MIDDLE);
}
if (button3.risingEdge()) {
Mouse.release(MOUSE_MIDDLE);
}
if (button4.fallingEdge()) {
Mouse.press(MOUSE_RIGHT);
}
if (button4.risingEdge()) {
Mouse.release(MOUSE_RIGHT);
}
// The status commands are available only for the PAN3101 and the ADNS2051:
Optical1.updateStatus(); // Get the latest motion status
if (Optical1.motion()) // If the 'Motion' status bit is set,
{
Mouse.move(-1*Optical1.dx(), -1*Optical1.dy());
}
}
Am I supposed to send this upstream to Github????