TSI button support. You may custom the tsi channel of the button and button number.
Dependents: FRDM_KL25Z_TSI_Touch
Fork of TSI by
Revision 4:4b7c5856807e, committed 2015-05-21
- Comitter:
- shaoziyang
- Date:
- Thu May 21 16:29:40 2015 +0000
- Parent:
- 3:1a60ef257879
- Commit message:
- TSI button support.
Changed in this revision
TSISensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
TSISensor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1a60ef257879 -r 4b7c5856807e TSISensor.cpp --- a/TSISensor.cpp Thu May 09 09:24:34 2013 +0000 +++ b/TSISensor.cpp Thu May 21 16:29:40 2015 +0000 @@ -25,60 +25,27 @@ #include "TSISensor.h" #define NO_TOUCH 0 -#define SLIDER_LENGTH 40 //LENGTH in mm -#define TOTAL_ELECTRODE 2 - -#define TSI0a 0 -#define TSI1 1 -#define TSI2 2 -#define TSI3 3 -#define TSI4 4 -#define TSI5 5 -#define TSI6 6 -#define TSI7 7 -#define TSI8 8 -#define TSI9 9 -#define TSI10 10 -#define TSI11 11 -#define TSI12 12 -#define TSI13 13 -#define TSI14 14 -#define TSI15 15 +#define TOTAL_ELECTRODE ELECTRODE_NUM +#define NSCN_NUM 12 -/*Chose the correct TSI channel for the electrode number*/ -#define ELECTRODE0 TSI9 -#define ELECTRODE1 TSI10 -#define ELECTRODE2 TSI0a -#define ELECTRODE3 TSI1 -#define ELECTRODE4 TSI2 -#define ELECTRODE5 TSI3 -#define ELECTRODE6 TSI4 -#define ELECTRODE7 TSI5 -#define ELECTRODE8 TSI6 -#define ELECTRODE9 TSI7 -#define ELECTRODE10 TSI8 -#define ELECTRODE11 TSI11 -#define ELECTRODE12 TSI12 -#define ELECTRODE13 TSI13 -#define ELECTRODE14 TSI14 -#define ELECTRODE15 TSI15 +#define TSI_CH0 0 +#define TSI_CH1 1 +#define TSI_CH2 2 +#define TSI_CH3 3 +#define TSI_CH4 4 +#define TSI_CH5 5 +#define TSI_CH6 6 +#define TSI_CH7 7 +#define TSI_CH8 8 +#define TSI_CH9 9 +#define TSI_CH10 10 +#define TSI_CH11 11 +#define TSI_CH12 12 +#define TSI_CH13 13 +#define TSI_CH14 14 +#define TSI_CH15 15 -#define THRESHOLD0 100 -#define THRESHOLD1 100 -#define THRESHOLD2 100 -#define THRESHOLD3 100 -#define THRESHOLD4 100 -#define THRESHOLD5 100 -#define THRESHOLD6 100 -#define THRESHOLD7 100 -#define THRESHOLD8 100 -#define THRESHOLD9 100 -#define THRESHOLD10 100 -#define THRESHOLD11 100 -#define THRESHOLD12 100 -#define THRESHOLD13 100 -#define THRESHOLD14 100 -#define THRESHOLD15 100 + static uint8_t total_electrode = TOTAL_ELECTRODE; static uint8_t elec_array[16]={ELECTRODE0,ELECTRODE1,ELECTRODE2,ELECTRODE3,ELECTRODE4,ELECTRODE5, @@ -110,7 +77,7 @@ | TSI_GENCS_DVOLT(0) | TSI_GENCS_EXTCHRG(7) | TSI_GENCS_PS(4) - | TSI_GENCS_NSCN(11) + | TSI_GENCS_NSCN(NSCN_NUM-1) | TSI_GENCS_TSIIEN_MASK | TSI_GENCS_STPE_MASK ); @@ -194,6 +161,21 @@ return AbsoluteDistancePosition; } +uint8_t TSISensor::Pressed(uint8_t ch){ + return (gu16Delta[ch] > gu16Threshold[ch]); +} + +float TSISensor::readTSI(uint8_t ch){ + if(Pressed(ch)) + return (gu16Delta[ch]/(NSCN_NUM*128.0 - gu16Baseline[ch])); + else + return 0; +} + +uint16_t TSISensor::readTSI_u16(uint8_t ch){ + return (gu16Delta[ch]); +} + static void changeElectrode(void) { int16_t u16temp_delta;
diff -r 1a60ef257879 -r 4b7c5856807e TSISensor.h --- a/TSISensor.h Thu May 09 09:24:34 2013 +0000 +++ b/TSISensor.h Thu May 21 16:29:40 2015 +0000 @@ -24,6 +24,46 @@ #ifndef TSISENSOR_H #define TSISENSOR_H +#define SLIDER_LENGTH 40 //LENGTH in mm +#define ELECTRODE_NUM 2 + +/*Chose the correct TSI channel for the electrode number*/ +#define ELECTRODE0 TSI_CH9 +#define ELECTRODE1 TSI_CH10 +#define ELECTRODE2 TSI_CH13 +#define ELECTRODE3 TSI_CH1 +#define ELECTRODE4 TSI_CH2 +#define ELECTRODE5 TSI_CH3 +#define ELECTRODE6 TSI_CH4 +#define ELECTRODE7 TSI_CH5 +#define ELECTRODE8 TSI_CH6 +#define ELECTRODE9 TSI_CH7 +#define ELECTRODE10 TSI_CH8 +#define ELECTRODE11 TSI_CH11 +#define ELECTRODE12 TSI_CH12 +#define ELECTRODE13 TSI_CH0 +#define ELECTRODE14 TSI_CH14 +#define ELECTRODE15 TSI_CH15 + +// TSI Channel THRESHOLD +#define THRESHOLD0 100 +#define THRESHOLD1 100 +#define THRESHOLD2 100 +#define THRESHOLD3 100 +#define THRESHOLD4 100 +#define THRESHOLD5 100 +#define THRESHOLD6 100 +#define THRESHOLD7 100 +#define THRESHOLD8 100 +#define THRESHOLD9 100 +#define THRESHOLD10 100 +#define THRESHOLD11 100 +#define THRESHOLD12 100 +#define THRESHOLD13 100 +#define THRESHOLD14 100 +#define THRESHOLD15 100 + + /** * TSISensor example * @@ -63,6 +103,10 @@ */ uint8_t readDistance(); + uint8_t Pressed(uint8_t ch); + float readTSI(uint8_t ch); + uint16_t readTSI_u16(uint8_t ch); + private: void sliderRead(void); void selfCalibration(void);