ssss
Fork of tsi_sensor by
Diff: tsi_sensor.h
- Revision:
- 4:f64097679f27
- Parent:
- 3:20ffa9b18488
- Child:
- 5:14f1557e02a0
- Child:
- 6:f269379b60c5
--- a/tsi_sensor.h Sun Feb 23 18:31:58 2014 +0000 +++ b/tsi_sensor.h Mon Aug 04 07:43:15 2014 +0000 @@ -52,6 +52,12 @@ public: /** Initialize electrode. */ + TSIElectrode(PinName pin) : _threshold(100) { + _channel = getTSIChannel(pin); + } + + /** Initialize electrode. + */ TSIElectrode(uint32_t tsi_channel) : _threshold(100) { _channel = (uint8_t)tsi_channel; } @@ -100,6 +106,38 @@ uint32_t getChannel() { return _channel; } + /** Get TSI Channel for PinName. + * + * @returns TSI channel ID for use in constructor of TSIAnalogSlider and TSIElectrode. + * @throws compile-time error if target is not supported, or runtime error if pin does not match any channel. + */ + static uint8_t getTSIChannel(PinName pin) { +#if defined (TARGET_KL25Z) + switch(pin) { + //these are + case PTA0: return 1; + case PTA1: return 2; + case PTA2: return 3; + case PTA3: return 4; + case PTA4: return 5; + case PTB0: return 0; + case PTB1: return 6; + case PTB2: return 7; + case PTB3: return 8; + case PTB16: return 9; + case PTB17: return 10; + case PTB18: return 11; + case PTB19: return 12; + case PTC0: return 13; + case PTC1: return 14; + default: error("PinName provided to TSIElectrode::getTSIChannel() does not correspond to any known TSI channel."); + } +# else + #error "Unknown target for TSIElectrode::getTSIChannel() - only supports KL25Z so far." +# endif + return 0xFF; //should never get here + } + private: uint8_t _channel; uint16_t _signal; @@ -112,6 +150,11 @@ class TSIAnalogSlider { public: /** + * + * Initialize the TSI Touch Sensor with the given PinNames + */ + TSIAnalogSlider(PinName elec0, PinName elec1, uint32_t range); + /** * Initialize the TSI Touch Sensor */ TSIAnalogSlider(uint32_t elec0, uint32_t elec1, uint32_t range); @@ -167,6 +210,7 @@ return _instance; } private: + void initObject(void); //shared constructor code void sliderRead(void); void selfCalibration(void); void setSliderPercPosition(uint32_t elec_num, uint32_t position) {