digiusb 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/digiterm +51 -13
  2. metadata +2 -2
@@ -4,18 +4,50 @@ require 'digiusb'
4
4
  require 'colored'
5
5
  require 'io/console'
6
6
 
7
- puts "Looking for Digispark running DigiUSB...".blue
7
+ if ARGV.include? '--help' or ARGV.include? '-h'
8
+ puts "Usage:"
9
+ puts " digiterm [options]"
10
+ puts " digiterm [options] [device name]"
11
+ puts
12
+ puts " Options:"
13
+ puts " --raw Disable ansi colouring and other friendly decorations."
14
+ puts " Useful for using as subprocess from another programming language."
15
+ puts " --no-wait Don't loop and wait for a digispark - return immediately if no"
16
+ puts " device is found."
17
+ puts " --no-info Don't write out any status information to standard error output"
18
+ exit
19
+ end
8
20
 
9
- sleep 0.5 until DigiUSB.sparks.length > 0
10
- spark = DigiUSB.sparks.last
21
+ raw_mode = ARGV.include?("--raw")
22
+ device_name = if ARGV.empty? or ARGV.last.start_with?("--")
23
+ false
24
+ else
25
+ ARGV.last
26
+ end
27
+ no_stderr = ARGV.include?("--no-info")
11
28
 
12
- puts "Attached to #{spark.inspect.green}".blue
13
- puts "Type control + c to exit".blue
29
+
30
+ $stderr.puts "Looking for Digispark running DigiUSB...".blue unless no_stderr
31
+
32
+ sleep 0.5 until DigiUSB.sparks(device_name).length > 0 unless ARGV.include? '--no-wait'
33
+ spark = DigiUSB.sparks(device_name).last
34
+
35
+ unless spark
36
+ $stderr.puts "No device found".white_on_red unless no_stderr
37
+ exit 1
38
+ end
39
+
40
+ $stderr.puts "Attached to #{spark.inspect.green}".blue unless no_stderr
41
+ $stderr.puts "Type control + c to exit".blue unless no_stderr
14
42
  begin
15
43
  loop do
16
44
  char = spark.getc
17
45
  if char != ""
18
- print char.green
46
+ if raw_mode
47
+ print char
48
+ else
49
+ print char.green
50
+ end
19
51
  else
20
52
  sleep 1.0 / 30.0
21
53
  end
@@ -27,12 +59,18 @@ begin
27
59
  end
28
60
  end
29
61
  rescue LIBUSB::ERROR_PIPE, LIBUSB::ERROR_NO_DEVICE
30
- puts "" # newline
31
- puts "Digispark disconnected".white_on_red
62
+ unless no_stderr
63
+ $stderr.puts "" # newline
64
+ $stderr.puts "Digispark disconnected".white_on_red unless no_stderr
65
+ end
66
+ exit 2
32
67
  rescue DigiUSB::ErrorCrashed
33
- puts "" # newline
34
- puts "Digispark has crashed".white_on_red
35
- puts " >> Probably need to call DigiUSB.refresh() more frequently in Digispark Program".blue
68
+ unless no_stderr
69
+ $stderr.puts "" # newline
70
+ $stderr.puts "Digispark has crashed".white_on_red
71
+ $stderr.puts " >> Probably need to call DigiUSB.refresh() more frequently in Digispark Program".blue
72
+ end
73
+ exit 3
36
74
  rescue Interrupt
37
- puts ""
38
- end
75
+ $stderr.puts "" unless no_stderr
76
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digiusb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: libusb