/*
 *  Copyright (C) 2013-2014 by Embedded and Real-Time Systems Laboratory
 *              Graduate School of Information Science, Nagoya Univ., JAPAN
 * 
 *  $Id: rcb3.h 213 2014-09-02 11:48:58Z honda $
 */

#ifndef _RCB3_H_
#define _RCB3_H_

/*
 *  RCB3電文解析処理
 */
/*
 *  RCB3 Message format
 */
#define RCB3_MSG_LEN 8
#define RCB3_MSG_HEADER_1 0x80

#define RCB3_MSG_OFFSET_BUTTON_H 1
#define RCB3_MSG_OFFSET_BUTTON_L 2
#define RCB3_MSG_OFFSET_L_ANALOG_LR  3
#define RCB3_MSG_OFFSET_L_ANALOG_UD  4
#define RCB3_MSG_OFFSET_R_ANALOG_LR  5
#define RCB3_MSG_OFFSET_R_ANALOG_UD  6

#define RCB3_MSG_BUTTON_UP        0x0001
#define RCB3_MSG_BUTTON_DOWN      0x0002
#define RCB3_MSG_BUTTON_LEFT      0x0004
#define RCB3_MSG_BUTTON_RIGHT     0x0008
#define RCB3_MSG_BUTTON_TRIANGLE  0x0010
#define RCB3_MSG_BUTTON_CROSS     0x0020
#define RCB3_MSG_BUTTON_NOUGHT    0x0040
#define RCB3_MSG_BUTTON_SQUARE    0x0100
#define RCB3_MSG_BUTTON_L1        0x0200
#define RCB3_MSG_BUTTON_L2        0x0400
#define RCB3_MSG_BUTTON_R1        0x0800
#define RCB3_MSG_BUTTON_R2        0x1000
#define RCB3_MSG_BUTTON_START     0x0003
#define RCB3_MSG_BUTTON_SELECT    0x000C

#define RCB3_MSG_ANALOG_MAX      127
#define RCB3_MSG_ANALOG_MIN        1
#define RCB3_MSG_ANALOG_NEUTRAL   64


/*
 * 前状態と現在状態を示すポインタ
 */
extern boolean  *p_g_pre_ps3button;
extern boolean  *p_g_cur_ps3button;
extern sint8    *p_g_pre_ps3analog;
extern sint8    *p_g_cur_ps3analog;
extern uint8     g_rcb3_rmsg[RCB3_MSG_LEN];

/*
 *  各ボタン状態の番号
 */
#define NO_PS3BUTTON_UP        0
#define NO_PS3BUTTON_DOWN      1
#define NO_PS3BUTTON_LEFT      3
#define NO_PS3BUTTON_RIGHT     2
#define NO_PS3BUTTON_TRIANGLE  4
#define NO_PS3BUTTON_CROSS     5
#define NO_PS3BUTTON_NOUGHT    6
#define NO_PS3BUTTON_SQUARE    7
#define NO_PS3BUTTON_L1        8
#define NO_PS3BUTTON_L2        9
#define NO_PS3BUTTON_R1        10
#define NO_PS3BUTTON_R2        11
#define NO_PS3BUTTON_START     12
#define NO_PS3BUTTON_SELECT    13

#define NO_PS3ANALOG_L_LR  0
#define NO_PS3ANALOG_L_UD  1
#define NO_PS3ANALOG_R_LR  2
#define NO_PS3ANALOG_R_UD  3

/*
 *  初期化処理 
 */
void rcb3_Init(void);


/*
 *  RCB3コマンドの解析
 * 
 *  受信した1バイト毎に引数に指定して呼び出す．
 *  電文の最後でTRUEを返す．
 */
extern boolean rcb3_AddReceivedByte(uint8 c);

#endif /* _RCB3_H_ */
