Thundersoft / Mbed OS PirSensor_for_TT_Mxx

Files at this revision

API Documentation at this revision

Comitter:
ThunderSoft
Date:
Thu Mar 21 10:01:07 2019 +0000
Child:
1:0b1a84ce037f
Commit message:
Add PriSenor code for TT_Mxx

Changed in this revision

PirSensor/PirSensor.cpp Show annotated file Show diff for this revision Revisions of this file
PirSensor/PirSensor.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PirSensor/PirSensor.cpp	Thu Mar 21 10:01:07 2019 +0000
@@ -0,0 +1,28 @@
+#include "PirSensor.h"
+
+
+
+#if defined(__TT_M4G9__)
+#define DEFAULT_DOR_PIN PL0
+#endif
+
+
+#if defined(__TT_M3HQ__)
+#define DEFAULT_DOR_PIN PK7
+#endif
+
+
+PirSensor::PirSensor()
+{
+     interruptPin = new InterruptIn(DEFAULT_DOR_PIN);
+}
+
+PirSensor::PirSensor(PinName pin)
+{
+    interruptPin = new InterruptIn(pin);
+}
+
+void PirSensor::handleCallback(Callback<void()> func)
+{
+    interruptPin->fall(func);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PirSensor/PirSensor.h	Thu Mar 21 10:01:07 2019 +0000
@@ -0,0 +1,34 @@
+#ifndef PIRSENSOR_H
+#define PIRSENSOR_H
+
+#include "mbed.h"
+
+
+
+class PirSensor {
+
+
+public:
+    /**
+     * @brief 
+     */
+    PirSensor(PinName pin);
+
+    PirSensor();
+
+    /**
+     * @brief Handle the event about door status.
+     * @param func handle of function.
+     */
+    void handleCallback(Callback<void()> func);
+private:
+    InterruptIn *interruptPin;
+
+};
+
+
+
+
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 21 10:01:07 2019 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "PirSensor.h"
+
+
+
+
+
+
+#if __TT_M3HQ__
+#define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M3HQ"
+#endif
+
+
+#if __TT_M4G9__
+#define DISPLAY_TMPM_STRING "Welcome to Thundersoft TT_M4G9"
+#endif
+
+DigitalOut testLed(LED1);
+
+static void pirHandle()
+{
+    testLed = 1;
+    wait_ms(5000);
+    testLed = 0;
+}
+
+int main()
+{
+    printf("%s\r\n",DISPLAY_TMPM_STRING);
+    PirSensor pir;
+    testLed = 1;
+    pir.handleCallback(&pirHandle);
+    while(1)
+    {
+
+    }  
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Mar 21 10:01:07 2019 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#51d55508e8400b60af467005646c4e2164738d48