kusano kiyoshige / Mbed 2 deprecated 17robo_tokyo_kaede

Dependencies:   QEI accelerator bit_test cyclic_io cyclic_var cylinder event_var limit mbed mecanum motor_drive pid pid_encoder rs422_put sbdbt servo

Fork of 17robo_fuzi by kusano kiyoshige

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers varEvent_.h Source File

varEvent_.h

00001 /******************************************************
00002 -Class [varEvent]
00003 
00004 The [varEvent] is used to trigger an event when input data state changes.
00005 
00006 目的:
00007     入力された状態の[立ち上がり],[立ち下がり]を検知する
00008     [Rise(0->1)],[Fall(1->0)]
00009     Sbdbt用として作成,流用可
00010     
00011 使い方:
00012 Public Member Functions:
00013 
00014     varEvent <useName>          //宣言
00015     .input((int)<inputData>)    //(void)検出したい変数(Data)を引数に代入
00016     .getRise()                  //(int)立ち上がり検知 検出時は(int)1,それ以外は(int)0を返す
00017     .getFall()                  //(int)立ち下がり検知 検出時は(int)1,それ以外は(int)0を返す
00018         
00019 ***************************************************************/
00020 
00021 class varEvent {
00022 public:
00023     void input(int inputState) {
00024         valState = ((valState<<1)|inputState)&3;
00025         if(valState == 1) {
00026             riseState = 1;
00027             fallState = 0;
00028         } else if(valState == 2){
00029             riseState = 0;
00030             fallState = 1;
00031         } else {
00032             riseState = 0;
00033             fallState = 0;
00034         }
00035     }
00036     
00037     int getRise(){
00038         return riseState;   
00039     }
00040     
00041     int getFall(){
00042         return fallState;   
00043     }
00044     
00045 private:
00046     int inputState, valState;
00047     int riseState, fallState;
00048 };