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:
- 0:cc4ffe9bb764
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Mar 13 22:47:00 2018 +0000
@@ -0,0 +1,152 @@
+#include "mbed.h"
+#include "draw.h"
+
+#define CM_EJECUTAR 0xff // FF COMO EJECUTAR
+#define CM_GUARDAR 0xfe // FE COMO GUARDAR
+#define CM_VERTEX2D 0xfd // FD COMO VERTEX
+#define CM_DRAW 0xfc // FC COMO DIBUJO
+#define CM_NODRAW 0xfb // FB COMO NO DIBUJO
+#define CM_STOP 0xfa // FA COMO PARADA
+#define CM_END 0xf0 // F0 COMO FINALIZAR LINEA
+
+#define MEM_SIZE 10
+#define MEM_TYPE uint32_t
+
+
+int mem_head = 0;
+int mem_tail = 0;
+uint8_t full = 0;
+
+Serial command(USBTX, USBRX); // configurar comando serial
+MEM_TYPE buffer[MEM_SIZE];
+
+
+void ejecutar(){ // subprograma ejecutar
+ command.printf("se esta ejecutando el dibujo...");
+ uint32_t mem_free();
+
+ while (command.getc() != CM_END)
+ {
+ void initdraw(); // posicion inicio de dibujo
+ void memory(); //revisar memoria
+ void dinamic (); //memoria dinamica
+ uint8_t mem_get (); //leer
+
+ switch (command.getc())
+ {
+ case CM_VERTEX2D:
+
+ for (int i=0; i<4; i++){
+ void vertex2d(uint8_t x, uint8_t y);
+ }
+ break;
+ case CM_DRAW:
+ void draw ();
+ break;
+ case CM_NODRAW:
+ void nodraw ();
+ break;
+ default:
+ command.printf("error de comando");
+ break ;
+ }
+ }
+ }
+
+
+void guardar(){ // subprograma guardar
+ command.printf("se inicia el comando de guardar..");
+ uint32_t mem_free();
+ while (command.getc() != CM_END)
+ {
+ void initdraw(); //posicion incial de dibujo
+ void memory();
+ void dinamic ();
+ uint8_t mem_put(); //escribir
+
+ }
+ }
+
+void parada (){ //subprograma de parada
+ command.printf("finalizando programa..");
+ uint32_t mem_free();
+ void nodraw();
+ void home();
+ }
+
+
+void init_serial()
+{
+ command.baud(9600); //configuracion velocidad de transmision
+}
+
+int main() { // programa para reconocer efecutar o guardar
+ init_servo();
+ init_serial();
+ home();
+ char read_cc;
+ while(1)
+ {
+ switch (read_cc) {
+ case CM_EJECUTAR: ejecutar(); break;
+ case CM_GUARDAR: guardar(); break;
+ case CM_STOP: parada (); break;
+ default: command.printf("error de comando");break ;
+ }
+ }
+}
+
+uint32_t mem_free() //memoria libre
+{
+ mem_head=0;
+ full=0;
+}
+
+uint8_t mem_put(MEM_TYPE data) //Escribir en espacio de memoria
+{
+
+ if (full)
+ return 1;
+ buffer[mem_head] = data;
+ mem_head += 1;
+ if (mem_head == MEM_SIZE)
+ full =1;
+ return 0;
+}
+
+uint8_t mem_get(MEM_TYPE* data) // Leer espacio de memoria
+{
+ if (mem_head == 0)
+ return 1;
+ if (mem_head == mem_tail)
+ return 1;
+
+
+ *data = buffer[mem_tail];
+ mem_tail += 1;
+
+ return 0;
+}
+
+
+void dinamic () // memoria dinamica de 32 bits
+ {
+ int temp = command.getc();
+
+ temp = temp<<8 + command.getc();
+ temp = temp<<8 + command.getc();
+ temp = temp<<8 + command.getc();
+ temp = temp<<8 + command.getc();
+ }
+
+void memory () // memoria para obtener el dato
+ {
+ mem_put(command.getc());
+ mem_put(command.getc());
+ mem_put(command.getc());
+ mem_put(command.getc());
+ MEM_TYPE val;
+ mem_get(&val);
+ command.putc(val);
+ }
+