CQ出版社セミナ "実習・Armマイコン内蔵ペリフェラルを活用するためのC++プログラミング" で使う外付け回路のテスト

Dependencies:   mbed UIT_SetOutputPortType UIT_AQM1602 UIT_ADT7410

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PushButton.cpp Source File

PushButton.cpp

00001 //----------------------------------------------------------------
00002 //  InterruptIn, Timeout を利用してチャタリングを防止するクラス
00003 //      割込みサービス・ルーチンは非 static 関数にしている
00004 //
00005 //  2019/03/22, Copyright (c) 2019 MIKAMI, Naoki
00006 //----------------------------------------------------------------
00007 
00008 #include "PushButton.hpp"
00009 
00010 using namespace Mikami;
00011 
00012 // コンストラクタ
00013 PushButton::PushButton(PinName pin, PinMode mode, RiseFall rf,
00014                         void (*Func)(), float time)
00015     : pbSw_(InterruptIn(pin, mode)), fp_(Func), time_(time)
00016 {
00017     if (rf == RISE)
00018         pbSw_.rise(callback(this, &PushButton::IsrIntrIn));
00019     else
00020         pbSw_.fall(callback(this, &PushButton::IsrIntrIn));
00021 }
00022             
00023 // InterruptIn の割込みサービス・ルーチン
00024 void PushButton::IsrIntrIn()
00025 {
00026     pbSw_.disable_irq();
00027     enabler_.attach(callback(this, &PushButton::IsrTimeout), time_);
00028     fp_();      // コンストラクタの引数で与えられた関数が実行される
00029 }
00030 
00031 // Timeout の割込みサービス・ルーチン
00032 void PushButton::IsrTimeout()
00033 {
00034     pbSw_.enable_irq();
00035 }
00036