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.
Diff: main.cpp
- Revision:
- 22:000890b38b32
- Parent:
- 21:c6c33381fc5f
- Child:
- 23:d64d37561b4a
--- a/main.cpp Wed May 09 14:08:56 2018 +0000
+++ b/main.cpp Mon May 14 04:04:56 2018 +0000
@@ -1,7 +1,12 @@
// LIBs ------------------------------------------------------------------------------------
#include "mbed.h"
+#include "string"
// MACHINE SETUP ---------------------------------------------------------------------------
+#define tx PC_10
+#define rx PC_11
+
+Serial ihm(tx, rx); //tx e rx (D1 e D0)
// drivers output signal
DigitalOut enable(D2);
@@ -28,7 +33,6 @@
DigitalIn zUp(D15);
DigitalIn zDwn(D14);
-InterruptIn saveBtn(A5);
InterruptIn startBtn(D12);
// switch to alternate between JOG and routine
@@ -101,8 +105,9 @@
int saved = 0;
const int maxPoints = 10;
-float points[3][maxPoints];
-int pontos_restantes = 0;
+float points[3][maxPoints]; // [0] X; [1] Y; [2] Z;
+float path[2][maxPoints]; // [0] speed; [1] mode;
+int resting_points = 0;
int startSaved = 0;
int autoReload = 0;
@@ -133,16 +138,22 @@
void printDistance(void);
+void rxCallback(void);
+
// MAIN PROGRAM ----------------------------------------------------------------------------------------------
+char buffer[8] = "Hello\r";
+
int main(){
printf("\nStarting...\r\n");
- modeStatus = botao;
+ enable = 0;
- enable = 0;
-
+ // interrupção serial
+ ihm.attach(&rxCallback, Serial::RxIrq);
+
// interrupções de fim de curso
+ /*
endX.fall(&endX_press);
endX.rise(&endX_release);
@@ -151,9 +162,8 @@
endZ.fall(&endZ_press);
endZ.rise(&endZ_release);
-
- saveBtn.rise(&savePoint);
- startBtn.rise(&startSavedPoints);
+
+ startBtn.rise(&startSavedPoints);*/
int contador = 0;
@@ -534,7 +544,7 @@
printf("X: %.2f Y: %.2f Z: %.2f\r\n", X, Y, Z);
}
-void savePoint(void){
+void savePoint(string speed, string mode){
if(!autoReload){
keepSavedPointsReload = 0;
exitSavedPointsLoop = 0;
@@ -549,13 +559,15 @@
points[0][saved] = X;
points[1][saved] = Y;
points[2][saved] = Z;
-
+ path[0][saved] = atof(speed.c_str());
+ path[1][saved] = atof(mode.c_str());
saved+=1;
}
// save code
printf("Saved --> X: %.2f Y: %.2f Z: %.2f\r\n", X, Y, Z);
- pontos_restantes = maxPoints-saved;
- printf("Pontos restantes: %d\n\n\r", pontos_restantes);
+ printf("Path --> Speed: %.2f Mode: %.2f\n\r", path[0][saved-1], path[1][saved-1]);
+ resting_points = maxPoints-saved;
+ printf("Pontos restantes: %d\n\n\r", resting_points);
}
else {
exitSavedPointsLoop = 1;
@@ -572,4 +584,58 @@
keepSavedPointsReload = 1;
exitSavedPointsLoop = 0;
}
+}
+
+void rxCallback(void){
+ int first_rec_c = 1;
+ char mode_c;
+ char recv;
+
+ //save
+ int save = 0;
+ int mode = 0;
+ int speed = 0;
+ string mode_recv;
+ string speed_str;
+
+ printf("Receiving...\n\r");
+
+ while(1){
+ recv = ihm.getc();
+
+ if(first_rec_c && recv != 'x'){
+ mode_c = recv;
+ first_rec_c = 0;
+ } else if(recv == 'x'){
+ if(save){
+ printf("Saved: mode->%s, speed->%s\n\r", mode_recv, speed_str);
+ savePoint(speed_str, mode_recv);
+ }
+ break;
+ }
+
+ if(recv == 's'){
+ save = 1;
+ }
+
+ if(save){
+ if(recv == 'M'){
+ mode = 1;
+ speed = 0;
+ } else if(recv == 'F'){
+ mode = 0;
+ speed = 1;
+ }
+
+ if(mode){
+ if(recv != 'M'){
+ mode_recv.push_back(recv);
+ }
+ } else if(speed){
+ if(recv != 'F'){
+ speed_str.push_back(recv);
+ }
+ }
+ }
+ }
}
\ No newline at end of file