APP2 - SNE CODE / Mbed 2 deprecated Exercice_3V1

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Kurogami
Date:
Fri Mar 01 15:49:13 2019 +0000
Commit message:
Voila voila

Changed in this revision

blink.cpp Show annotated file Show diff for this revision Revisions of this file
blink.h Show annotated file Show diff for this revision Revisions of this file
bp.cpp Show annotated file Show diff for this revision Revisions of this file
bp.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.bld Show annotated file Show diff for this revision Revisions of this file
onoff.cpp Show annotated file Show diff for this revision Revisions of this file
onoff.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blink.cpp	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,59 @@
+#include "blink.h"
+
+smartled::blink::blink(PinName name,smartled::bp * bp, std::size_t * click_cpt) : DigitalOut(name), m_bp(bp), m_click_cpt(click_cpt)
+{
+    
+}
+
+void smartled::blink::run(void)
+{
+    static blinkEtat state=off;
+    
+    switch(state)
+    {
+    case off:
+        if(*m_click_cpt>0u)
+        {
+            *m_click_cpt= *m_click_cpt - 1u;
+            m_timer.reset();
+            m_timer.start();
+            this->write(1);
+            state=blinkOn;
+        }
+        break;
+        
+    case blinkOn:
+        if(m_timer.read_ms()>250)
+        {
+            this->write(0);
+            m_timer.reset();
+            m_timer.start();
+            state=blinkOff;
+        }
+        break;
+        
+    case blinkOff:
+        if(m_timer.read_ms()>1000)
+        {
+            if(*m_click_cpt>0u)
+            {
+                *m_click_cpt= *m_click_cpt - 1u;
+                m_timer.reset();
+                m_timer.start();
+                this->write(1);
+                state=blinkOn;
+            }
+            else
+            {
+                m_timer.stop();
+                state=off;
+            }
+        }
+        break;        
+    }
+}
+
+void smartled::blink::operator ()(void)
+{
+    this->run();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blink.h	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,28 @@
+#ifndef BLINK_H
+#define BLINK_H
+
+#include <DigitalOut.h>
+#include <Timer.h>
+#include "bp.h"
+
+namespace smartled
+{
+
+typedef enum{off,blinkOn,blinkOff} blinkEtat;
+
+class blink : mbed::DigitalOut
+{
+public:
+    blink(PinName name,smartled::bp * bp, std::size_t * click_cpt);
+    
+    void run(void);
+    
+    void operator ()(void);
+private:
+    smartled::bp * m_bp;
+    std::size_t * m_click_cpt;
+    mbed::Timer m_timer;
+};
+
+}
+#endif //BLINK_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bp.cpp	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,68 @@
+#include "bp.h"
+
+smartled::bp::bp(PinName name, std::size_t * click_cpt) : DigitalIn(name), m_click_cpt(click_cpt)
+{
+    
+}
+
+void smartled::bp::run(void)
+{
+    static bpEtat state = init;
+    
+    switch(state)
+    {
+    case init :
+        if(*this==1)
+        {
+            m_timer.reset();
+            m_timer.start();
+            state = under50ms;
+        }
+        break;
+    case under50ms:
+        if(*this == 0)
+        {
+            m_timer.stop();
+            state=init;
+        }
+        else if (m_timer.read_ms()>50)
+        {
+            state = shortPush;
+        }
+        break;
+    case shortPush:
+        if(*this == 0)
+        {
+            if(m_isOnOff_On)
+            {
+                *m_click_cpt= *m_click_cpt + 1u;
+            }
+            m_timer.stop();
+            state=init;
+        }
+        else if (m_timer.read_ms()>250)
+        {
+            state = longPush;
+        }
+        break;
+    case longPush:
+        if(*this == 0)
+        {
+            m_isOnOff_On=!m_isOnOff_On;
+            *m_click_cpt = 0u;
+            m_timer.stop();
+            state=init;
+        }
+        break;
+    }
+}
+
+bool smartled::bp::getIsOnOff_On(void)
+{
+    return m_isOnOff_On;
+}
+
+void smartled::bp::operator ()(void)
+{
+    this->run();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bp.h	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,29 @@
+#ifndef BP_H
+#define BP_H
+
+#include <DigitalIn.h>
+#include <Timer.h>
+
+namespace smartled
+{
+typedef enum {init,under50ms,shortPush,longPush} bpEtat;
+
+class bp : public mbed::DigitalIn
+{
+public:
+    bp(PinName name,std::size_t * click_cpt);
+    
+    void run(void);
+    
+    bool getIsOnOff_On(void);
+    
+    void operator ()(void);
+    
+private:
+    std::size_t * m_click_cpt;
+    bool m_isOnOff_On;
+    mbed::Timer m_timer;
+};
+
+}
+#endif //BP_H
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,26 @@
+#include <PinNames.h>
+#include <DigitalOut.h>
+#include <cstddef>
+#include "bp.h"
+#include "onoff.h"
+#include "blink.h"
+
+//# include <Timer.h>
+
+
+
+int main ()
+{
+    std::size_t click_cpt =0u;
+    smartled::bp my_bp(PA_0 , &click_cpt);
+    smartled::onoff my_onoff(PB_2,&my_bp,&click_cpt);
+    smartled::blink my_blink(PE_8,&my_bp,&click_cpt);
+    
+    while (1)
+    {
+        my_bp();
+        my_onoff();
+        my_blink();
+    }
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/onoff.cpp	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,19 @@
+#include "onoff.h"
+
+smartled::onoff::onoff(PinName name,smartled::bp * bp, std::size_t * click_cpt) : DigitalOut(name), m_bp(bp) , m_click_cpt(click_cpt)
+{
+    this->write(0);
+}
+
+void smartled::onoff::run(void)
+{
+    if(m_bp->getIsOnOff_On())
+        this->write(1);
+    else
+        this->write(0);
+}
+
+void smartled::onoff::operator ()(void)
+{
+    this->run();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/onoff.h	Fri Mar 01 15:49:13 2019 +0000
@@ -0,0 +1,25 @@
+#ifndef ONOFF_H
+#define ONOFF_H
+
+#include <DigitalOut.h>
+#include <bp.h>
+
+namespace smartled 
+{
+
+class onoff : public mbed::DigitalOut
+{
+public:
+    onoff(PinName name,smartled::bp * bp, std::size_t * click_cpt);
+    
+    void run(void);
+    
+    void operator ()(void);
+private:
+    smartled::bp * m_bp;
+    bool m_state;
+    std::size_t * m_click_cpt;
+};
+
+}
+#endif // ONOFF_H
\ No newline at end of file