TTP229 16key touch keypad

Dependents:   TTP229_sample

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TTP229.h Source File

TTP229.h

00001 #ifndef TTP229_H
00002 #define TTP229_H
00003 #include "mbed.h"
00004 #include <bitset>
00005 
00006 /** 16key touch keypad\n
00007  *  Only supported 16key and active low mode\n
00008  *  jamper settng : TP1=1(jamper2=open):active low, TP2=0(jamper3=close):16key mode\n
00009  */
00010 class TTP229 {
00011 public:
00012     ///@param sdopin PinName that support DigitalIn and InterruptIn, connected to TTP229 SDO.
00013     ///@param sclpin PinName that support DigitalOut, connected to TTP229 SCL.
00014     TTP229 (PinName sdopin, PinName sclpin);
00015     /// set function that is called at change state of keypad\n
00016     /// FunctionPointer is a pointer to function(no param and void return)
00017     /// @code
00018     /// void func();
00019     /// ttp229.attach(&func);
00020     /// @endcode
00021     /// or to menber function(no param and void return)
00022     /// @code
00023     /// class Foo {
00024     /// public:
00025     ///     void func();
00026     /// };
00027     /// Foo foo;   
00028     /// ttp229.attach(FunctionPointer(&foo, &Foo::func));
00029     /// @endcode
00030     void attach(const FunctionPointer& fp) {callback=fp;}
00031     ///get keypad status
00032     bitset<16> getkeys() {return sw;}
00033     ///same as getkeys()
00034     operator bitset<16>() {return getkeys();}
00035     ///get keypad status especially singlekey mode(TP3=1,TP4=1)
00036     ///@return touched keypad number(1~16) or 0:no keypad touched
00037     int onkey() {return swnum;}
00038     ///Is number i(0~15) keypad touched?
00039     bool ison(size_t i) {return getkeys()[i];}
00040     ///same as ison()
00041     bool operator[](size_t i) {return ison(i);}
00042 protected:
00043     void interrupt();
00044 private:
00045     DigitalIn sdo;
00046     InterruptIn sdoInt;
00047     DigitalOut scl;
00048     FunctionPointer callback;
00049     bitset<16> sw;
00050     int swnum;
00051 };
00052 
00053 #endif