Mbed OS 5

Fork of PinDetect by Arturo Alvarado

Rewritten to Mbed OS 5 and their callback mechanism

Revision:
5:2b0afd293d1d
Parent:
4:bacc386fe2ad
Child:
6:09458c0b5cad
--- a/PinDetect.h	Wed Nov 16 23:20:29 2016 +0000
+++ b/PinDetect.h	Thu Jun 28 14:02:22 2018 +0200
@@ -1,16 +1,16 @@
 /*
     Copyright (c) 2010 Andy Kirkham
- 
+
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to deal
     in the Software without restriction, including without limitation the rights
     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     copies of the Software, and to permit persons to whom the Software is
     furnished to do so, subject to the following conditions:
- 
+
     The above copyright notice and this permission notice shall be included in
     all copies or substantial portions of the Software.
- 
+
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -24,127 +24,98 @@
 #define AJK_PIN_DETECT_H
 
 #ifndef MBED_H
-#include "mbed.h"
+    #include "mbed.h"
 #endif
 
-#ifndef PINDETECT_PIN_ASSTERED
-#define PINDETECT_PIN_ASSTERED   1
+#ifndef PINDETECT_PIN_ASSERTED
+    #define PINDETECT_PIN_ASSERTED   1
 #endif
 
 #ifndef PINDETECT_SAMPLE_PERIOD
-#define PINDETECT_SAMPLE_PERIOD 20000
+    #define PINDETECT_SAMPLE_PERIOD 20000
 #endif
 
-#ifndef PINDETECT_ASSERT_COUNT  
-#define PINDETECT_ASSERT_COUNT  1
+#ifndef PINDETECT_ASSERT_COUNT
+    #define PINDETECT_ASSERT_COUNT  1
 #endif
 
 #ifndef PINDETECT_HOLD_COUNT
-#define PINDETECT_HOLD_COUNT    50
+    #define PINDETECT_HOLD_COUNT    50
 #endif
 
 namespace AjK {
 
 class PinDetect {
-
-public:
+  public:
     friend class Ticker;
-    
-    
+
+
     /** PinDetect constructor
      *
      * By default the PinMode is set to PullDown.
      *
      * @see http://mbed.org/handbook/DigitalIn
      * @param p PinName is a valid pin that supports DigitalIn
-     */   
+     */
     PinDetect(PinName p);
-    
+
     /** PinDetect constructor
      *
      * @see http://mbed.org/handbook/DigitalIn
      * @param PinName p is a valid pin that supports DigitalIn
      * @param PinMode m The mode the DigitalIn should use.
-     */  
+     */
     PinDetect(PinName p, PinMode m);
-    
+
     /** PinDetect destructor
-     */ 
+     */
     virtual ~PinDetect(void);
-    
+
     /** Set the sampling time in microseconds.
      *
      * @param int The time between pin samples in microseconds.
      */
     void setSampleFrequency(int i = PINDETECT_SAMPLE_PERIOD);
-    
+
     /** Set the value used as assert.
      *
      * Defaults to 1 (ie if pin == 1 then pin asserted).
      *
      * @param int New assert value (1 or 0)
      */
-    void setAssertValue (int i = PINDETECT_PIN_ASSTERED);
-    
+    void setAssertValue(int i = PINDETECT_PIN_ASSTERED);
+
     /** Set the number of continuous samples until assert assumed.
      *
      * Defaults to 1 (1 * sample frequency).
      *
      * @param int The number of continuous samples until assert assumed.
-     */    
+     */
     void setSamplesTillAssert(int i);
-    
+
     /** Set the number of continuous samples until held assumed.
      *
      * Defaults to 50 * sample frequency.
      *
      * @param int The number of continuous samples until held assumed.
-     */    
+     */
     void setSamplesTillHeld(int i);
-    
+
     /** Set the pin mode.
      *
      * @see http://mbed.org/projects/libraries/api/mbed/trunk/DigitalInOut#DigitalInOut.mode
      * @param PinMode m The mode to pass on to the DigitalIn
      */
     void mode(PinMode m);
-    
+
     void attach_asserted(Callback<void()> function);
-    
-    template<typename T, typename M>
-    void attach_asserted(T *obj, M method){
-        core_util_critical_section_enter();
-        attach_asserted(callback(obj, method));
-        core_util_critical_section_exit();
-    }
-    
+
     void attach_deasserted(Callback<void()> function);
-    
-    template<typename T, typename M>
-    void attach_deasserted(T *obj, M method){
-        core_util_critical_section_enter();
-        attach_deasserted(callback(obj, method));
-        core_util_critical_section_exit();
-    }
-    
+
     void attach_asserted_held(Callback<void()> function);
-    
-    template<typename T, typename M>
-    void attach_asserted_held(T *obj, M method){
-        core_util_critical_section_enter();
-        attach_asserted_held(callback(obj, method));
-        core_util_critical_section_exit();
-    }
-    
+
     void attach_deasserted_held(Callback<void()> function);
-    
-    template<typename T, typename M>
-    void attach_deasserted_held(T *obj, M method){
-        core_util_critical_section_enter();
-        attach_deasserted_held(callback(obj, method));
-        core_util_critical_section_exit();
-    }
-    
+
     /** operator int()
      *
      * Read the value of the pin being sampled.
@@ -153,7 +124,7 @@
         return _in->read();
     }
 
-protected:    
+  protected:
     DigitalIn   *_in;
     Ticker      *_ticker;
     int         _prevState;
@@ -168,11 +139,11 @@
     Callback<void()> _callbackDeasserted;
     Callback<void()> _callbackAssertedHeld;
     Callback<void()> _callbackDeassertedHeld;
-    
-   /** The Ticker periodic callback function
-     */
+
+    /** The Ticker periodic callback function
+      */
     void isr(void);
-    
+
     /** initialise class
      *
      * @param PinName p is a valid pin that supports DigitalIn