PSI3422_Aula3

Fork of NunchukLib by decarvalho adelino

Committer:
adelino
Date:
Tue Feb 25 10:50:05 2014 +0000
Revision:
2:0a8f43931041
Parent:
1:72d62147e2b8
start a new acquisition manually without internal Ticker

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adelino 0:37e9a0644485 1 #ifndef NUNCHUK_H
adelino 0:37e9a0644485 2 #define NUNCHUK_H
adelino 0:37e9a0644485 3
adelino 0:37e9a0644485 4 #include "mbed.h"
adelino 0:37e9a0644485 5
adelino 0:37e9a0644485 6 /** Class to interface with a Nintendo wii Nunchuk.
adelino 1:72d62147e2b8 7 Exemple
adelino 1:72d62147e2b8 8 @code
adelino 1:72d62147e2b8 9 #include "mbed.h"
adelino 1:72d62147e2b8 10 #include "Nunchuk.h"
adelino 1:72d62147e2b8 11
adelino 1:72d62147e2b8 12 Serial pc(USBTX,USBRX);
adelino 1:72d62147e2b8 13 Nunchuk device(p28,p27,0.05);
adelino 1:72d62147e2b8 14 int main()
adelino 1:72d62147e2b8 15 {
adelino 1:72d62147e2b8 16 while(1) {
adelino 1:72d62147e2b8 17
adelino 1:72d62147e2b8 18 pc.printf("> :%d : %d : %d: %d \r\n",device.getJoyX(),device.getJoyY(),device.getAccX(),device.getBtnZ());
adelino 1:72d62147e2b8 19
adelino 1:72d62147e2b8 20 wait(1);
adelino 1:72d62147e2b8 21 }
adelino 1:72d62147e2b8 22 }
adelino 1:72d62147e2b8 23 @endcode
adelino 0:37e9a0644485 24 */
adelino 0:37e9a0644485 25
adelino 0:37e9a0644485 26 class Nunchuk
adelino 0:37e9a0644485 27 {
adelino 0:37e9a0644485 28
adelino 0:37e9a0644485 29 public:
adelino 0:37e9a0644485 30 /** Construct a Nunchuk object.
adelino 0:37e9a0644485 31 *
adelino 0:37e9a0644485 32 * @param sda I2C channel to use.
adelino 0:37e9a0644485 33 * @param scl I2C channel
adelino 0:37e9a0644485 34 * @param mTe the sampling time for the internal Ticker
adelino 2:0a8f43931041 35 * if @param mTe=0 start a new acquisition manually without internal Ticker
adelino 0:37e9a0644485 36 */
adelino 2:0a8f43931041 37 Nunchuk(PinName sda,PinName scl,float mTe=0);
adelino 0:37e9a0644485 38
adelino 0:37e9a0644485 39 ~Nunchuk(void);
adelino 2:0a8f43931041 40
adelino 2:0a8f43931041 41 /// start a new acquisition manually without internal Ticker
adelino 2:0a8f43931041 42 void process(void);
adelino 0:37e9a0644485 43
adelino 1:72d62147e2b8 44 /// Get the joyStick position
adelino 1:72d62147e2b8 45 /// @returns -1: joyStick in left position
adelino 1:72d62147e2b8 46 /// @returns +1: joyStick in righ position
adelino 1:72d62147e2b8 47 /// @returns 0: center position
adelino 0:37e9a0644485 48
adelino 1:72d62147e2b8 49
adelino 0:37e9a0644485 50 signed char getJoyX(void);
adelino 0:37e9a0644485 51
adelino 1:72d62147e2b8 52 //! Get the joyStick position
adelino 1:72d62147e2b8 53 //! @returns -1: joyStick in left position
adelino 1:72d62147e2b8 54 //! @returns +1: joyStick in righ position
adelino 1:72d62147e2b8 55 //! @returns 0: center position
adelino 0:37e9a0644485 56
adelino 0:37e9a0644485 57 signed char getJoyY(void);
adelino 0:37e9a0644485 58
adelino 1:72d62147e2b8 59 /** @returns The acceleration in axis X (10 bits)
adelino 0:37e9a0644485 60 */
adelino 0:37e9a0644485 61 int getAccX(void);
adelino 0:37e9a0644485 62
adelino 1:72d62147e2b8 63 /** @returns The acceleration in axis Y (10 bits)
adelino 0:37e9a0644485 64 */
adelino 0:37e9a0644485 65 int getAccY(void);
adelino 0:37e9a0644485 66
adelino 1:72d62147e2b8 67 /** @returns The acceleration in axis Z (10 bits)
adelino 0:37e9a0644485 68 */
adelino 0:37e9a0644485 69 int getAccZ(void);
adelino 1:72d62147e2b8 70
adelino 1:72d62147e2b8 71
adelino 1:72d62147e2b8 72 //! @returns true if button C pressed
adelino 1:72d62147e2b8 73
adelino 0:37e9a0644485 74 bool getBtnC(void);
adelino 0:37e9a0644485 75
adelino 1:72d62147e2b8 76
adelino 1:72d62147e2b8 77 //! @returns true if button Z pressed
adelino 1:72d62147e2b8 78
adelino 0:37e9a0644485 79 bool getBtnZ(void);
adelino 0:37e9a0644485 80
adelino 1:72d62147e2b8 81 /** @returns The sampling period
adelino 0:37e9a0644485 82 */
adelino 0:37e9a0644485 83 float getPeriodeTe(void);
adelino 2:0a8f43931041 84
adelino 2:0a8f43931041 85
adelino 0:37e9a0644485 86
adelino 0:37e9a0644485 87 protected:
adelino 0:37e9a0644485 88 I2C myI2C;
adelino 0:37e9a0644485 89 //
adelino 0:37e9a0644485 90 Ticker myTicker;
adelino 0:37e9a0644485 91 //
adelino 0:37e9a0644485 92 bool setup(void);
adelino 0:37e9a0644485 93 //
adelino 0:37e9a0644485 94 bool request(void);
adelino 0:37e9a0644485 95 //
adelino 0:37e9a0644485 96 char decode(char data);
adelino 0:37e9a0644485 97 //
adelino 2:0a8f43931041 98
adelino 0:37e9a0644485 99
adelino 0:37e9a0644485 100
adelino 0:37e9a0644485 101 //datas
adelino 0:37e9a0644485 102 static const int ADRESSE=0xA4;
adelino 0:37e9a0644485 103 signed char joyX; //-1 0 +1
adelino 0:37e9a0644485 104 signed char joyY; //-1 0 +1
adelino 0:37e9a0644485 105
adelino 0:37e9a0644485 106 int accX;
adelino 0:37e9a0644485 107 int accY;
adelino 0:37e9a0644485 108 int accZ;
adelino 0:37e9a0644485 109
adelino 0:37e9a0644485 110 bool btnC;
adelino 0:37e9a0644485 111 bool btnZ;
adelino 0:37e9a0644485 112
adelino 0:37e9a0644485 113 float periodeTe;
adelino 0:37e9a0644485 114
adelino 0:37e9a0644485 115
adelino 0:37e9a0644485 116 };
adelino 0:37e9a0644485 117
adelino 0:37e9a0644485 118 #endif