Last active
April 7, 2016 22:32
-
-
Save cutalion/051882348d5645bb5dd2611aa29f9672 to your computer and use it in GitHub Desktop.
Arduino formatter for rspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--color | |
--require spec_helper | |
--format Fuubar | |
--format ArduinoFormatter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArduinoFormatter | |
# This registers the notifications this formatter supports, and tells | |
# us that this was written against the RSpec 3.x formatter API. | |
RSpec::Core::Formatters.register self, :start, :dump_failures | |
def initialize(*args) | |
system 'stty -F /dev/ttyACM0 9600 cs8' | |
@tty = File.open('/dev/ttyACM0', 'w') | |
# sleep(2) # if auto-reset is turned ON on the Arduino is on | |
end | |
def start(_) | |
@tty.putc('y') | |
end | |
def dump_failures(notification) | |
if notification.failure_notifications.empty? | |
@tty.putc('g') | |
else | |
@tty.putc('r') | |
end | |
@tty.close | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define RED 10 | |
#define YELLOW 11 | |
#define GREEN 12 | |
int incomingByte = 0; | |
int leds[3] = { RED, YELLOW, GREEN }; | |
int leds_count = 3; | |
void setup() { | |
for(int i = 0; i < 3; i++) { | |
pinMode(leds[i], OUTPUT); | |
} | |
Serial.begin(9600); | |
} | |
void loop() { | |
} | |
void serialEvent() { | |
incomingByte = Serial.read(); | |
switch(incomingByte) { | |
case 103: // g, green | |
turnOn(GREEN); | |
break; | |
case 121: // y, yellow | |
turnOn(YELLOW); | |
break; | |
case 114: // r, red | |
turnOn(RED); | |
break; | |
} | |
} | |
void turnOn(int pin) { | |
for(int i = 0; i < 3; i++) { | |
digitalWrite(leds[i], pin == leds[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment