Silicon Labs / EFM32_CapSenseSlider

Dependents:   EFM32 RDA5807M RDS Radio EMF32-Segment-Touch-Demo EFM32_Bugs MFALHIMOHAMMED ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EFM32_CapSenseSlider.h Source File

EFM32_CapSenseSlider.h

Go to the documentation of this file.
00001 /***************************************************************************//**
00002  * @file EFM32_CapSenseSlider.h
00003  * @brief Driver class for the capacitive touch slider on some EFM32 STK's.
00004  *******************************************************************************
00005  * @section License
00006  * <b>(C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
00007  *******************************************************************************
00008  *
00009  * Permission is granted to anyone to use this software for any purpose,
00010  * including commercial applications, and to alter it and redistribute it
00011  * freely, subject to the following restrictions:
00012  *
00013  * 1. The origin of this software must not be misrepresented; you must not
00014  *    claim that you wrote the original software.
00015  * 2. Altered source versions must be plainly marked as such, and must not be
00016  *    misrepresented as being the original software.
00017  * 3. This notice may not be removed or altered from any source distribution.
00018  *
00019  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Silicon Labs has no
00020  * obligation to support this Software. Silicon Labs is providing the
00021  * Software "AS IS", with no express or implied warranties of any kind,
00022  * including, but not limited to, any implied warranties of merchantability
00023  * or fitness for any particular purpose or warranties against infringement
00024  * of any proprietary rights of a third party.
00025  *
00026  * Silicon Labs will not be liable for any consequential, incidental, or
00027  * special damages, or any other relief, or for any claim by any third party,
00028  * arising from your use of this Software.
00029  *
00030  ******************************************************************************/
00031 
00032 #ifndef SILABS_EFM32_CAPSENSESLIDER_H
00033 #define SILABS_EFM32_CAPSENSESLIDER_H
00034 
00035 #ifndef TARGET_EFM32
00036 #error "The Silicon Labs EFM32 CapSenseSlider library is specifically designed for EFM32 targets."
00037 #elif (defined(TARGET_EFM32GG_STK3700) || defined(TARGET_EFM32TG_STK3300) || defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800))
00038 #include "platform.h"
00039 #include <mbed.h>
00040 
00041 #include "caplesense.h"
00042 #include "CThunk.h"
00043 #include "sleepmodes.h"
00044 
00045 typedef void (*cbptr_t)(void);
00046 
00047 namespace silabs {
00048     
00049 /**  A driver for the capacitive touch slider on some EFM32 STKs
00050  *
00051  * Currently supports EFM32 Wonder, Giant and Leopard Gecko kits.
00052  *
00053  * @code
00054  * #include "mbed.h"
00055  * #include "EFM32_CapSenseSlider.h"
00056  * 
00057  * silabs::EFM32_CapSenseSlider capSlider;
00058  *
00059  * void touchCallback(void) {
00060  *   if(!capSlider.isTouched()) {
00061  *       printf("Lost touch");
00062  *   } else {
00063  *       printf("Finger detected! Position %d", capSlider.getPosition());
00064  *   }
00065  * }
00066  * 
00067  * int main() {
00068  *     capSlider.start();
00069  *     capSlider.attach_touch(touchCallback);
00070  *     
00071  *     while(1) sleep();
00072  * }
00073  * @endcode
00074  */
00075 class EFM32_CapSenseSlider {
00076 public:
00077     /**
00078      * Constructor.
00079      */
00080     EFM32_CapSenseSlider();
00081 
00082     /**
00083      * Start measuring
00084      */
00085     void start();
00086 
00087     /**
00088      * Stop measuring
00089      */
00090     void stop();
00091 
00092     /**
00093      * Attach a callback handler, which gets called once on touch
00094      *
00095      * @param callback   pointer to a void (void) function. If null, then the callback gets disabled.
00096      */
00097     void attach_touch(cbptr_t callback = NULL);
00098 
00099     /**
00100      * Attach a callback handler, which gets called once on releasing touch
00101      *
00102      * @param callback   pointer to a void (void) function. If null, then the callback gets disabled.
00103      */
00104     void attach_untouch(cbptr_t callback = NULL);
00105 
00106     /**
00107      * Attach a callback which will trigger once the slider value passes a certain point.
00108      *
00109      * @param trip       point after which the callback gets called. If -1, the callback gets called on any change in position.
00110      * @param callback   pointer to a void (void) function. If null, then the callback gets disabled.
00111      */
00112     void attach_slide(int32_t trip = -1, cbptr_t callback = NULL);
00113 
00114     /**
00115      * Check whether the slider is currently being touched.
00116      *
00117      * @return           True if a finger is currently detected.
00118      */
00119     bool isTouched();
00120 
00121     /**
00122      * Get the current position
00123      *
00124      * @return           The finger position on the slider (0-48). -1 if not touched.
00125      */
00126     int32_t get_position();
00127 
00128 protected:
00129     CThunk<EFM32_CapSenseSlider> _channelCallback;
00130     CThunk<EFM32_CapSenseSlider> _scanCallback;
00131 
00132     cbptr_t _slideCb;
00133     cbptr_t _touchCb;
00134     cbptr_t _untouchCb;
00135     int32_t _trippingPoint;
00136     bool _running;
00137     bool _touched;
00138     volatile int32_t _lastValue, _position;
00139 
00140     void channelCallbackHandler(void);
00141     void scanCallbackHandler(void);
00142 
00143 };
00144 }
00145 #else
00146 #error "Target is not supported. (supported targets: EFM32WG/LG/GG/TG/G STK's)"
00147 #endif //TARGET Check
00148 
00149 #endif //SILABS_EFM32_CAPSENSESLIDER_H