Skip to content

Commit 50303e5

Browse files
committed
Fix in arduino firmware
* Fixed a bug that was setting in zero the analog read & write resolution * Fixed a bug that was writing garbage in the digital and analog outputs Issue #53
1 parent 93c101d commit 50303e5

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

MLC/arduino/Firmware/GenericArduinoController.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "Arduino.h"
22
#include "GenericArduinoController.h"
33

4+
#define DEBUG 0
5+
46
#ifndef DEBUG
57
#define DEBUG 0
68
#endif
@@ -81,7 +83,7 @@ void GenericArduinoController::handle_commands()
8183
{
8284
b_read += stream_.readBytes(&input[b_read], data_len + 5 - b_read);
8385

84-
LOG("Received command part: ", data_len + 5 - b_read);
86+
LOG("Data remaining: ", data_len + 5 - b_read);
8587
}
8688

8789
executor[input[0]](this, data_len, &input[0]); // Does the callback for the command
@@ -110,7 +112,8 @@ int GenericArduinoController::protocol_version(GenericArduinoController* this_,
110112
{
111113
char response[] = { char(VERSION_RESPONSE), char(0), char(0), char(0), char(0x03)};
112114
this_->stream_.write(response, 5);
113-
this_->stream_.write(VERSION, 3);
115+
this_->stream_.write(VERSION, sizeof(VERSION));
116+
LOG("Arduino Protocol Version ", VERSION);
114117
return 8;
115118
}
116119

@@ -129,7 +132,7 @@ int GenericArduinoController::analog_write(GenericArduinoController* this_, uint
129132
*/
130133
int GenericArduinoController::set_analog_precision(GenericArduinoController* this_, uint32_t &buff_len, const char* data)
131134
{
132-
int i = byte(data[6]);
135+
int i = byte(data[5]);
133136
// Tal vez conviene separar estas funciones ya que hay boards con resoluciones distintas...
134137
// Igual, así funciona bien con el due (y con todos, ya que no hay problema en superar el máximo de la resolución)
135138
analogWriteResolution(i);
@@ -160,7 +163,7 @@ int GenericArduinoController::set_report_mode(GenericArduinoController* this_, u
160163
this_->REPORT_MODE = (ReportModes)(data[5]);
161164
this_->REPORT_READ_COUNT = byte(data[6]);
162165
this_->REPORT_READ_DELAY = byte(data[7]);
163-
LOG("Report mode changed", "")
166+
LOG("Report mode changed", "");
164167
LOG("Report mode: ", this_->REPORT_MODE);
165168
LOG("New Read count: ", this_->REPORT_READ_COUNT);
166169
LOG("New Read delay: ", this_->REPORT_READ_DELAY);
@@ -215,7 +218,7 @@ int GenericArduinoController::reset(GenericArduinoController* this_, uint32_t &b
215218
int GenericArduinoController::set_analog_output(GenericArduinoController* this_, uint32_t &buff_len, const char* data)
216219
{
217220
// No se si vale la pena guardar registro de pines de salida...
218-
221+
LOG("Added as output the pin", data[5]);
219222
return 6; // Command of 3 bytes
220223
}
221224

@@ -235,19 +238,19 @@ int GenericArduinoController::actuate(GenericArduinoController* this_, uint32_t
235238
while (offset < buff_len)
236239
{
237240
//Se aplica la acción a cada puerto indicado
238-
int port = byte(data[2 + offset]);
241+
int port = byte(data[5 + offset]);
239242

240243
//Detects an analog port
241244
if ( port >= A0 )
242245
{
243-
int value = (data[3 + offset] << 8) + data[4 + offset];
246+
int value = (data[6 + offset] << 8) + data[7 + offset];
244247
analogWrite(port, value);
245248
offset += 3;
246249

247250
LOG("Analog pin written", port);
248251
} else
249252
{
250-
int value = data[3 + offset] > 0 ? HIGH : LOW; // Creo que da igual si pongo el entero directamente
253+
int value = data[6 + offset] > 0 ? HIGH : LOW; // Creo que da igual si pongo el entero directamente
251254
digitalWrite(port, value);
252255
offset += 2;
253256

MLC/arduino/connection/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ConnectionException(Exception):
2424

2525
class ConnectionTimeoutException(ConnectionException):
2626
def __init__(self, what):
27-
ConnectionException.__init__("Connection timeout: %s" % (what))
27+
ConnectionException.__init__(self, "Connection timeout: %s" % (what))
2828

2929
class BaseConnection:
3030
'''

0 commit comments

Comments
 (0)