Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Lorawan_Version_0_1
Dependents: Lorawan_Version_0_1
Diff: Light/Light.cpp
- Revision:
- 70:65b2f1cc2859
- Parent:
- 69:316fee01f5d9
- Child:
- 71:ca2425c0a864
diff -r 316fee01f5d9 -r 65b2f1cc2859 Light/Light.cpp
--- a/Light/Light.cpp Sun Jan 19 15:53:57 2020 +0000
+++ b/Light/Light.cpp Tue Jan 21 13:20:59 2020 +0000
@@ -8,88 +8,55 @@
#include "GPS.h"
#include <mbed.h>
#include "Light.h"
-
-
-
-DigitalOut LichtAus(PC_12);
-DigitalOut LichtHell(PC_9);
-DigitalOut led1(LED1);
+static EventQueue *Ref_Events;
-static EventQueue *Ref_Events;
-int BlinkEventID;
-
-
- int blink_counter,max_blink_count;
-int GPSEvent;
-
-Light::Light(EventQueue *q)
+Light::Light(EventQueue *q,DigitalOut *la,DigitalOut*lh)
{
Ref_Events=q;
+ LichtAus=la;
+ LichtHell=lh;
}
void Light::adjust(bool IsMoving, uint32_t TimeStanding )
{
- LichtHell=IsMoving;
- LichtAus=TimeStanding>10000;
-}
-
-void Light::Licht_aus()
-{
- printf("\r\n LICHT AUS \r\n");
- LichtHell=0;
- LichtAus=1;
-}
-
-void Light::Licht_an(int time)
-{
- printf("\r\n LICHT AN\r\n");
- LichtHell=1;
- LichtAus=0;
- if (time>0) {Ref_Events->call_in(time, Licht_aus);}
+ if (this->BlinkEventID == 0){ // if Blinking is active we shouldnt override the blink outputs
+ if(IsMoving) LichtHell->write(1); else LichtHell->write(0);
+ if(TimeStanding>10000) LichtAus->write(1); else LichtAus->write(0);
+ }
}
-void Light::Licht_hell()
-{
- LichtHell=1;
-}
-
-void Light::Licht_dunkel()
-{
- LichtHell=0;
-}
-
-
-void Light::Licht_toggle()
+void Light::Licht_toggle(Light *l)
{
- printf("\r\n LICHT TOGGLE \r\n");
- if (LichtAus)
- {
- LichtHell=1;
- LichtAus=0;
- }else
- {
- LichtHell=0;
- LichtAus=1;
+ printf("\r\n[Light] TOGGLE\n");
+ if (l->LichtAus->read()){
+ l->LichtHell->write(1);
+ l->LichtAus->write(0);
+ }else{
+ l->LichtHell->write(0);
+ l->LichtAus->write(1);
}
}
-void Light::Blinken_aus()
+void Light::Blinken_aus(Light *l)
{
- printf("\r\n BLINKEN AUS \r\n");
- Ref_Events->cancel(BlinkEventID);
- LichtHell=0;
- LichtAus=1;
+ printf("\n[Light] BLINK STOP\n");
+ Ref_Events->cancel(l->BlinkEventID);
+ l->BlinkEventID=0;
+ l->LichtHell->write(0);
+ l->LichtAus->write(1);
}
void Light::Blinken_ein(int time_to_blink)
{
- printf("\r\n BLINKEN EIN\r\n");
- BlinkEventID=Ref_Events->call_every(500,Licht_toggle);
- Ref_Events->call_in(time_to_blink, Blinken_aus);
+ if (this->BlinkEventID == 0){ // we can only track 1 blinkevent so we cant have 2 running at the same time
+ printf("\n [Light] BLINK START\n");
+ this->BlinkEventID=Ref_Events->call_every(500,Licht_toggle,this);
+ Ref_Events->call_in(time_to_blink, Blinken_aus,this);
+ }
}