このライブラリはSW認識を行います。 SWは1個から20個まで認識できます。 SWの認識周期は10msです。 SWはmbedの端子とGNDの間に接続します。 This library does the recognition SW. SW, one can recognize up to 20. Recognition of the SW period is 10ms. SW is connected to GND terminal of mbed. ON the SW, OFF (level) data output. Output data from OFF to ON edge of the SW. Output data from ON to OFF edge of the SW. SWのON,OFF(レベル)データを出力します。 SWのOFFからONのエッジデータを出力します。 SWのONからOFFのエッジデータを出力します。

Dependents:   kitchenTimer_Clock SwDigitalLibraryExampleProgram

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SwDigital.cpp Source File

SwDigital.cpp

00001 //======================================================================
00002 //    SwDigital.cpp
00003 //
00004 // pwmOutput - digtalOutput de sound syuturyoku suru library
00005 //======================================================================
00006 #define _SWDIGITAL_C
00007 
00008 #include "mbed.h"
00009 #include "SwDigital.h"
00010 
00011 //======================================================================
00012 // syokika
00013 //======================================================================
00014 
00015     SwDigital::SwDigital(PinName sw0, PinName sw1, PinName sw2, PinName sw3, PinName sw4,
00016                          PinName sw5, PinName sw6, PinName sw7, PinName sw8, PinName sw9,
00017                          PinName sw10, PinName sw11, PinName sw12, PinName sw13, PinName sw14,
00018                          PinName sw15, PinName sw16, PinName sw17, PinName sw18, PinName sw19
00019                          ):
00020                          _sw0(sw0),   _sw1(sw1),   _sw2(sw2),   _sw3(sw3),   _sw4(sw4),
00021                          _sw5(sw5),   _sw6(sw6),   _sw7(sw7),   _sw8(sw8),   _sw9(sw9),
00022                          _sw10(sw10), _sw11(sw11), _sw12(sw12), _sw13(sw13), _sw14(sw14),
00023                          _sw15(sw15), _sw16(sw16), _sw17(sw17), _sw18(sw18), _sw19(sw19)
00024                          {
00025        
00026     //---------------------------------
00027     // touroku sareta Sw Suu wo kakunin
00028     //---------------------------------
00029     if(sw0 != NC){D_swSuu = 1; _sw0.mode(PullUp);}
00030     if(sw1 != NC){D_swSuu = 2; _sw1.mode(PullUp);}
00031     if(sw2 != NC){D_swSuu = 3; _sw2.mode(PullUp);}
00032     if(sw3 != NC){D_swSuu = 4; _sw3.mode(PullUp);}
00033     if(sw4 != NC){D_swSuu = 5; _sw4.mode(PullUp);}
00034     
00035     if(sw5 != NC){D_swSuu = 6; _sw5.mode(PullUp);}
00036     if(sw6 != NC){D_swSuu = 7; _sw6.mode(PullUp);}
00037     if(sw7 != NC){D_swSuu = 8; _sw7.mode(PullUp);}
00038     if(sw8 != NC){D_swSuu = 9; _sw8.mode(PullUp);}
00039     if(sw9 != NC){D_swSuu = 10; _sw9.mode(PullUp);}    
00040     
00041     if(sw10 != NC){D_swSuu = 11; _sw10.mode(PullUp);}
00042     if(sw11 != NC){D_swSuu = 12; _sw11.mode(PullUp);}
00043     if(sw12 != NC){D_swSuu = 13; _sw12.mode(PullUp);}
00044     if(sw13 != NC){D_swSuu = 14; _sw13.mode(PullUp);}
00045     if(sw14 != NC){D_swSuu = 15; _sw14.mode(PullUp);}
00046     
00047     if(sw15 != NC){D_swSuu = 16; _sw15.mode(PullUp);}
00048     if(sw16 != NC){D_swSuu = 17; _sw16.mode(PullUp);}
00049     if(sw17 != NC){D_swSuu = 18; _sw17.mode(PullUp);}
00050     if(sw18 != NC){D_swSuu = 19; _sw18.mode(PullUp);}
00051     if(sw19 != NC){D_swSuu = 20; _sw19.mode(PullUp);}    
00052     
00053     // sw ninsiki syuki 10[ms]
00054     swCheckTimer.attach_us(this, &SwDigital::input, Z_matchcycle); 
00055         
00056 }
00057 
00058 void SwDigital::input(void){
00059     // genzai level input
00060     switch(D_swSuu){
00061     case 20:
00062         B_kariLevel[19] = ((B_kariLevel[19] << 1) | (((uint8_t)~_sw19) & 0x01));
00063         //break;
00064     case 19:
00065         B_kariLevel[18] = ((B_kariLevel[18] << 1) | (((uint8_t)~_sw18) & 0x01));
00066         //break;
00067     case 18:
00068         B_kariLevel[17] = ((B_kariLevel[17] << 1) | (((uint8_t)~_sw17) & 0x01));
00069         //break;        
00070     case 17:
00071         B_kariLevel[16] = ((B_kariLevel[16] << 1) | (((uint8_t)~_sw16) & 0x01));
00072         //break;        
00073     case 16:
00074         B_kariLevel[15] = ((B_kariLevel[15] << 1) | (((uint8_t)~_sw15) & 0x01));
00075         //break;       
00076     case 15:
00077         B_kariLevel[14] = ((B_kariLevel[14] << 1) | (((uint8_t)~_sw14) & 0x01));
00078         //break;
00079     case 14:
00080         B_kariLevel[13] = ((B_kariLevel[13] << 1) | (((uint8_t)~_sw13) & 0x01));
00081         //break;
00082     case 13:
00083         B_kariLevel[12] = ((B_kariLevel[12] << 1) | (((uint8_t)~_sw12) & 0x01));
00084         //break;        
00085     case 12:
00086         B_kariLevel[11] = ((B_kariLevel[11] << 1) | (((uint8_t)~_sw11) & 0x01));
00087         //break;        
00088      case 11:
00089         B_kariLevel[10] = ((B_kariLevel[10] << 1) | (((uint8_t)~_sw10) & 0x01));
00090         //break;               
00091         
00092     case 10:
00093         B_kariLevel[9] = ((B_kariLevel[9] << 1) | (((uint8_t)~_sw9) & 0x01));
00094         //break;
00095     case 9:
00096         B_kariLevel[8] = ((B_kariLevel[8] << 1) | (((uint8_t)~_sw8) & 0x01));
00097         //break;
00098     case 8:
00099         B_kariLevel[7] = ((B_kariLevel[7] << 1) | (((uint8_t)~_sw7) & 0x01));
00100         //break;        
00101     case 7:
00102         B_kariLevel[6] = ((B_kariLevel[6] << 1) | (((uint8_t)~_sw6) & 0x01));
00103         //break;        
00104     case 6:
00105         B_kariLevel[5] = ((B_kariLevel[5] << 1) | (((uint8_t)~_sw5) & 0x01));
00106         //break;       
00107     case 5:
00108         B_kariLevel[4] = ((B_kariLevel[4] << 1) | (((uint8_t)~_sw4) & 0x01));
00109         //break;
00110     case 4:
00111         B_kariLevel[3] = ((B_kariLevel[3] << 1) | (((uint8_t)~_sw3) & 0x01));
00112         //break;
00113     case 3:
00114         B_kariLevel[2] = ((B_kariLevel[2] << 1) | (((uint8_t)~_sw2) & 0x01));
00115         //break;        
00116     case 2:
00117         B_kariLevel[1] = ((B_kariLevel[1] << 1) | (((uint8_t)~_sw1) & 0x01));
00118         //break;        
00119     case 1:
00120         B_kariLevel[0] = ((B_kariLevel[0] << 1) | (((uint8_t)~_sw0) & 0x01));
00121         //break;                       
00122     default:
00123         // nothing
00124         break;
00125     }
00126     
00127     // kakutei Level kosin
00128     uint8_t kakutei = 0;
00129     for(uint8_t i = 0; i < D_swSuu; i++){
00130         uint8_t work = B_kariLevel[i] & Z_itchiPattern;
00131         if(work == 0x00){
00132             // off kakutei
00133             D_oldLevel[i] = D_nowLevel[i];
00134             D_nowLevel[i] = Z_levelOff;
00135             kakutei = 1;
00136         }
00137         else if(work == Z_itchiPattern){
00138             // on kakutei
00139             D_oldLevel[i] = D_nowLevel[i];
00140             D_nowLevel[i] = Z_levelOn;
00141             kakutei = 1;
00142         }
00143         else{
00144             // nothing
00145         }
00146         
00147         if(kakutei == 1){
00148             // edge kosin
00149             if((D_oldLevel[i] == Z_levelOff) && (D_nowLevel[i] == Z_levelOn)){
00150                 B_edgeOn[i] = Z_edgeAri;
00151             }
00152             if((D_oldLevel[i] == Z_levelOn) && (D_nowLevel[i] == Z_levelOff)){
00153                 B_edgeOff[i] = Z_edgeAri;
00154             }
00155         }
00156 
00157     }              
00158 }
00159 
00160 void SwDigital::refreshEdgeData(void){
00161     for(uint8_t i = 0; i < D_swSuu; i++){
00162         __disable_irq();    // Disable Interrupts
00163         D_edgeOn[i]  = B_edgeOn[i];
00164         D_edgeOff[i] = B_edgeOff[i];
00165         
00166         B_edgeOn[i]  = Z_edgeNasi;
00167         B_edgeOff[i] = Z_edgeNasi;
00168         __enable_irq();     // Enable Interrupts
00169     }
00170 }
00171 
00172 uint8_t SwDigital::checkEdgeOn(uint8_t swNo){
00173     uint8_t ans = 0;
00174     
00175     if(D_edgeOn[swNo] == Z_edgeAri){
00176         ans = 1;
00177     } 
00178 
00179     return (ans);
00180 }
00181 
00182 uint8_t SwDigital::checkEdgeOff(uint8_t swNo){
00183     uint8_t ans = 0;
00184     
00185     if(D_edgeOff[swNo] == Z_edgeAri){
00186         ans = 1;
00187     } 
00188 
00189     return (ans);
00190 }
00191 
00192 uint8_t SwDigital::checkLevel(uint8_t swNo){
00193     uint8_t ans = 0;
00194     
00195     if(D_nowLevel[swNo] == Z_levelOn){
00196         ans = 1;
00197     } 
00198 
00199     return (ans);
00200 }