flowchart LR
BTN["ボタン ISR"] -->|post| Q[("キュー")]
TMR["タイマー"] -->|post| Q
BLE["BLE"] -->|post| Q
Q -->|wait| L["loop()"]
L --> T["handler_table<br/>[状態][イベント]"]
T --> H["ハンドラ → 次の状態"]
イベントキューと状態遷移テーブルで、ボタン・タイマー・BLE・センサを整理する
delay() や while 待ちで 全体が止まるloop() の 競合flowchart LR
BTN["ボタン ISR"] -->|post| Q[("キュー")]
TMR["タイマー"] -->|post| Q
BLE["BLE"] -->|post| Q
Q -->|wait| L["loop()"]
L --> T["handler_table<br/>[状態][イベント]"]
T --> H["ハンドラ → 次の状態"]
Event = ID + 値でコピーした ペイロード + 時刻xQueueSendToBackFromISR、タスクからは 待たない xQueueSendToBack
event_post() 1 本にportMAX_DELAY で 眠って待つdropped を監視| 状態 | BUTTON_SHORT | BUTTON_LONG | TIMER_100MS | TIMER_1S | CMD_START | CMD_STOP |
|---|---|---|---|---|---|---|
| WAIT | → MEAS | — | 最新値更新 | — | → MEAS | — |
| MEAS | — | → WAIT | サンプル | 集計・通知 | — | → WAIT |
nullptr = 無視。抜け漏れを コードの前に 議論できるtypedef State (*EventHandler)(const Event &ev);
const EventHandler handler_table[STATE_MAX][EVT_MAX] = {
[STATE_WAIT] = { [EVT_BUTTON_SHORT] = wait_on_button_short, ... },
[STATE_MEAS] = { [EVT_BUTTON_LONG] = meas_on_button_long, ... },
};
State dispatch(State cur, const Event &ev) {
EventHandler h = handler_table[cur][ev.id];
return h ? h(ev) : cur;
}| 場所 | コンテキスト | やること |
|---|---|---|
ボタン attachInterrupt |
ISR | 時刻記録 + post |
SoftwareTimer |
タイマータスク | post |
| Bluefruit コールバック | BLE タスク | 解釈 + post |
| ハンドラ | loop タスク | 処理(I²C・送信など) |
delay / Serial / I²C 禁止、共有変数は volatile、チャタリング対策00 01 情報 / 01 00 開始 / 01 01 停止 / 02 01 最新値requestDevice({ filters: [{ services: [UUID] }] })delay() しない(LED は millis() から計算)event_init() を 最初にble.h は SoftDevice と衝突)app/ をハードから切り離して PC でテスト