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: mbed BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
main.cpp
- Committer:
- DiegoColl
- Date:
- 2017-06-08
- Revision:
- 1:6e255a933812
- Parent:
- 0:9cac1b16cf93
- Child:
- 2:997b65c65e65
File content as of revision 1:6e255a933812:
#include<string>
#include "mbed.h"
#include "TS_DISCO_F746NG.h"
#include "LCD_DISCO_F746NG.h"
//-------------------------------------------- definicion de uarts
//Serial pc(USBTX, USBRX); //activar para manejar las dos conexiones uart.(no olvidar ordenar los cambios)
Serial uart(USBTX, USBRX); //cambiar por el de abajo a la ahora de cargarlo en la placa, para testear con los modulos.
//Serial uart(PC_6, PC_7);
//-------------------------------------------- definicion de etiquetas
LCD_DISCO_F746NG lcd;
TS_DISCO_F746NG ts;
InterruptIn button(BUTTON1);
DigitalOut myled(LED1);
//-------------------------------------------- definicion de variables globales
string ID="C1",ST="OK",AC="",AK="";
//char IDs[]="",STs[]="",ACs[]="",AKs[]="";
char buffer[32]="";
char* aux[10];
//char* acc[4]={"CN","DT","OK","ER"};
int SP=1;
int OP=1;
int x=0;
int yx=72, yy=142, yz=212;
int gx=72, gy=142, gz=212;
int mx=72, my=142, mz=212;
//-------------------------------------------- definicion de funciones
void encabezado_lcd(){
//------------------------------ programa
lcd.Clear(LCD_COLOR_BLACK);
lcd.SetBackColor(LCD_COLOR_BLACK);
lcd.SetTextColor(LCD_COLOR_GREEN);
lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"PRAXIS", CENTER_MODE);
wait(3); // 3s
lcd.Clear(LCD_COLOR_BLACK);
};
void refrescar_lcd(){
//------------------------------ programa
lcd.SetTextColor(LCD_COLOR_GREEN);
lcd.DisplayStringAt(0, LINE(0), (uint8_t *)"PRAXIS", CENTER_MODE);
x++;
if(x==480){
x=0;
lcd.Clear(LCD_COLOR_BLACK);
}
lcd.DrawPixel(x, yx, LCD_COLOR_ORANGE);
lcd.DrawPixel(x, yy, LCD_COLOR_YELLOW);
lcd.DrawPixel(x, yz, LCD_COLOR_RED);
wait(0.01); // 10 ms
};
void blinkled(){
myled = 1; // LED is ON
wait(0.2); // 200 ms
myled = 0; // LED is OFF
wait(0.2); // 200 ms
};
void speed(){
//------------ variables locales
//------------ programa
uart.printf("<%s;%s;S%i;2F>",ID,ST,SP);
SP++;
if(SP==4){
SP=1;
}
};
void borrar_buffer(char *cadena){
//------------ variables locales
int i=0;
//------------ programa
for(i=0;i<31;i++){
cadena[i]=0x00;
}
};
void interrup(){
//------------ variables locales
char chksm=0;
char c;
int i=0;
//------------ programa
c=uart.getc();
if(c=='<'){
while(c!='>'){
c=uart.getc();
if(c!='>'){
buffer[i++]=c; //------------ carga buffer
}
}
for(i=0;i<strlen(buffer)-2;i++){ //------------ calculo checksum
chksm ^= buffer[i];
}
//uart.printf("%x",chksm);
i=0;
aux[i]=strtok(buffer,";"); //------------ separa la cadena
do{
i++;
aux[i]=strtok(NULL, ";");
}while(aux[i]!=NULL);
//if(strcmp(aux[??],chksm) == 0){ //------------ comparar checksum (FALTA)
// uart.printf("checksum igual");
// }
if(strcmp(aux[2],"CN") == 0){ //------------ toma de decision
uart.printf("<%s;%s;YE;51>",ID,ST);
}
if(strcmp(aux[2],"D1") == 0){
yx= 120 - *aux[3];
yy= 190 - *aux[4];
yz= 260 - *aux[5];
//uart.putc(yx);
//uart.putc(yy);
//uart.putc(yz);
//uart.printf("<%s;%s;DT;2F>",ID,ST);
}
if(strcmp(aux[2],"D2") == 0){
gx=*aux[3];
gy=*aux[4];
gz=*aux[5];
//uart.printf("<%s;%s;DT;2F>",ID,ST);
}
if(strcmp(aux[2],"D3") == 0){
mx=*aux[3];
my=*aux[4];
mz=*aux[5];
//uart.printf("<%s;%s;DT;2F>",ID,ST);
}
}
borrar_buffer(buffer);
};
//codigo principal
int main() {
//pc.printf("Inicio de programa\n"); //cambiar uart de destino al final
uart.printf("Inicio de programa\n");
encabezado_lcd();
//------------------------------ Interrupciones
button.rise(&speed);
uart.attach(&interrup);
//------------------------------ programa
while(1) {
refrescar_lcd();
//blinkled();
}
}