digiusb 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/digiusb.rb +55 -38
- data/license.txt +24 -106
- metadata +21 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52f78cacd459c373f90fbd41e043d12c8e0b5ff5
|
4
|
+
data.tar.gz: 70924c701448f285f2686e2f7b0890d2c9cc0f66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5c6473feea90654cd90bf178e04335a549e7c454e85c0647c75d26fee16ba34c7165bbf362a78822095d427ffb9948308a5af8c714c7e30e49081af5f1deac1a
|
7
|
+
data.tar.gz: 3e23962bbf56bfb09f8483532e812d452ed48561cde1990cf7bed6f3e2f1f2bea107f35452396404bf894628a71bd7920f4b933811a10fd5d29551609526ea1c
|
data/lib/digiusb.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
-
# The DigiUSB class helps find, connect to, and talk with Digisparks using the
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
1
|
+
# The DigiUSB class helps find, connect to, and talk with Digisparks using the
|
2
|
+
# DigiUSB arduino library bundled with the Digispark Arduino software. This
|
3
|
+
# class aims to work like an IO object, letting you read and write characters,
|
4
|
+
# bytes, and strings as if it were a file, socket, or serial port. To get
|
5
|
+
# started, grab a list of Digisparks with the DigiUSB.sparks method. Each spark
|
6
|
+
# has an inspect method with a unique identifier including the USB device name
|
7
|
+
# (usually DigiUSB), and some numbers representing which ports and hubs each
|
8
|
+
# spark connects to. To begin with, DigiUSB.sparks.last works well if you only
|
9
|
+
# intend to have one digispark connected to your computer. Eventually the device
|
10
|
+
# name (aka "product name") will hopefully provide a simple way to differentiate
|
11
|
+
# different digisparks.
|
7
12
|
#
|
8
|
-
# Once you have a reference to a Digispark, you can start using it as if it were
|
9
|
-
#
|
10
|
-
#
|
13
|
+
# Once you have a reference to a Digispark, you can start using it as if it were
|
14
|
+
# an IO object immediately with methods like getc and putc. As soon as you start
|
15
|
+
# interacting with the Digispark using these reading and writing methods the
|
16
|
+
# Digispark will be claimed to your ruby program and will be unavailable to
|
17
|
+
# other programs until you do one of: close the ruby program, or unplug and plug
|
18
|
+
# back in the Digispark.
|
11
19
|
#
|
12
|
-
# Note also that calling DigiUSB.sparks can sometimes disrupt program uploads,
|
13
|
-
#
|
20
|
+
# Note also that calling DigiUSB.sparks can sometimes disrupt program uploads,
|
21
|
+
# so if you're polling waiting for a digispark to appear you may see some
|
22
|
+
# programming errors in the Digispark Arduino software.
|
14
23
|
|
15
24
|
require 'libusb'
|
16
25
|
|
@@ -18,7 +27,7 @@ require 'libusb'
|
|
18
27
|
class DigiUSB
|
19
28
|
ProductID = 0x05df # product id number from Digistump
|
20
29
|
VendorID = 0x16c0 # vendor id number for Digistump
|
21
|
-
Timeout = 1_000 #
|
30
|
+
Timeout = 1_000 # spark needs to DigiUSB.refresh or DigiUSB.sleep every second
|
22
31
|
DefaultPollingFrequency = 15 # 15hz when waiting for data to be printed
|
23
32
|
|
24
33
|
# :nodoc: initialize a new DigiUSB object using a libusb device object
|
@@ -28,13 +37,15 @@ class DigiUSB
|
|
28
37
|
@polling_frequency = DefaultPollingFrequency
|
29
38
|
end
|
30
39
|
|
31
|
-
# polling frequency describes how aggressively ruby will ask for new bytes
|
32
|
-
# a lower value is faster (it
|
40
|
+
# polling frequency describes how aggressively ruby will ask for new bytes
|
41
|
+
# when waiting for the device to print something a lower value is faster (it
|
42
|
+
# is in hertz)
|
33
43
|
attr_accessor :polling_frequency
|
34
44
|
|
35
|
-
# Returns an array of all Digisparks connected to this computer. Optionally
|
36
|
-
#
|
37
|
-
# there
|
45
|
+
# Returns an array of all Digisparks connected to this computer. Optionally
|
46
|
+
# specify a device name string to return only Digisparks with that name. At
|
47
|
+
# the time of writing there is no easy way to customize the device name in
|
48
|
+
# the Digispark Arduino software, but hopefully there will be in the future.
|
38
49
|
def self.sparks product_name = false
|
39
50
|
usb = LIBUSB::Context.new
|
40
51
|
usb.devices.select { |device|
|
@@ -44,10 +55,16 @@ class DigiUSB
|
|
44
55
|
}
|
45
56
|
end
|
46
57
|
|
58
|
+
# Connect to a Digispark. Usually the most recently plugged in one.
|
59
|
+
def self.connect product_name = false
|
60
|
+
sparks(product_name).last
|
61
|
+
end
|
47
62
|
|
48
|
-
# Attempt to read a single character from the Digispark. Returns a string
|
49
|
-
#
|
50
|
-
#
|
63
|
+
# Attempt to read a single character from the Digispark. Returns a string
|
64
|
+
# either zero or one characters long. A zero character string means there are
|
65
|
+
# no characters available to read - the Digispark hasn't printed anything for
|
66
|
+
# you to consume yet. Returns next time Digispark calls DigiUSB.refresh()
|
67
|
+
# regardless of how many characters are available.
|
51
68
|
def getc
|
52
69
|
control_transfer(
|
53
70
|
bRequest: 0x01, # hid get report
|
@@ -55,10 +72,12 @@ class DigiUSB
|
|
55
72
|
)
|
56
73
|
end
|
57
74
|
|
58
|
-
# Send a single character in to the Digispark's memory. Argument may be either
|
75
|
+
# Send a single character in to the Digispark's memory. Argument may be either
|
76
|
+
# a single byte String, or an integer between 0 and 255 inclusive.
|
77
|
+
#
|
59
78
|
# Returns next time Digispark calls DigiUSB.refresh()
|
60
79
|
def putc character
|
61
|
-
character = [character % 256].pack('
|
80
|
+
character = [character % 256].pack('C') if character.is_a? Integer
|
62
81
|
raise "Cannot putc more than one byte" if character.bytesize > 1
|
63
82
|
raise "Cannot putc fewer than one byte" if character.bytesize < 1
|
64
83
|
|
@@ -68,14 +87,15 @@ class DigiUSB
|
|
68
87
|
)
|
69
88
|
end
|
70
89
|
|
71
|
-
# Read a string
|
72
|
-
#
|
90
|
+
# Read a string from the Digispark until a newline is received (eg, from the
|
91
|
+
# println function in Digispark's DigiUSB library) The returned string
|
92
|
+
# includes a newline character on the end.
|
73
93
|
def gets
|
74
94
|
chars = ""
|
75
95
|
until chars.include? "\n"
|
76
96
|
char = getc()
|
77
97
|
chars += char
|
78
|
-
sleep 1.0 /
|
98
|
+
sleep 1.0 / @polling_frequency if char == ""
|
79
99
|
end
|
80
100
|
return chars
|
81
101
|
end
|
@@ -100,22 +120,18 @@ class DigiUSB
|
|
100
120
|
alias_method :print, :write
|
101
121
|
alias_method :send, :write
|
102
122
|
|
103
|
-
# Recieve a specific number of bytes and return them as a String. Unlike #getc
|
104
|
-
# the specified number of bytes are available before
|
105
|
-
|
123
|
+
# Recieve a specific number of bytes and return them as a String. Unlike #getc
|
124
|
+
# read will wait until the specified number of bytes are available before
|
125
|
+
# returning. Optionally specify a timeout
|
126
|
+
def read bytes = 1, timeout = nil
|
127
|
+
start_time = Time.now.to_f
|
106
128
|
chars = ""
|
107
|
-
|
108
|
-
until chars.include? "\n"
|
109
|
-
char = getc()
|
110
|
-
chars += char
|
111
|
-
sleep 1.0 / PollingFrequency if char == ""
|
112
|
-
end
|
113
|
-
|
114
|
-
chars += getc() until chars.length == bytes
|
129
|
+
chars += getc() until chars.length >= bytes || (timeout && Time.now.to_f - start_time > timeout)
|
115
130
|
return chars
|
116
131
|
end
|
117
132
|
|
118
|
-
# A friendly textual representation of this specific Digispark. Can be called
|
133
|
+
# A friendly textual representation of this specific Digispark. Can be called
|
134
|
+
# without claiming the digispark for this program
|
119
135
|
def inspect
|
120
136
|
"<Digispark:#{name}:@#{address}>"
|
121
137
|
end
|
@@ -126,7 +142,8 @@ class DigiUSB
|
|
126
142
|
@device.product
|
127
143
|
end
|
128
144
|
|
129
|
-
# Returns the device's bus number and address on the computer's USB interface
|
145
|
+
# Returns the device's bus number and address on the computer's USB interface
|
146
|
+
# as a string
|
130
147
|
def address
|
131
148
|
"#{@device.bus_number}.#{@device.device_address}"
|
132
149
|
end
|
data/license.txt
CHANGED
@@ -1,106 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
lizzie borden took an axe, and gave her father forty whacks
|
27
|
-
then gave her mother forty-one, and left a tragic puzzle
|
28
|
-
if only they had given her an instrument, those puritans
|
29
|
-
had lost the plot completely
|
30
|
-
see what happens when you muzzle
|
31
|
-
a person’s creativity
|
32
|
-
and do not let them sing and scream
|
33
|
-
and nowadays it’s worse ‘cause kids have automatic handguns
|
34
|
-
it takes about an hour to learn how to play the ukulele
|
35
|
-
about same to teach someone to build a standard pipe bomb
|
36
|
-
YOU DO THE MATH
|
37
|
-
|
38
|
-
so play your favorite cover song, especially if the words are wrong
|
39
|
-
‘cos even if your grades are bad, it doesn’t mean you’re failing
|
40
|
-
do your homework with a fork
|
41
|
-
and eat your fruit loops in the dark
|
42
|
-
and bring your flask of jack to work
|
43
|
-
and play your ukulele
|
44
|
-
|
45
|
-
ukulele, thing of wonder
|
46
|
-
ukulele, wand of thunder
|
47
|
-
you can play the ukulele, too
|
48
|
-
in london and down under
|
49
|
-
play joan jett, and play jacques brel
|
50
|
-
and eminem and neutral milk hotel
|
51
|
-
the children crush the hatred
|
52
|
-
play your ukulele naked
|
53
|
-
and if anybody tries to steal your ukulele, let them take it
|
54
|
-
|
55
|
-
imagine there’s no music, imagine there are no songs
|
56
|
-
imagine that john lennon wasn’t shot in front of his apartment
|
57
|
-
imagine if john lennon had composed “imagine” on the ukulele
|
58
|
-
maybe folks would have more clearly got the message
|
59
|
-
|
60
|
-
you may think my approach is simple-minded and naïve
|
61
|
-
like if you want to save the world then why not quit and feed the hungry
|
62
|
-
but people for millennia have needed music to survive
|
63
|
-
and that’s why i’ve promised john that i will not feel guilty
|
64
|
-
|
65
|
-
so play your favorite beatles’ song
|
66
|
-
and make the subway fall in love
|
67
|
-
they’re only $19.95, that’s not a lot of money
|
68
|
-
play until the sun comes up
|
69
|
-
and play until your fingers suffer
|
70
|
-
play LCD soundsystem songs on your ukulele
|
71
|
-
quit the bitching on your blog
|
72
|
-
and stop pretending art is hard
|
73
|
-
just limit yourself to three chords
|
74
|
-
and do not practice daily
|
75
|
-
you’ll minimize some stranger’s sadness
|
76
|
-
with a piece of wood and plastic
|
77
|
-
holy fuck it’s so fantastic, playing ukulele
|
78
|
-
eat your homework with a fork
|
79
|
-
and do your fruit loops in the dark
|
80
|
-
bring your etch-a-sketch to work
|
81
|
-
your flask of jack
|
82
|
-
your vibrator
|
83
|
-
your fear of heights
|
84
|
-
your nikon lens
|
85
|
-
your mom and dad
|
86
|
-
your disco stick
|
87
|
-
your soundtrack from “karate kid”
|
88
|
-
your ginsu knives
|
89
|
-
your rosary
|
90
|
-
your new rebecca black CD
|
91
|
-
your favorite room
|
92
|
-
your bowie knife
|
93
|
-
your stuffed giraffe
|
94
|
-
your new glass eye
|
95
|
-
your sousaphone
|
96
|
-
your breakfast tea
|
97
|
-
your nick drake tapes
|
98
|
-
your giving tree
|
99
|
-
your ice cream truck
|
100
|
-
your missing wife
|
101
|
-
your will to live
|
102
|
-
your urge to cry
|
103
|
-
remember we’re all going to die
|
104
|
-
so PLAY YOUR UKULELE
|
105
|
-
|
106
|
-
— Amanda Palmer
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
metadata
CHANGED
@@ -1,68 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digiusb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bluebie
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: libusb
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.2.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.2.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: colorist
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 0.0.2
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.0.2
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: colored
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '1.2'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '1.2'
|
62
|
-
description:
|
63
|
-
|
64
|
-
|
65
|
-
|
55
|
+
description: |-
|
56
|
+
A tiny library for talking to digispark (a small arduino clone) over usb a bit like talking
|
57
|
+
to a real arduino through a serial port! This library works with the DigiUSB library built in to Digistump's
|
58
|
+
version of the Arduino software. Also includes a tiny terminal tool, kinda like telnet for digisparks
|
66
59
|
email: a@creativepony.com
|
67
60
|
executables:
|
68
61
|
- digiterm
|
@@ -75,10 +68,12 @@ files:
|
|
75
68
|
- license.txt
|
76
69
|
- examples/digiblink.rb
|
77
70
|
- examples/finn.rb
|
78
|
-
-
|
79
|
-
YmluL2RpZ2l0ZXJt
|
71
|
+
- bin/digiterm
|
80
72
|
homepage: http://github.com/Bluebie/digiusb.rb
|
81
|
-
licenses:
|
73
|
+
licenses:
|
74
|
+
- Unlicense
|
75
|
+
- CC0
|
76
|
+
metadata: {}
|
82
77
|
post_install_message:
|
83
78
|
rdoc_options:
|
84
79
|
- --main
|
@@ -86,22 +81,19 @@ rdoc_options:
|
|
86
81
|
require_paths:
|
87
82
|
- lib
|
88
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
84
|
requirements:
|
91
|
-
- -
|
85
|
+
- - '>='
|
92
86
|
- !ruby/object:Gem::Version
|
93
87
|
version: 1.9.3
|
94
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
89
|
requirements:
|
97
|
-
- -
|
90
|
+
- - '>='
|
98
91
|
- !ruby/object:Gem::Version
|
99
92
|
version: '0'
|
100
93
|
requirements: []
|
101
94
|
rubyforge_project:
|
102
|
-
rubygems_version:
|
95
|
+
rubygems_version: 2.0.3
|
103
96
|
signing_key:
|
104
|
-
specification_version:
|
97
|
+
specification_version: 4
|
105
98
|
summary: a tiny library for talking to digisparks
|
106
99
|
test_files: []
|
107
|
-
has_rdoc:
|