Buttons update
Dependencies: mbed mbed-rtos X_NUCLEO_IHM02A1
Revision 38:3776ee18e56f, committed 2019-05-13
- Comitter:
- scherfa2
- Date:
- Mon May 13 10:11:48 2019 +0000
- Parent:
- 37:a74d377d8f74
- Commit message:
- Buttons update
Changed in this revision
--- a/Buttons.cpp Fri May 10 17:31:36 2019 +0000
+++ b/Buttons.cpp Mon May 13 10:11:48 2019 +0000
@@ -1,5 +1,11 @@
#include "SETUP.h"
+
+extern DigitalIn Button1;
+extern DigitalIn Button2;
+
+
+/*
extern volatile bool buttonSTART_pressed; // Used in the main loop
extern volatile bool buttonSTART_enabled; // Used for debouncing
extern Timeout buttonSTART_timeout; // Used for debouncing
@@ -8,9 +14,9 @@
extern volatile bool buttonAbbruch_enabled; // Used for debouncing
extern Timeout buttonAbbruch_timeout; // Used for debouncing
-
+*/
-/* --------------------------- START_BUTTON --------------------------------- */
+/* --------------------------- START_BUTTON ---------------------------------
// Enables button when bouncing is over
void buttonSTART_enabled_cb(void)
{
@@ -36,7 +42,7 @@
-/* ------------------------- ABBRUCH_BUTTON --------------------------------- */
+/* ------------------------- ABBRUCH_BUTTON ---------------------------------
// Enables button when bouncing is over
void buttonAbbruch_enabled_cb(void)
{
@@ -57,22 +63,49 @@
buttonAbbruch_timeout.attach(callback(buttonAbbruch_enabled_cb), 0.300); // Debounce time 300 ms
}
}
-/*
-bool Button_2()
+*/
+
+bool get_Button_1()
+{
+ if(Button1 == 1)
+ {
+ wait(0.01);
+ if(Button1 == 1)
+ {
+ return true;
+ }
+ }
+ else if(Button1 == 0)
+ {
+ wait(0.01);
+ if(Button1 == 0)
+ {
+ return false;
+ }
+ }
+ else return false;
+}
+
+bool get_Button_2()
{
if(Button2 == 1)
{
- wait(0.1);
+ wait(0.01);
if(Button2 == 1)
{
- retrun true;
+ return true;
}
-
}
else if(Button2 == 0)
{
-
+ wait(0.01);
+ if(Button2 == 0)
+ {
+ return false;
+ }
}
-}*/
+ else return false;
+}
+
/* ---------------------------------- END ----------------------------------- */
--- a/Buttons.h Fri May 10 17:31:36 2019 +0000 +++ b/Buttons.h Mon May 13 10:11:48 2019 +0000 @@ -2,16 +2,18 @@ #define MBED_Buttons_H /* --------------------------- START_BUTTON --------------------------------- */ -void buttonSTART_enabled_cb(); +/*void buttonSTART_enabled_cb(); void buttonSTART_diable_cb(); -void buttonSTART_onpressed_cb(); +void buttonSTART_onpressed_cb();*/ +bool get_Button_1(); /* ---------------------------------- END ----------------------------------- */ /* ------------------------- ABBRUCH_BUTTON --------------------------------- */ -void buttonAbbruch_enabled_cb(); +/*void buttonAbbruch_enabled_cb(); void buttonAbbruch_diable_cb(); -void buttonAbbruch_onpressed_cb(); +void buttonAbbruch_onpressed_cb();*/ +bool get_Button_2(); /* ---------------------------------- END ----------------------------------- */
--- a/PWM.cpp Fri May 10 17:31:36 2019 +0000
+++ b/PWM.cpp Mon May 13 10:11:48 2019 +0000
@@ -43,10 +43,10 @@
void Init_Cutter()
{
Cutter_1.period(1/(float)CUTTER_FRQ_1);
- Cutter_1 = 0.7;
+ Cutter_1 = 0.0;
Cutter_2.period(1/(float)CUTTER_FRQ_2);
- Cutter_2 = 0.7;
+ Cutter_2 = 0.0;
}
void Set_Cutter(int arc_on_time, int arc_off_time, int repeats)
@@ -71,10 +71,10 @@
void Init_Spleisser()
{
Spleisser_1.period(1/(float)SPLEISSER_FRQ_1);
- Spleisser_1 = 0.7;
+ Spleisser_1 = 0.0;
Spleisser_2.period(1/(float)SPLEISSER_FRQ_2);
- Spleisser_2 = 0.7;
+ Spleisser_2 = 0.0;
}
void Set_Spleisser(int arc_on_time, int arc_off_time, int repeats)
--- a/ST_DUO.cpp Fri May 10 17:31:36 2019 +0000
+++ b/ST_DUO.cpp Mon May 13 10:11:48 2019 +0000
@@ -2,58 +2,176 @@
int StatusDUO=DUO_DEFAULT;
+
+bool ButtonSTART = false;
+bool ButtonABBRUCH = false;
+
+
+/*
extern volatile bool buttonSTART_pressed;
extern volatile bool buttonSTART_enabled;
+
+extern volatile bool buttonAbbruch_pressed;
+extern volatile bool buttonAbbruch_enabled;
+*/
+
+
+
extern PwmOut Servo;
+extern L6470 **motors;
+extern L6470B **motors2;
+
+extern DigitalIn LS_1;
+extern DigitalIn LS_2;
+extern DigitalIn LS_3;
+
+extern PwmOut Cutter_1;
+extern PwmOut Cutter_2;
+extern PwmOut Spleisser_1;
+extern PwmOut Spleisser_2;
+
+void EntryDuoDefault()
+{
+ StatusDUO=DUO_DEFAULT;
+}
+
void EntryDuoStart()
{
+ Stepper_1_Leerlauf();
+ Stepper_2_Leerlauf();
+ Stepper_3_Leerlauf();
+
+ DisplaySendeBefehl(0x0C);
+ DisplaySendeBefehl(0x01);
+ gotoxy(1,1);
+ DisplaySendeString("Modus: DUO-Betrieb");
+ gotoxy(1,4);
+ DisplaySendeString("Start PLA");
+
+ StatusDUO=DUO_START;
+
+}
+
+void EntryDuoFilamentIN()
+{
+ DisplaySendeBefehl(0x01);
gotoxy(1,1);
- DisplaySendeString("Modus: DUO-Betrieb");
+ DisplaySendeString("Betrieb gestartet ");
gotoxy(1,3);
- DisplaySendeString("Betrieb gestartet");
+ DisplaySendeString("Filament einlegen ");
+ gotoxy(1,4);
+ DisplaySendeString(" Abbruch");
+
+ // Set_Cutter(200, 200, 2);
- //SpleisserMotorFWD();
+ motors[0]->run(StepperMotor::FWD, 100);
+ StatusDUO=DUO_FilamentIN;
+}
+
+void EntryDuoSchneiden1()
+{
+ Stepper_1_SetHome();
+
+ DisplaySendeBefehl(0x01);
+ gotoxy(1,1);
+ DisplaySendeString("Filament an Eingang");
+ gotoxy(1,3);
+ DisplaySendeString("Wird gefoerdert...");
+ gotoxy(1,4);
+ DisplaySendeString("Spleissen Abbruch");
- //Test pwm
- //ServoAusschuss(0.001, 0.5);
+ StatusDUO=DUO_Schneiden1;
+
+}
+void EntryDuoSchneiden2()
+{
+ Stepper_1_SetHome();
- StatusDUO=DUO_START;
+ DisplaySendeBefehl(0x01);
+ gotoxy(1,1);
+ DisplaySendeString("Spleissen");
+ gotoxy(1,3);
+ DisplaySendeString("");
+ gotoxy(1,4);
+ DisplaySendeString(" Abbruch");
+
+
+
+ Set_Spleisser(200, 200, 2);
+ Stepper_2_Move('V', 400);
+ printf("Spleissen\r\n");
+
+
+ StatusDUO=DUO_Schneiden2;
+
}
void EntryDUO()
{
+ ButtonSTART = get_Button_1();
+ ButtonABBRUCH = get_Button_2();
+
switch(StatusDUO)
{
case DUO_DEFAULT:
- printf("DUO_MODUS\r\n");
- // SpleisserMotorFWD();
-
+ //buttonAbbruch_diable_cb();
+ //buttonSTART_enabled_cb();
+ EntryDuoStart();
+ break;
- if(buttonSTART_pressed==true)
- {
- /*
- buttonSTART_pressed=false;
- buttonSTART_diable_cb();
- EntryDuoStart();
- */
+ case DUO_START:
+ if(ButtonSTART==true)
+ {
+
+ ButtonSTART=false;
+ // buttonSTART_diable_cb();
+ //buttonAbbruch_enabled_cb();
+ EntryDuoFilamentIN();
}
break;
- case DUO_START:
- printf("DUO_START\r\n");
+ case DUO_FilamentIN:
+ if(LS_1 == 0)
+ {
+ EntryDuoSchneiden1();
+ }
+
+ if(ButtonABBRUCH == true)
+ {
+ ButtonABBRUCH = false;
+ //buttonAbbruch_pressed=false;
+ //buttonAbbruch_diable_cb();
+ EntryDuoDefault();
+ }
+
+ break;
+
+ case DUO_Schneiden1:
+ if(ButtonABBRUCH == true)
+ {
+ ButtonABBRUCH = false;
+ //buttonAbbruch_pressed=false;
+ //buttonAbbruch_diable_cb();
+ EntryDuoDefault();
+ }
+ if(ButtonSTART == true)
+ {
+ ButtonSTART = false;
+ EntryDuoSchneiden2();
+
+ }
break;
- case DUO_FilamentIN:
- break;
-
- case DUO_Schneiden1:
- break;
-
case DUO_Schneiden2:
+ if(ButtonABBRUCH == true)
+ {
+ ButtonABBRUCH = false;
+ EntryDuoDefault();
+ }
break;
case DUO_Spleissen:
@@ -73,4 +191,3 @@
}
}
-
--- a/ST_SOLO.cpp Fri May 10 17:31:36 2019 +0000
+++ b/ST_SOLO.cpp Mon May 13 10:11:48 2019 +0000
@@ -67,11 +67,16 @@
int StatusSOLO=SOLO_DEFAULT;
extern PwmOut Servo;
-extern volatile bool buttonSTART_pressed;
+/*extern volatile bool buttonSTART_pressed;
extern volatile bool buttonSTART_enabled;
extern volatile bool buttonAbbruch_pressed;
-extern volatile bool buttonAbbruch_enabled;
+extern volatile bool buttonAbbruch_enabled;*/
+
+extern DigitalIn Button1;
+extern DigitalIn Button2;
+
+
extern DigitalIn LS_1;
extern DigitalIn LS_2;
@@ -96,6 +101,9 @@
int val_LS2 = 0;
int val_LS3 = 0;
+bool SOLOButtonSTART = false;
+bool SOLOButtonABBRUCH = false;
+
int count = 0;
@@ -103,8 +111,8 @@
void enable_Buttons()
{
- buttonSTART_enabled_cb();
- buttonAbbruch_enabled_cb();
+ // buttonSTART_enabled_cb();
+ //buttonAbbruch_enabled_cb();
}
void entry_SOLO_DEFAULT()
@@ -193,6 +201,9 @@
void EntrySOLO()
{
+
+ SOLOButtonSTART = get_Button_1();
+ SOLOButtonSTART = get_Button_2();
switch(StatusSOLO) {
case SOLO_DEFAULT:
@@ -213,17 +224,21 @@
DisplaySendeString("Start PLA");
}
- if(buttonAbbruch_pressed == true) {
- buttonAbbruch_pressed = false;
- buttonAbbruch_diable_cb();
+ if(SOLOButtonSTART == true) {
+
+ SOLOButtonSTART = false;
+ //buttonAbbruch_pressed = false;
+ //buttonAbbruch_diable_cb();
material = !material;
}
- if(buttonSTART_pressed == true) {
- buttonSTART_pressed = false;
- buttonSTART_diable_cb();
+ if(SOLOButtonSTART == true) {
+
+ SOLOButtonSTART = false;
+ //buttonSTART_pressed = false;
+ //buttonSTART_diable_cb();
//entry_SOLO_EinlegenOUT();
entry_SOLO_EinlegenIN();
}
@@ -246,9 +261,10 @@
DisplaySendeString(" Abbruch");
- if(buttonAbbruch_pressed == true) {
- buttonAbbruch_pressed = false;
- buttonAbbruch_diable_cb();
+ if(SOLOButtonSTART == true) {
+ SOLOButtonSTART = false;
+ //buttonAbbruch_pressed = false;
+ //buttonAbbruch_diable_cb();
entry_SOLO_DEFAULT();
}
@@ -287,15 +303,17 @@
entry_SOLO_DEFAULT();
}
- if(buttonAbbruch_pressed == true) {
- buttonAbbruch_pressed = false;
- buttonAbbruch_diable_cb();
+ if(SOLOButtonSTART == true) {
+ SOLOButtonSTART = false;
+ //buttonAbbruch_pressed = false;
+ //buttonAbbruch_diable_cb();
entry_SOLO_DEFAULT();
}
- if(buttonSTART_pressed == true) {
- buttonSTART_pressed = false;
- buttonSTART_diable_cb();
+ if(SOLOButtonSTART == true) {
+ SOLOButtonSTART = false;
+ //buttonSTART_pressed = false;
+ //buttonSTART_diable_cb();
entry_SOLO_EinlegenOUT();
}
@@ -310,9 +328,10 @@
gotoxy(1, 4);
DisplaySendeString(" Abbruch");
- if(buttonAbbruch_pressed == true) {
- buttonAbbruch_pressed = false;
- buttonAbbruch_diable_cb();
+ if(SOLOButtonSTART == true) {
+ SOLOButtonSTART = false;
+ //buttonAbbruch_pressed = false;
+ //buttonAbbruch_diable_cb();
entry_SOLO_DEFAULT();
}
@@ -346,15 +365,17 @@
entry_SOLO_DEFAULT();
}
- if(buttonAbbruch_pressed == true) {
- buttonAbbruch_pressed = false;
- buttonAbbruch_diable_cb();
+ if(SOLOButtonSTART == true) {
+ SOLOButtonSTART = false;
+ //buttonAbbruch_pressed = false;
+ //buttonAbbruch_diable_cb();
entry_SOLO_DEFAULT();
}
- if(buttonSTART_pressed == true) {
- buttonSTART_pressed = false;
- buttonSTART_diable_cb();
+ if(SOLOButtonSTART == true) {
+ SOLOButtonSTART = false;
+ // buttonSTART_pressed = false;
+ // buttonSTART_diable_cb();
entry_SOLO_Spleissen();
}
break;
--- a/main.cpp Fri May 10 17:31:36 2019 +0000 +++ b/main.cpp Mon May 13 10:11:48 2019 +0000 @@ -19,14 +19,14 @@ /*Buttons initialisieren*/ -InterruptIn buttonSTART(START_BUTTON); -//DigitaIn Button1(START_BUTTON); +//InterruptIn buttonSTART(START_BUTTON); +DigitalIn Button1(START_BUTTON); volatile bool buttonSTART_pressed = false; // Used in the main loop volatile bool buttonSTART_enabled = true; // Used for debouncing Timeout buttonSTART_timeout; // Used for debouncing -InterruptIn buttonAbbruch(ABBRUCH_BUTTON); -//DigitaIn Button2(ABBRUCH_BUTTON); +//InterruptIn buttonAbbruch(ABBRUCH_BUTTON); +DigitalIn Button2(ABBRUCH_BUTTON); volatile bool buttonAbbruch_pressed = false; // Used in the main loop volatile bool buttonAbbruch_enabled = true; // Used for debouncing Timeout buttonAbbruch_timeout; // Used for debouncing @@ -136,10 +136,10 @@ motors2 = x_nucleo_ihm02a1_2->get_components(); motors = x_nucleo_ihm02a1_1->get_components(); -/* Attach ISR to handle button press event */ +/* Attach ISR to handle button press event buttonSTART.fall(callback(buttonSTART_onpressed_cb)); buttonAbbruch.fall(callback(buttonAbbruch_onpressed_cb)); - +*/ /* Init PWM */ Init_Servo(); Init_Cutter();
PES_4_Spleisser