@@ -40,7 +40,46 @@ DigitalOut led_time_2(PA_10);
40
40
DigitalOut motor (PB_3);
41
41
42
42
// instancio uart driver
43
- UnbufferedSerial serial_port (USBTX, USBRX);
43
+ UnbufferedSerial serial_port (USBTX, USBRX); // seria ideal limitar el scope a una biblioteca de manejo serial
44
+
45
+
46
+ // to do: pasar un puntero a una estructura que contenga todo el estado del aparato para poder monitorear y modificar mas libremente
47
+ bool manage_serial (uint8_t vel, uint8_t tim){
48
+ bool ret = false ;
49
+ // atiendo comandos seriales:
50
+ char received = 0 ; // '\0'
51
+ if ( serial_port.readable () ){
52
+ serial_port.read ( &received, 1 );
53
+ switch (received){
54
+ // ---------------------------------------------------------------
55
+ case ' A' :
56
+ serial_port.write ( " Starting stirer\r\n " , 17 );// estaria bueno una funcion que le pases el const char* y cuente solo los caracteres.
57
+ ret=true ;
58
+ break ;
59
+ // ---------------------------------------------------------------
60
+ case ' S' :
61
+ char str[30 ];
62
+ sprintf (str," La velocidad seteada es: %d\n " , vel);
63
+ serial_port.write ( str, strlen (str) );
64
+
65
+ sprintf (str," el tiempo seteado es: %d\n " , tim);
66
+ serial_port.write ( str, strlen (str) );
67
+
68
+ // queda por implementar medicion de temperatura, pero no deja de ser solo otro A/D
69
+ // sprintf(str,"La temperatura actual es %d\n", speed);
70
+ // serial.write( str, strlen(str) );
71
+ break ;
72
+ // ---------------------------------------------------------------
73
+ default :
74
+ // availableCommands();
75
+ break ;
76
+ // ---------------------------------------------------------------
77
+ }
78
+
79
+ }
80
+ return ret;
81
+ }
82
+
44
83
45
84
int main (void )
46
85
{
@@ -82,14 +121,16 @@ int main(void)
82
121
83
122
thread_sleep_for (1 ); // uso de base de tiempo falopa, tambien me cambia frecuencia de pwm, polemiquisimo.
84
123
85
- // atiendo comandos seriales:
86
- if (serial_port.readable ( ){
87
124
88
-
125
+ if ( manage_serial (speed, set_time) == true ){
126
+ working=true ;
89
127
}
90
128
129
+
130
+
131
+
91
132
// leo la velocidad seteada
92
- speed = speed_input * 255 ; // escalo a 0 a 255 para el pwm casero
133
+ speed = speed_input * 99 ; // escalo a 0 a 255 para el pwm casero
93
134
94
135
// espero a que se aprete boton de start para arrancar
95
136
if (start_button == 0 ){
@@ -115,7 +156,7 @@ int main(void)
115
156
116
157
// hago control de velocidad, bastante precario, sin control de frecuencia, fase, ni nada de nada, de casualidad cambia el ancho de pulso
117
158
static uint8_t pwm_cnt=0 ;
118
- pwm_cnt = pwm_cnt < 255 ? pwm_cnt+1 : 0 ; // esto podria ser simplemente "pwm_cnt++" pero para asegurarse de que pegue la vuelta...
159
+ pwm_cnt = pwm_cnt < 99 ? pwm_cnt+1 : 0 ;
119
160
120
161
motor = pwm_cnt < speed ? 0 : 1 ; // pwm :s
121
162
}else {
0 commit comments