Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
769803f
updated readme to add new Firmata client libraries
soundanalogous Nov 18, 2013
ecc1b87
remove duplicate word
nicolaspanel Feb 10, 2014
d8f9a75
add interrupt pins, see http://arduino.cc/en/Reference/attachInterrup…
nicolaspanel Feb 10, 2014
58c0518
create EncoderFirmata header file
nicolaspanel Feb 10, 2014
a40eb12
add private method to report all encoders positions
nicolaspanel Feb 10, 2014
3bcec4a
improve documentation
nicolaspanel Feb 10, 2014
3dc34c1
fix syntax issues
nicolaspanel Feb 10, 2014
ccfe8af
add EncoderFirmata implementation file
nicolaspanel Feb 10, 2014
084b667
implement EncoderFirmata
nicolaspanel Feb 10, 2014
b2b5f62
update IS_PIN_INTERRPUT macros, according to http://www.pjrc.com/teen…
nicolaspanel Feb 10, 2014
3a6aacf
update ConfigurableFirmata to manage Encoders
nicolaspanel Feb 10, 2014
c1fe131
rename encoder utilities folder
nicolaspanel Feb 10, 2014
5ce5007
fix synthax errors and and encoder unit tests
Feb 10, 2014
b27db4c
fix remaining bugs and improve testing coverage
Feb 10, 2014
e3977a1
move function to public to improve tests
nicolaspanel Feb 11, 2014
09f240f
improve tests and check for memory leaks
nicolaspanel Feb 11, 2014
bc5e578
add example.ion file for encoders, including protocol proposal
nicolaspanel Feb 11, 2014
5361118
improve documentation
nicolaspanel Feb 11, 2014
4b7b718
Merge branch 'encoders'
nicolaspanel Feb 11, 2014
8a803dc
improve testing and documentation
Feb 11, 2014
113cbd0
add reference to wire and servo to avoid compilation issue
Feb 11, 2014
72aec53
ConfigurableFirmata.ino compiling. Size : 30kbytes
Feb 11, 2014
26e95e3
Automatic reporting report one encoder at the time (best performences)
nicolaspanel Feb 14, 2014
0b2e630
fix naming issue
nicolaspanel Feb 14, 2014
6861d19
improve full report test
nicolaspanel Feb 14, 2014
be9f18e
Merge branch 'develop'
nicolaspanel Feb 14, 2014
dc237a2
there is discussion on the Arduino dev list about resolving this prob…
nicolaspanel Feb 14, 2014
3d7d8b9
Errors and warnings are commented to avoid out-of-sram error.
nicolaspanel Feb 14, 2014
12624a1
AVR gcc doen't implement a true C++ delete so use free instead
nicolaspanel Feb 14, 2014
415a002
Manage ENCODER pin mode
nicolaspanel Feb 14, 2014
4a29597
determine how much memory each instance
nicolaspanel Feb 14, 2014
fdffde9
rename test
nicolaspanel Feb 14, 2014
35aad7d
fix
nicolaspanel Feb 14, 2014
c8dfb81
update tests
nicolaspanel Feb 14, 2014
7e42f61
tests improvement
nicolaspanel Feb 14, 2014
8fa3f0f
change ENCODER to 11 (0x0B)
nicolaspanel Feb 14, 2014
e63bc82
update total pin modes number
nicolaspanel Feb 15, 2014
d1e7eb5
Use sysex responses instead of MIDI
nicolaspanel Feb 16, 2014
f643b34
fix remaining bugs
nicolaspanel Feb 16, 2014
9037100
Report positions only when at least 1 encoder is attached
nicolaspanel Feb 16, 2014
6730517
fix remaining bugs
nicolaspanel Feb 16, 2014
9a7d6ff
fix remaining bugs
nicolaspanel Feb 16, 2014
ff0a55f
Report encoder position after initialization (Firmata convention, eve…
nicolaspanel Feb 16, 2014
47fc4e6
Move ENCODER_DATA instruction to Firmata.h
nicolaspanel Feb 17, 2014
de3052d
use FakeStream#reset instead of FakeStream#flush to cleanup the stream
Feb 17, 2014
cd1f295
Merge pull request #119 from nicolaspanel/master
ntruchsess Feb 20, 2014
8d5f462
implement reporting for changed positions only
ntruchsess Feb 28, 2014
3d7ec6c
memory optimize reportPositions(), adjust test_encoder.ino to match n…
ntruchsess Feb 28, 2014
355bdf1
Merge pull request #120 from ntruchsess/encoder_report_changedonly
ntruchsess Feb 28, 2014
de0d009
remove makefiles from examples
soundanalogous Mar 9, 2014
07c2fa9
added intel galileo to boards.h
soundanalogous Mar 9, 2014
7a67148
update library properties for new IDE 1.5.6 format
soundanalogous Mar 9, 2014
4d746e8
update version in headers and build script
soundanalogous Mar 9, 2014
2a94af8
update readme
soundanalogous Mar 9, 2014
988d3c2
copy over changes from these commits: 27f7e4276974a6a5c74008490f23ba5…
soundanalogous Mar 9, 2014
572f4b3
remove arduino 1.5.x specific build because original build works for …
soundanalogous Mar 9, 2014
2b6bc1e
add back line to delete temp directory
soundanalogous Mar 9, 2014
b524dfc
missing equal sign in comparison
soundanalogous Mar 9, 2014
9cb7d4f
formatting change
soundanalogous Mar 9, 2014
ef50e73
saving a few bytes
soundanalogous Mar 9, 2014
2764059
Merge pull request #122 from firmata/merge-in-dev
soundanalogous Mar 30, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix remaining bugs and improve testing coverage
  • Loading branch information
nicolaspanel committed Feb 10, 2014
commit b27db4c764dcaed0df544886f19daf4db696ed67
74 changes: 60 additions & 14 deletions test/encoder_test/encoder_test.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/*
* To run this test suite, you must first install the ArduinoUnit library
* to your Arduino/libraries/ directory.
* You can get ArduinoUnit here: https://github.com/mmurdoch/arduinounit
* Download version 2.0 or greater.
* To run this test suite, you must first install to your Arduino/libraries/ directory :
* the ArduinoUnit library to your Arduino/libraries/ directory.
* available here: https://github.com/mmurdoch/arduinounit (2.0 or greater.)
*/

#include <Wire.h>
#include <Servo.h>
#include <ArduinoUnit.h>
#include "Firmata.h"
#include "utility/EncoderFirmata.h"

// overide interrupt macro (for unit tests only)
#define IS_PIN_INTERRUPT(p) ((p) == 2 || (p) == 3 )
#define IS_PIN_INTERRUPT(p) ((p) == 2 || (p) == 3)


FakeStream stream;
Expand All @@ -29,15 +27,63 @@ void loop()
Test::run();
}

test(handleInterruptPins)
test(fullTest)
{
Serial.print(F("BT mem.: "));
Serial.println(freeMemory());

EncoderFirmata encoder;
assertTrue(encoder.handlePinMode(2, INPUT));
}

assertTrue(encoder.handlePinMode(2, INPUT)); // 2 is interrupt
assertFalse(encoder.handlePinMode(1, INPUT)); // 1 is NOT intterrupt

test(handleNonInterruptPinS)
{
EncoderFirmata encoder;
assertFalse(encoder.handlePinMode(4, INPUT));
}
byte encoderNum = 0, pin1 = 2, pin2 = 3;

byte attachEncoderMessage[] = { ENCODER_ATTACH, encoderNum, pin1, pin2 };
byte detachEncoderMessage[] = { ENCODER_DETACH, encoderNum };

assertFalse(encoder.isEncoderAttached(encoderNum));

assertTrue(encoder.handleSysex(ENCODER_DATA, 0, attachEncoderMessage));

assertTrue(encoder.isEncoderAttached(encoderNum));

assertTrue(encoder.handleSysex(ENCODER_DATA, 0, detachEncoderMessage));
assertFalse(encoder.isEncoderAttached(encoderNum));

encoder.handleSysex(ENCODER_DATA, 0, attachEncoderMessage);
assertTrue(encoder.isEncoderAttached(encoderNum));
//report encoder position
byte reportPosition[] = {ENCODER_REPORT_POSITION, encoderNum};
stream.flush();
assertTrue(encoder.handleSysex(ENCODER_DATA, 0, reportPosition));
assertEqual(stream.bytesWritten().length(), 6);

byte reportPositions[] = {ENCODER_REPORT_POSITIONS};
stream.flush();
assertTrue(encoder.handleSysex(ENCODER_DATA, 0, reportPositions));
assertEqual(stream.bytesWritten().length(), 9);


// check that auto-report is disable by default
assertFalse(encoder.autoReport);
stream.flush();
encoder.report();
assertTrue(stream.bytesWritten().length()==0);


// simulate logical reset
encoder.reset();
assertFalse(encoder.isEncoderAttached(encoderNum));

// Enable auto reports
byte enableReportsMessage[] = {ENCODER_REPORT_AUTO, 0x01};
assertTrue(encoder.handleSysex(ENCODER_DATA, 0, enableReportsMessage));
assertTrue(encoder.autoReport);
stream.flush();
encoder.report();
assertEqual(stream.bytesWritten().length(), 3); // i.e : no encoder attached, message is empty (expt sysex start/end and ENCODER_DATA message)

Serial.print(F("AT mem.: "));
Serial.println(freeMemory());
}
27 changes: 18 additions & 9 deletions utility/EncoderFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
/* Constructor */
EncoderFirmata::EncoderFirmata()
{
byte encoder;
for(encoder=0; encoder<MAX_ENCODERS; encoder++)
{
encoders[encoder]=NULL;
}
autoReport = false;
}
EncoderFirmata::~EncoderFirmata()
Expand Down Expand Up @@ -55,6 +60,7 @@ void EncoderFirmata::detachEncoder(byte encoderNum)
if (isEncoderAttached(encoderNum))
{
delete encoders[encoderNum];
encoders[encoderNum] = NULL;
}
}

Expand Down Expand Up @@ -124,39 +130,42 @@ boolean EncoderFirmata::handleSysex(byte command, byte argc, byte *argv)
attachEncoder(encoderNum, pinA, pinB);
return true;
}
else if (encoderCommand == ENCODER_REPORT_POSITION)


if (encoderCommand == ENCODER_REPORT_POSITION)
{
encoderNum = argv[1];
reportEncoder(encoderNum);
return true;
}
else if (encoderCommand == ENCODER_REPORT_POSITIONS)

if (encoderCommand == ENCODER_REPORT_POSITIONS)
{
reportEncodersPositions();
return true;
}
else if (encoderCommand == ENCODER_RESET_POSITION)

if (encoderCommand == ENCODER_RESET_POSITION)
{
encoderNum = argv[1];
resetEncoderPosition(encoderNum);
return true;
}
else if (encoderCommand == ENCODER_REPORT_AUTO)
if (encoderCommand == ENCODER_REPORT_AUTO)
{
enableReports = argv[1];
toggleAutoReport(enableReports == 0x00 ? false : true);
return true;
}
else if (encoderCommand == ENCODER_DETACH)

if (encoderCommand == ENCODER_DETACH)
{
encoderNum = argv[1];
detachEncoder(encoderNum);
return true;
}
else
{
Firmata.sendString("Encoder Error: Invalid command");
}

Firmata.sendString("Encoder Error: Invalid command");
}
return false;
}
Expand Down
22 changes: 11 additions & 11 deletions utility/EncoderFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
#include "Encoder.h"

#define MAX_ENCODERS 5 // arbitrary value, may need to adjust
#define ENCODER_ATTACH 0x00
#define ENCODER_REPORT_POSITION 0x01
#define ENCODER_REPORT_POSITIONS 0x02
#define ENCODER_RESET_POSITION 0x03
#define ENCODER_REPORT_AUTO 0x04
#define ENCODER_DETACH 0x05
#define ENCODER_DATA 0x61 // TODO : Move to Firmata.h
#define ENCODER_MESSAGE 0x80 // TODO : Move to Firmata.h
#define ENCODER_ATTACH (0x00)
#define ENCODER_REPORT_POSITION (0x01)
#define ENCODER_REPORT_POSITIONS (0x02)
#define ENCODER_RESET_POSITION (0x03)
#define ENCODER_REPORT_AUTO (0x04)
#define ENCODER_DETACH (0x05)
#define ENCODER_DATA (0x61) // TODO : Move to Firmata.h
#define ENCODER_MESSAGE (0x80) // TODO : Move to Firmata.h

class EncoderFirmata:public FirmataFeature
{
Expand All @@ -104,7 +104,8 @@ class EncoderFirmata:public FirmataFeature
boolean handleSysex(byte command, byte argc, byte *argv);
void reset();
void report();
boolean isEncoderAttached(byte encoderNum);
boolean isEncoderAttached(byte encoderNum);
volatile bool autoReport;

private:
void attachEncoder(byte encoderNum, byte pinANum, byte pinBNum);
Expand All @@ -113,8 +114,7 @@ class EncoderFirmata:public FirmataFeature
void reportEncodersPositions();
void resetEncoderPosition(byte encoderNum);
void toggleAutoReport(bool report);
Encoder *encoders[MAX_ENCODERS];
volatile bool autoReport;
Encoder *encoders[MAX_ENCODERS];
};

#endif