test publish
Dependencies: BLE_API nRF51822 mbed
Fork of KS7 by
exio.h
00001 /*------------------------------------------------------------ 00002 exio.h 00003 拡張内容 00004 ・スイッチ長押し/通常押しの区別 00005 ・秒をHH:MM表示する。 00006 ・HH:MMをLED表示する。 00007 -------------------------------------------------------------*/ 00008 #ifndef __EXIO_H__ 00009 #define __EXIO_H__ 00010 00011 #include "mbed.h" 00012 #include "io.h" 00013 #include "app_util.h" 00014 #include <time.h> 00015 #include "ble_date_time.h" 00016 #include "common.h" 00017 00018 class exio : public io 00019 { 00020 protected: 00021 /*単位の表示*/ 00022 virtual void display_unit(void) 00023 { 00024 // [row6] D56-D49 00025 // [row7] D64-D57 00026 // 00027 // D53 D54 D55 * * * 00028 // D56 D57 D58 * 00029 // D59 D60 D61 * 00030 // D62 D63 D64 * 00031 // 00032 if(_mode == M_SCALE){ // (SCALE) G 00033 _row_out[6] |= 0xf0; 00034 _row_out[7] |= 0xf4; 00035 _cnt = 0; 00036 } else if(_mode == M_WATCHTIMER && _state == S_WATCH){ // (WATCH) .(period) 00037 if(_cnt < 5){ 00038 L001: 00039 _row_out[6] |= 0x00; // 単位表示 00040 _row_out[7] |= 0x20; 00041 } else if(_cnt < 10){ 00042 _row_out[6] &= 0x0f; // 単位消去 00043 _row_out[7] &= 0x00; 00044 } else { 00045 _cnt = 0; 00046 goto L001; 00047 } 00048 } else if(_mode == M_WATCHTIMER && _state == S_TIMER){ // (TIME) T 00049 _row_out[6] |= (0x10 + 0x20 + 0x40); 00050 _row_out[7] |= (0x01 + 0x08 + 0x40); 00051 _cnt = 0; 00052 } 00053 } 00054 /*void display_unitT(void) 00055 { 00056 // 単位T表示 00057 _row_out[6] |= (0x10 + 0x20 + 0x40); 00058 _row_out[7] |= (0x01 + 0x08 + 0x40); 00059 _cnt = 0; 00060 }*/ 00061 protected: 00062 /*100msec処理*/ 00063 virtual void TickerCallback(void) 00064 { 00065 _cnt++; 00066 // スイッチ状態を定期的に見る 00067 uint8_t sw = _sw->read(); 00068 if(sw == 1 && !_swFlag){// スイッチ押されたとき 00069 _counter = 0; 00070 _swState = None; 00071 _swFlag = true; 00072 00073 } else if(sw == 0 && _swFlag){// スイッチ離されたとき 00074 _swFlag = false; 00075 if(_swState == None){ // スイッチ状態未決定の場合 00076 if(_counter >= 10){ /*1sec*/ 00077 _swState = LongPressed; 00078 //printf("LongPressed\r\n"); 00079 } else { 00080 _swState = Pressed; 00081 //printf("Pressed\r\n"); 00082 } 00083 } 00084 } else { 00085 _counter++; 00086 // スイッチ押された状態で1sec経過したらコールバック 00087 if(_swFlag && _counter >= 10 && !_callFlag){ 00088 _callback.call(); 00089 _callFlag = true; // 1回コールすれば用済み 00090 } 00091 } 00092 _lastSW = sw; 00093 #ifdef UART_DEBUG 00094 //pc.printf("%d", sw); 00095 #endif 00096 } 00097 00098 public: 00099 /*コンストラクタ*/ 00100 exio() : io(P0_15, P0_13) 00101 { 00102 _callFlag = false; 00103 _cnt = 0; 00104 _swFlag = false; 00105 _swState = None; 00106 _ticker.attach(this, &exio::TickerCallback, 0.1); 00107 } 00108 00109 /*スイッチ状態*/ 00110 typedef enum { 00111 None = 0, 00112 Pressed, 00113 LongPressed, 00114 } Switch_t; 00115 00116 /*スイッチ状態の取得 ==> スーパークラスのものを上書き*/ 00117 virtual uint8_t get_switch() 00118 { 00119 return _swState; 00120 } 00121 00122 /*スイッチ状態のリセット*/ 00123 void switch_reset(void) 00124 { 00125 _swState = None; 00126 _lastSW = 0; 00127 } 00128 00129 /*秒をHH:MM表示する*/ 00130 void displaySeconds(int value) 00131 { 00132 // 4-digit convert 00133 // 40s->0040 100s->0140 00134 int a = value / 60; 00135 int b = value % 60; 00136 value = 100 * a + b; 00137 display_value = value; 00138 #ifdef UART_DEBUG 00139 pc.printf("[%04d]\r\n", value); 00140 #endif 00141 } 00142 00143 /*HH:MMをLED表示する*/ 00144 void displayHHMM(ble_date_time_t &dt) 00145 { 00146 // 4-digit convert 00147 // 10:50->1050 23:59->2359 00148 int value = dt.hours * 100 + dt.minutes; 00149 display_value = value; 00150 #ifdef UART_DEBUG 00151 pc.printf("[%04d][%d/%d/%d %02d:%02d:%02d]\r\n", 00152 value, dt.year, dt.month, dt.day, dt.hours, dt.minutes, dt.seconds); 00153 #endif 00154 } 00155 00156 void attach(void (*func)(void)) 00157 { 00158 _callback.attach(func); 00159 } 00160 /*template<typename T> 00161 void attach(T *obj, void (T::*member)(void)) 00162 { 00163 _callback.attach(obj, member); 00164 }*/ 00165 void CallFlagClear() 00166 { 00167 _callFlag = false; 00168 } 00169 00170 private: 00171 bool _swFlag; 00172 Switch_t _swState; 00173 uint8_t _lastSW; 00174 Ticker _ticker; 00175 int _counter; 00176 int _cnt; 00177 FunctionPointer _callback; 00178 bool _callFlag; 00179 00180 }; 00181 00182 #endif /*__EXIO_H__*/
Generated on Fri Jul 15 2022 17:45:18 by
1.7.2
