First Release

Dependencies:   USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers In_CyberStick.h Source File

In_CyberStick.h

00001 #pragma once
00002 
00003 /** Class: In_CyberStick
00004  *
00005  * Used for reading from CyberStick(CZ-8NJ2)
00006  *
00007  * Example:
00008  *
00009  * > #include "mbed.h"
00010  *
00011  * > In_CyberStick myCS(p20, p19,... inputStates);
00012  */
00013 
00014 #include "mbed.h"
00015 #include "InputStatus.h"
00016 
00017 class In_CyberStick
00018 {
00019 public:
00020     /** Constructor: In_CyberStick
00021      *
00022      * Parameters:
00023      * pn_D0  - DigitalIn for CyberStick's D0 (D-Sub 9pin connector's pin1)
00024      * pn_D1  - DigitalIn for D1 (D-Sub9 pin2)
00025      * pn_D2  - DigitalIn for D2 (D-Sub9 pin3)
00026      * pn_D3  - DigitalIn for D3 (D-Sub9 pin4)
00027      * pn_LH  - DigitalIn for L/H (D-Sub9 pin6)
00028      * pn_ACK - DigitalIn for Ack (D-Sub9 pin7)
00029      * pn_REQ - DigitalOut for Req (D-Sub9 pin8)
00030      * inputStatus - The variable to store input status
00031      */
00032     In_CyberStick(
00033         PinName pn_D0, PinName pn_D1, PinName pn_D2, PinName pn_D3, 
00034         PinName pn_LH, PinName pn_ACK, PinName pn_REQ,
00035         InputStatus *inputStatus
00036     );
00037 
00038     void TestShow(void);
00039     
00040     void StartReading(void);
00041     void StopReading(void);
00042         
00043 private:
00044     // Private constants
00045     static const int REQUESTINTERVAL__MICROSEC      = 2500; // reading period microsec
00046     static const int TRANSFERSPEED_MAX__MICROSEC    = 50;    // from AJOY_SUB.DOC
00047     static const int TRANSFERSPEED_1_2__MICROSEC    = 96;
00048     static const int TRANSFERSPEED_1_3__MICROSEC    = 144;
00049     static const int TRANSFERSPEED_1_4__MICROSEC    = 192;
00050 
00051     // mbed pins
00052     DigitalIn   _IN_D0;
00053     DigitalIn   _IN_D1;
00054     DigitalIn   _IN_D2;
00055     DigitalIn   _IN_D3;
00056     DigitalIn   _IN_LH;
00057     DigitalIn   _IN_ACK;
00058     DigitalOut  _OUT_REQ;
00059 
00060     // Variables
00061     InputStatus     *_InputStatus;
00062     volatile char   _ReadEnable;
00063     Ticker          _PollingTicker;
00064     Timer           _AckTimer;
00065     volatile int    _Buttons;
00066     volatile char   _Ch0;
00067     volatile char   _Ch1;
00068     volatile char   _Ch2;
00069     volatile char   _Ch3;
00070     volatile int    _AnalogReadFailCounter;
00071 
00072     // Private Method
00073     void Initialize(void);
00074     void EnablePolling(void);
00075     void DisablePolling(void);
00076     void PollingMethod(void);
00077     void ReadPhase(char phase);
00078 
00079     void DigitalModeReader(void);
00080 
00081     int  ReadPinValue(void);
00082     void CommitAnalogData(void);
00083 
00084 };