Dependents:   XBEE_LPC1114

Committer:
inst
Date:
Thu Nov 12 08:05:36 2015 +0000
Revision:
1:a3a4ae2c5af2
Parent:
0:f55382f220f2

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:f55382f220f2 1 #ifndef INCLUDED_SERIAL_TO_I2C_H
inst 0:f55382f220f2 2 #define INCLUDED_SERIAL_TO_I2C_H
inst 0:f55382f220f2 3
inst 0:f55382f220f2 4 #include "mbed.h"
inst 0:f55382f220f2 5
inst 0:f55382f220f2 6 // Serial通信で得たデータをI2Cで渡す
inst 0:f55382f220f2 7 class SerialToI2C{
inst 0:f55382f220f2 8 public:
inst 0:f55382f220f2 9 enum ActionType{
inst 0:f55382f220f2 10 STOP = 0x00, // 0000 0000(2)
inst 0:f55382f220f2 11 MOVE = 0x08, // 0000 1000(2)
inst 0:f55382f220f2 12 ROLL = 0x10, // 0001 0000(2)
inst 0:f55382f220f2 13 SHOOT = 0x18 // 0001 1000(2)
inst 0:f55382f220f2 14 };
inst 0:f55382f220f2 15
inst 0:f55382f220f2 16 enum AimState{
inst 0:f55382f220f2 17 OWN_POLE = 0x00,
inst 0:f55382f220f2 18 CENTER_MIDDLE_POLE = 0x40,
inst 0:f55382f220f2 19 CENTER_SIDE_POLE = 0x80,
inst 0:f55382f220f2 20 ENEMYS_POLE = 0xC0
inst 0:f55382f220f2 21 };
inst 0:f55382f220f2 22
inst 0:f55382f220f2 23 enum StopDetailType{
inst 0:f55382f220f2 24 NO_OPERATION,
inst 0:f55382f220f2 25 INCREMENT,
inst 0:f55382f220f2 26 DECREMENT,
inst 0:f55382f220f2 27 LOW_SPEED,
inst 0:f55382f220f2 28 HIGH_SPEED
inst 0:f55382f220f2 29 };
inst 0:f55382f220f2 30
inst 0:f55382f220f2 31 static void create( PinName sda, PinName scl, PinName tx, PinName rx ){
inst 0:f55382f220f2 32 if ( mInstance == NULL ){
inst 0:f55382f220f2 33 mInstance = new SerialToI2C( sda, scl, tx, rx );
inst 0:f55382f220f2 34 }
inst 0:f55382f220f2 35 }
inst 0:f55382f220f2 36 static SerialToI2C* getInstance(){
inst 0:f55382f220f2 37 return mInstance;
inst 0:f55382f220f2 38 }
inst 0:f55382f220f2 39
inst 0:f55382f220f2 40 void update();
inst 0:f55382f220f2 41
inst 0:f55382f220f2 42 private:
inst 0:f55382f220f2 43 static SerialToI2C* mInstance;
inst 0:f55382f220f2 44 // 実体なし
inst 0:f55382f220f2 45 SerialToI2C( SerialToI2C& a );
inst 0:f55382f220f2 46 void operator = ( SerialToI2C& a );
inst 0:f55382f220f2 47
inst 0:f55382f220f2 48 SerialToI2C( PinName sda, PinName scl, PinName tx, PinName rx );
inst 0:f55382f220f2 49 ~SerialToI2C(){
inst 0:f55382f220f2 50 delete mXBee;
inst 0:f55382f220f2 51 delete mI2C;
inst 0:f55382f220f2 52 }
inst 0:f55382f220f2 53
inst 0:f55382f220f2 54 void recvSerial();
inst 0:f55382f220f2 55 void stringToI2CData();
inst 0:f55382f220f2 56 void updateI2CSlave();
inst 0:f55382f220f2 57
inst 0:f55382f220f2 58 static const PinName mAddressDeciderPinName[ 4 ];
inst 0:f55382f220f2 59 static const char mControlMask;
inst 0:f55382f220f2 60 static const char mDetailMask;
inst 0:f55382f220f2 61 static const char mDutyMask;
inst 0:f55382f220f2 62
inst 0:f55382f220f2 63 char mAddress;
inst 0:f55382f220f2 64
inst 0:f55382f220f2 65 RawSerial* mXBee;
inst 0:f55382f220f2 66 I2CSlave* mI2C;
inst 0:f55382f220f2 67
inst 0:f55382f220f2 68 char mRecv;
inst 0:f55382f220f2 69 char mI2CSentData;
inst 0:f55382f220f2 70 bool mIsI2CSentDataChangeable;
inst 0:f55382f220f2 71
inst 0:f55382f220f2 72 char mMoveDirection;
inst 0:f55382f220f2 73 float mMoveCoeff;
inst 0:f55382f220f2 74 float mRoll;
inst 0:f55382f220f2 75 ActionType mActionType;
inst 0:f55382f220f2 76 AimState mAimState;
inst 0:f55382f220f2 77 StopDetailType mStopDetailType;
inst 0:f55382f220f2 78 bool mIsSupplying;
inst 0:f55382f220f2 79
inst 0:f55382f220f2 80 DigitalOut* mLED;
inst 0:f55382f220f2 81 };
inst 0:f55382f220f2 82
inst 0:f55382f220f2 83 #endif