Clemens Valens
/
touchpad
mbed with Nintendo DS touchpad, accelerometer & touchpad.
touchpad.h@0:0a76ae27065b, 2010-05-05 (annotated)
- Committer:
- Clemo
- Date:
- Wed May 05 12:10:15 2010 +0000
- Revision:
- 0:0a76ae27065b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Clemo | 0:0a76ae27065b | 1 | /* |
Clemo | 0:0a76ae27065b | 2 | Touchpad driver. |
Clemo | 0:0a76ae27065b | 3 | |
Clemo | 0:0a76ae27065b | 4 | CPV, 3/9/2009 |
Clemo | 0:0a76ae27065b | 5 | */ |
Clemo | 0:0a76ae27065b | 6 | |
Clemo | 0:0a76ae27065b | 7 | #ifndef __TOUCHPAD_H__ |
Clemo | 0:0a76ae27065b | 8 | #define __TOUCHPAD_H__ |
Clemo | 0:0a76ae27065b | 9 | |
Clemo | 0:0a76ae27065b | 10 | |
Clemo | 0:0a76ae27065b | 11 | #include "mbed.h" |
Clemo | 0:0a76ae27065b | 12 | #include "filters.h" |
Clemo | 0:0a76ae27065b | 13 | |
Clemo | 0:0a76ae27065b | 14 | |
Clemo | 0:0a76ae27065b | 15 | class TouchpadChannel |
Clemo | 0:0a76ae27065b | 16 | { |
Clemo | 0:0a76ae27065b | 17 | public: |
Clemo | 0:0a76ae27065b | 18 | void initialise(int min, int quantise_step); |
Clemo | 0:0a76ae27065b | 19 | void tick(int v) { m_filter.tick(v); } |
Clemo | 0:0a76ae27065b | 20 | int quantise(void); |
Clemo | 0:0a76ae27065b | 21 | int operator()(void) { return m_quantised; } |
Clemo | 0:0a76ae27065b | 22 | int get_raw(void) { return m_filter(); } |
Clemo | 0:0a76ae27065b | 23 | |
Clemo | 0:0a76ae27065b | 24 | protected: |
Clemo | 0:0a76ae27065b | 25 | FilterBoxI m_filter; |
Clemo | 0:0a76ae27065b | 26 | int m_min; |
Clemo | 0:0a76ae27065b | 27 | int m_quantise_step; |
Clemo | 0:0a76ae27065b | 28 | int m_quantised; |
Clemo | 0:0a76ae27065b | 29 | }; |
Clemo | 0:0a76ae27065b | 30 | |
Clemo | 0:0a76ae27065b | 31 | |
Clemo | 0:0a76ae27065b | 32 | class Touchpad |
Clemo | 0:0a76ae27065b | 33 | { |
Clemo | 0:0a76ae27065b | 34 | public: |
Clemo | 0:0a76ae27065b | 35 | Touchpad(PinName x0, PinName x1, PinName y0, PinName y1); |
Clemo | 0:0a76ae27065b | 36 | |
Clemo | 0:0a76ae27065b | 37 | void tick(void); |
Clemo | 0:0a76ae27065b | 38 | |
Clemo | 0:0a76ae27065b | 39 | int get_raw_x(void) { return m_ch_x.get_raw(); } |
Clemo | 0:0a76ae27065b | 40 | int get_raw_y(void) { return m_ch_y.get_raw(); } |
Clemo | 0:0a76ae27065b | 41 | |
Clemo | 0:0a76ae27065b | 42 | int hotspot(void) { return (m_ch_x.quantise()>=0 && m_ch_y.quantise()>=0); } |
Clemo | 0:0a76ae27065b | 43 | int get_hotspot_x(void) { return m_ch_x(); } |
Clemo | 0:0a76ae27065b | 44 | int get_hotspot_y(void) { return m_ch_y(); } |
Clemo | 0:0a76ae27065b | 45 | |
Clemo | 0:0a76ae27065b | 46 | protected: |
Clemo | 0:0a76ae27065b | 47 | TouchpadChannel m_ch_x; |
Clemo | 0:0a76ae27065b | 48 | TouchpadChannel m_ch_y; |
Clemo | 0:0a76ae27065b | 49 | |
Clemo | 0:0a76ae27065b | 50 | PinName m_x0; |
Clemo | 0:0a76ae27065b | 51 | PinName m_x1; |
Clemo | 0:0a76ae27065b | 52 | PinName m_y0; |
Clemo | 0:0a76ae27065b | 53 | PinName m_y1; |
Clemo | 0:0a76ae27065b | 54 | |
Clemo | 0:0a76ae27065b | 55 | int read(PinName drive_hi, PinName drive_lo, PinName read_hi, PinName read_lo); |
Clemo | 0:0a76ae27065b | 56 | int read_x(void) { return read(m_x1,m_x0,m_y1,m_y0); } |
Clemo | 0:0a76ae27065b | 57 | int read_y(void) { return read(m_y1,m_y0,m_x1,m_x0); } |
Clemo | 0:0a76ae27065b | 58 | }; |
Clemo | 0:0a76ae27065b | 59 | |
Clemo | 0:0a76ae27065b | 60 | |
Clemo | 0:0a76ae27065b | 61 | #endif // __TOUCHPAD_H__ |