Browse files

Allow setting the serial dev as an env var

  • Loading branch information...
1 parent 367f9a7 commit 28d84d3b9cf2fb4190ce94b9602d2981dea3371b @msantos committed Mar 31, 2012
Showing with 18 additions and 4 deletions.
  1. +15 −2 src/stk500.erl
  2. +3 −2 test/stk500_tests.erl
View
17 src/stk500.erl
@@ -44,7 +44,9 @@
hex_file/1, hex_file/2,
chunk/2,
load/2, load/3,
- cmd/2, cmd/3
+ cmd/2, cmd/3,
+
+ serial_device/0
]).
-define(DEV, "/dev/ttyUSB0").
@@ -59,7 +61,8 @@
open() ->
- open(?DEV, [{speed, b19200}]).
+ Dev = serial_device(),
+ open(Dev, [{speed, b19200}]).
open(Dev) ->
open(Dev, [{speed, b19200}]).
@@ -244,6 +247,16 @@ chunk(Bytes, Size, Acc) when Size > 0, Size rem 2 == 0, Size =< 256 ->
end.
+% Try to discover the serial device
+serial_device() ->
+ case os:getenv("STK500_SERIAL_PORT") of
+ false ->
+ ?DEV;
+ Serial ->
+ Serial
+ end.
+
+
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
View
5 test/stk500_tests.erl
@@ -34,12 +34,13 @@
-include_lib("eunit/include/eunit.hrl").
--define(SERIAL_PORT, "/dev/ttyUSB0").
-define(HEX_FILE, "doc/counter.cpp.hex").
+
%% Upload code to an Arduino.
stk500_program_load_test() ->
- {ok,FD} = stk500:open(?SERIAL_PORT),
+ Serial = stk500:serial_device(),
+ {ok,FD} = stk500:open(Serial),
error_logger:info_report([{hex_file, codepath(?HEX_FILE)}]),
Hex = stk500:hex_file(codepath(?HEX_FILE)),
Bytes = stk500:chunk(Hex, 128),

0 comments on commit 28d84d3

Please sign in to comment.