Version 1.0 - Library for Parallax OFN module 27903

Fork of OFN by Neha Kadam

Import library

Public Member Functions

OFN (PinName sda, PinName scl)
Constructor.
bool checkMotion ()
Function to check if motion has been detected Checks the 7th bit of MOTION register and Returns true if motion detected else returns false.
int readX ()
Function to get displacement in the X direction Returns an integer value.
int readY ()
Function to get displacement in the X direction Returns an integer value.
int readOrientation ()
Function to read the Orientation register Returns an integer value 1 - default orientation 0 - rotated by 90 degrees.
Committer:
nkadam
Date:
Mon Mar 09 03:18:22 2015 +0000
Revision:
0:c559e09a7b5d
Child:
1:ba28114bd6bb
Version 1.0 of Library for Parallax OFN module 27903

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nkadam 0:c559e09a7b5d 1
nkadam 0:c559e09a7b5d 2 //@Authors: Guru Das Srinagesh, Neha Kadam
nkadam 0:c559e09a7b5d 3 /* Copyright (c) March, 2015 MIT License
nkadam 0:c559e09a7b5d 4 *
nkadam 0:c559e09a7b5d 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
nkadam 0:c559e09a7b5d 6 * and associated documentation files (the "Software"), to deal in the Software without restriction,
nkadam 0:c559e09a7b5d 7 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
nkadam 0:c559e09a7b5d 8 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
nkadam 0:c559e09a7b5d 9 * furnished to do so, subject to the following conditions:
nkadam 0:c559e09a7b5d 10 *
nkadam 0:c559e09a7b5d 11 * The above copyright notice and this permission notice shall be included in all copies or
nkadam 0:c559e09a7b5d 12 * substantial portions of the Software.
nkadam 0:c559e09a7b5d 13 *
nkadam 0:c559e09a7b5d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
nkadam 0:c559e09a7b5d 15 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
nkadam 0:c559e09a7b5d 16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
nkadam 0:c559e09a7b5d 17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nkadam 0:c559e09a7b5d 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
nkadam 0:c559e09a7b5d 19 */
nkadam 0:c559e09a7b5d 20
nkadam 0:c559e09a7b5d 21
nkadam 0:c559e09a7b5d 22 /*
nkadam 0:c559e09a7b5d 23 * Library for Parallax Optical Finger Navigation Module 27903
nkadam 0:c559e09a7b5d 24 * Link to datasheet: http://www.parallax.com/sites/default/files/downloads/27903-OFN-Module-Documentation-v1.1.pdf
nkadam 0:c559e09a7b5d 25 *
nkadam 0:c559e09a7b5d 26 */
nkadam 0:c559e09a7b5d 27 #ifndef OFN_H
nkadam 0:c559e09a7b5d 28 #define OFN_H
nkadam 0:c559e09a7b5d 29
nkadam 0:c559e09a7b5d 30 #include "mbed.h"
nkadam 0:c559e09a7b5d 31
nkadam 0:c559e09a7b5d 32 #define DEVICE_ADDR 0x33
nkadam 0:c559e09a7b5d 33 #define PRODUCT_ID_ADDR 0x00
nkadam 0:c559e09a7b5d 34 #define REVISION_ID_ADDR 0x01
nkadam 0:c559e09a7b5d 35
nkadam 0:c559e09a7b5d 36 #define SOFT_RESET 0x3A
nkadam 0:c559e09a7b5d 37 #define OFN_ORIENTATION_CTRL 0x77
nkadam 0:c559e09a7b5d 38
nkadam 0:c559e09a7b5d 39 #define ORIENT_DEFAULT 1
nkadam 0:c559e09a7b5d 40 #define ORIENT_ROTATED_CLKWISE 0
nkadam 0:c559e09a7b5d 41
nkadam 0:c559e09a7b5d 42 class OFN {
nkadam 0:c559e09a7b5d 43
nkadam 0:c559e09a7b5d 44 public:
nkadam 0:c559e09a7b5d 45
nkadam 0:c559e09a7b5d 46 /**
nkadam 0:c559e09a7b5d 47 * Constructor.
nkadam 0:c559e09a7b5d 48 *
nkadam 0:c559e09a7b5d 49 * @param sda mbed pin to use for SDA line of I2C interface.
nkadam 0:c559e09a7b5d 50 * @param scl mbed pin to use for SCL line of I2C interface.
nkadam 0:c559e09a7b5d 51 */
nkadam 0:c559e09a7b5d 52 OFN(PinName sda, PinName scl);
nkadam 0:c559e09a7b5d 53
nkadam 0:c559e09a7b5d 54 /**
nkadam 0:c559e09a7b5d 55 *
nkadam 0:c559e09a7b5d 56 * Function to check if motion has been detected
nkadam 0:c559e09a7b5d 57 * Checks the 7th bit of MOTION register and
nkadam 0:c559e09a7b5d 58 * Returns true if motion detected else returns false
nkadam 0:c559e09a7b5d 59 */
nkadam 0:c559e09a7b5d 60 bool checkMotion();
nkadam 0:c559e09a7b5d 61
nkadam 0:c559e09a7b5d 62 /**
nkadam 0:c559e09a7b5d 63 *
nkadam 0:c559e09a7b5d 64 * Function to get displacement in the X direction
nkadam 0:c559e09a7b5d 65 * Returns an integer value
nkadam 0:c559e09a7b5d 66 */
nkadam 0:c559e09a7b5d 67 int readX();
nkadam 0:c559e09a7b5d 68
nkadam 0:c559e09a7b5d 69 /**
nkadam 0:c559e09a7b5d 70 *
nkadam 0:c559e09a7b5d 71 * Function to get displacement in the X direction
nkadam 0:c559e09a7b5d 72 * Returns an integer value
nkadam 0:c559e09a7b5d 73 */
nkadam 0:c559e09a7b5d 74 int readY();
nkadam 0:c559e09a7b5d 75
nkadam 0:c559e09a7b5d 76 /**
nkadam 0:c559e09a7b5d 77 *
nkadam 0:c559e09a7b5d 78 * Function to read the Orientation register
nkadam 0:c559e09a7b5d 79 * Returns an integer value
nkadam 0:c559e09a7b5d 80 * 1 - default orientation
nkadam 0:c559e09a7b5d 81 * 0 - rotated by 90 degrees
nkadam 0:c559e09a7b5d 82 */
nkadam 0:c559e09a7b5d 83 int readOrientation();
nkadam 0:c559e09a7b5d 84
nkadam 0:c559e09a7b5d 85 private:
nkadam 0:c559e09a7b5d 86
nkadam 0:c559e09a7b5d 87 I2C i2c;
nkadam 0:c559e09a7b5d 88
nkadam 0:c559e09a7b5d 89 char MOTREG_ADDR; // To contain address of Motion Register
nkadam 0:c559e09a7b5d 90 char DELTA_X_ADDR; // To contain address of Delta_X Register
nkadam 0:c559e09a7b5d 91 char DELTA_Y_ADDR; // To contain address of Delta_Y Register
nkadam 0:c559e09a7b5d 92 int MotReg; // To contain value of Motion Register
nkadam 0:c559e09a7b5d 93 bool moved; // To contain value of state of Motion
nkadam 0:c559e09a7b5d 94
nkadam 0:c559e09a7b5d 95 char raw_delta_X[1]; // To contain raw sensor reading of Delta_X
nkadam 0:c559e09a7b5d 96 int delta_X; // To contain correct reading of Delta_X
nkadam 0:c559e09a7b5d 97
nkadam 0:c559e09a7b5d 98 char raw_delta_Y[1]; // To contain raw sensor reading of Delta_Y
nkadam 0:c559e09a7b5d 99 int delta_Y; // To contain correct reading of Delta_Y
nkadam 0:c559e09a7b5d 100 };
nkadam 0:c559e09a7b5d 101
nkadam 0:c559e09a7b5d 102 #endif /* OFN_H */