ev3dev_ruby 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Display_API.md +124 -0
- data/README.md +12 -6
- data/lib/ev3dev.rb +2 -0
- data/lib/ev3dev/battery.rb +1 -1
- data/lib/ev3dev/button.rb +1 -1
- data/lib/ev3dev/image.rb +41 -0
- data/lib/ev3dev/led.rb +9 -11
- data/lib/ev3dev/screen.rb +55 -0
- data/lib/ev3dev/sound.rb +1 -1
- data/lib/ev3dev/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2ef7e22480bd273e44f7609568aa184ba03a945
|
4
|
+
data.tar.gz: 51ae42dde560f7bbe9e1ad5fd5c3004015feb0b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b02a281fc37fc894132d6bc628615c16ea7c5992d2dd8dfa58416102d0b834aa87f18321ef1774359f5191bc098d78df775821d52aed9b6535cfcb0434ae37c
|
7
|
+
data.tar.gz: 0ee5e884db3ec5ef86435a65200f087b9ec18371222d6fa168ca048f8426bc87d2c856251641abf302f88dca0775e7a4c3421004ddf311a30021e83a1310d3f3
|
data/Display_API.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# EV3 Display (LCD)
|
2
|
+
|
3
|
+
## Display Specifications
|
4
|
+
* Mode : 178 x 128 pixel
|
5
|
+
* LineLength : 24 bytes (192 bits)
|
6
|
+
* Geometry : 1 (1 bit per pixel)
|
7
|
+
* Type : PACKED PIXELS
|
8
|
+
* Visual : MONO01 (0: white, 1: black)
|
9
|
+
* Frame Buffer directory : /dev/fb0
|
10
|
+
* Frame Buffer size : 24 * 128 = 3072 bytes
|
11
|
+
* 178 bits in a line (192 bits) and 128 rows are actually displayed
|
12
|
+
|
13
|
+
## Image File Format
|
14
|
+
Image file must be 192 x 128 pixel .mono format
|
15
|
+
(raw bi-level bitmap in least-significant-byte(LSB) first order)
|
16
|
+
|
17
|
+
### .mono format
|
18
|
+
see [ImageMagick: Supported Image Formats](http://www.imagemagick.org/script/formats.php)
|
19
|
+
|
20
|
+
## Ev3dev::Screen Class
|
21
|
+
Screen Class only supports the 192 x 128 pixel .mono image file format
|
22
|
+
|
23
|
+
- \#initialize
|
24
|
+
|
25
|
+
creates an accessible instance variable @imgs (blank array)
|
26
|
+
|
27
|
+
- \#load(image_file)
|
28
|
+
|
29
|
+
loads image file and adds to the array @imgs
|
30
|
+
(file should be the 192 x 128 pixel .mono format)
|
31
|
+
|
32
|
+
- \#load_blank
|
33
|
+
|
34
|
+
adds blank image (white image) to the array @imgs
|
35
|
+
|
36
|
+
- \#show
|
37
|
+
|
38
|
+
shows the @imgs[0] image to the EV3 LCD display and shifts the array @imgs (if @imgs.size >= 2)
|
39
|
+
|
40
|
+
- \#show_blank
|
41
|
+
|
42
|
+
displays the blank image (white image) and the array @imgs is unchanged
|
43
|
+
|
44
|
+
|
45
|
+
## Ev3dev::Image Class
|
46
|
+
Image Class converts various size and format image files to the EV3 display format (192 x 128 pixel .mono format).
|
47
|
+
And it can also create text images.
|
48
|
+
|
49
|
+
It requires [RMagick](https://github.com/rmagick/rmagick) gem ([ImageMagick](http://www.imagemagick.org/) Ruby binding).
|
50
|
+
To install [RMagick](https://github.com/rmagick/rmagick):
|
51
|
+
```
|
52
|
+
robot@ev3dev:~$ sudo apt-get update
|
53
|
+
robot@ev3dev:~$ sudo apt-get install ruby-rmagick
|
54
|
+
(or ~$ sudo gem install rmagick -N -V)
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
- \#initialize(image_file)
|
59
|
+
|
60
|
+
loads image file and converts the EV3 display format (192 x 128 pixel .mono format), or creates a blank image (if no arguments)
|
61
|
+
|
62
|
+
- \#save(output_file)
|
63
|
+
|
64
|
+
saves the image_file (output file name should be '.mono')
|
65
|
+
|
66
|
+
|
67
|
+
- \#text(x, y, size, string)
|
68
|
+
|
69
|
+
creates a text image
|
70
|
+
- x; x position of text
|
71
|
+
- y; y position of text
|
72
|
+
- size; font size
|
73
|
+
- string; text string
|
74
|
+
|
75
|
+
|
76
|
+
## How to create the EV3 display format (192 x 128 pixel .mono format) file on PC
|
77
|
+
|
78
|
+
### ImageMagick
|
79
|
+
1. Install ImageMagick
|
80
|
+
|
81
|
+
see [ImageMagick site](http://www.imagemagick.org/)
|
82
|
+
|
83
|
+
2. Terminal command
|
84
|
+
```
|
85
|
+
$ convert -resize 192x128! original_file.jpg converted_file.mono
|
86
|
+
#converted_file_name must have .mono
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
- Display the .mono file on PC
|
91
|
+
it requires X Window System (or [XQuartz](https://www.xquartz.org) for Mac)
|
92
|
+
```
|
93
|
+
$ display -size 192x128 converted_file.mono
|
94
|
+
```
|
95
|
+
|
96
|
+
### RMagick (ImageMagick Ruby binding)
|
97
|
+
|
98
|
+
1. Install ImageMagick and RMagick
|
99
|
+
|
100
|
+
see [ImageMagick site](http://www.imagemagick.org/) and [RMagick site](https://github.com/rmagick/rmagick)
|
101
|
+
|
102
|
+
2. Ruby Program
|
103
|
+
```ruby
|
104
|
+
require 'RMagick'
|
105
|
+
target_image = Magick::Image.read('original_file.jpg').first
|
106
|
+
target_image.resize_to_fill!(192, 128)
|
107
|
+
target_image.write('converted_file.mono') #converted_file_name must have .mono
|
108
|
+
target_image.destroy!
|
109
|
+
```
|
110
|
+
|
111
|
+
|
112
|
+
- Display the .mono file on PC
|
113
|
+
it requires X Window System (or [XQuartz](https://www.xquartz.org) for Mac)
|
114
|
+
```ruby
|
115
|
+
require 'RMagick'
|
116
|
+
mono_image = Magick::Image.read('converted_file.mono') { self.size = "192x128" }.first
|
117
|
+
mono_image.display
|
118
|
+
```
|
119
|
+
|
120
|
+
## More Info
|
121
|
+
|
122
|
+
- Also checkout examples
|
123
|
+
|
124
|
+
- [Using the EV3 LCD - ev3dev.org ](http://www.ev3dev.org/docs/tutorials/using-ev3-lcd/)
|
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
# ev3dev ruby binding for LEGO Mindstorms EV3
|
2
2
|
|
3
3
|
|
4
|
-
ev3dev_ruby is a gem to controll sensors and motors on EV3 using Ruby.
|
4
|
+
ev3dev_ruby is a gem to controll sensors and motors on EV3 using Ruby on ev3dev OS.
|
5
|
+
ev3dev OS is a Debian Linux-based operating system for LEGO Mindstroms EV3.
|
5
6
|
|
6
|
-
- [ev3dev](http://www.ev3dev.org) version; ev3dev-jessie-2015-12-30
|
7
|
+
- [ev3dev OS](http://www.ev3dev.org) version; ev3dev-jessie-2015-12-30
|
8
|
+
|
9
|
+
|
10
|
+
## Install ev3dev OS
|
11
|
+
See [ev3dev OS website](http://www.ev3dev.org)
|
7
12
|
|
8
13
|
|
9
14
|
## Install ev3dev_ruby on EV3
|
@@ -15,11 +20,10 @@ SSH remote access to the EV3 from PC
|
|
15
20
|
$ ssh robot@ev3dev.local
|
16
21
|
```
|
17
22
|
|
18
|
-
|
19
|
-
|
20
23
|
then
|
21
24
|
|
22
25
|
```
|
26
|
+
robot@ev3dev:~$ sudo apt-get update
|
23
27
|
robot@ev3dev:~$ sudo gem install ev3dev_ruby
|
24
28
|
```
|
25
29
|
|
@@ -118,12 +122,14 @@ irb(main):012:0>
|
|
118
122
|
- [LED Transient Trigger](https://www.kernel.org/doc/Documentation/leds/ledtrig-transient.txt)
|
119
123
|
- Original Led Class APIs are added. Checkout examples.
|
120
124
|
- [Buttons](http://www.ev3dev.org/docs/tutorials/using-ev3-buttons/)
|
125
|
+
- [Display](http://www.ev3dev.org/docs/tutorials/using-ev3-lcd/)
|
126
|
+
- Original Screen Class and Image Class APIs are added. See Display_API.md and examples.
|
121
127
|
|
122
|
-
####
|
128
|
+
#### The EV3 device below are not supported yet.
|
123
129
|
|
124
|
-
- [LCD](http://www.ev3dev.org/docs/tutorials/using-ev3-lcd/)
|
125
130
|
- [Bluetooth](https://github.com/ev3dev/ev3dev/wiki/Using-Bluetooth)
|
126
131
|
|
127
132
|
|
128
133
|
## More Info
|
134
|
+
|
129
135
|
- [Getting Started with ev3dev - ev3dev.org](http://www.ev3dev.org/docs/getting-started/)
|
data/lib/ev3dev.rb
CHANGED
data/lib/ev3dev/battery.rb
CHANGED
data/lib/ev3dev/button.rb
CHANGED
@@ -19,7 +19,7 @@ module Ev3dev
|
|
19
19
|
BUF_LEN = (KEY_MAX + 7) / 8
|
20
20
|
PATH = "/dev/input/by-path/platform-gpio-keys.0-event"
|
21
21
|
|
22
|
-
def initialize
|
22
|
+
def initialize
|
23
23
|
raise "couldn't find LED attributes" unless File.exist?(PATH)
|
24
24
|
@buttons = {up: KEY_UP, down: KEY_DOWN, left: KEY_LEFT, right: KEY_RIGHT, enter: KEY_ENTER, back: KEY_BACK}
|
25
25
|
end
|
data/lib/ev3dev/image.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# You should install ImageMagick and its Ruby binding gem RMagick.
|
2
|
+
# robot@ev3dev:~$ sudo apt-get update
|
3
|
+
# robot@ev3dev:~$ sudo apt-get install ruby-rmagick
|
4
|
+
# (or ~$ sudo gem install rmagick -N -V)
|
5
|
+
|
6
|
+
module Ev3dev
|
7
|
+
class Image
|
8
|
+
def initialize(*args)
|
9
|
+
require 'RMagick'
|
10
|
+
|
11
|
+
case args.size
|
12
|
+
when 0
|
13
|
+
@image = Magick::Image.new(192, 128){ self.format = 'mono'}
|
14
|
+
when 1
|
15
|
+
image_file = args.first
|
16
|
+
|
17
|
+
if image_file.end_with?('.mono')
|
18
|
+
@image = Magick::Image.read(image_file){ self.size = "192x128" }.first
|
19
|
+
else
|
20
|
+
@image = Magick::Image.read(image_file).first
|
21
|
+
@image.format = 'mono'
|
22
|
+
@image.resize_to_fill!(192, 128)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
raise "ArgumentError: wrong number of arguments 0 or 1"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# resize EV3 Screen(192 x 128) and .mono image format
|
30
|
+
# output file name should be '.mono'
|
31
|
+
def save(output_file)
|
32
|
+
@image.write(output_file)
|
33
|
+
@image.destroy!
|
34
|
+
end
|
35
|
+
|
36
|
+
def text(x, y, size, string)
|
37
|
+
draw = Magick::Draw.new
|
38
|
+
draw.annotate(@image, 0, 0, x, y, string){self.pointsize = size}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/ev3dev/led.rb
CHANGED
@@ -10,7 +10,7 @@ module Ev3dev
|
|
10
10
|
|
11
11
|
MAX_BRIGHTNESS = 255
|
12
12
|
|
13
|
-
def initialize
|
13
|
+
def initialize
|
14
14
|
raise "couldn't find LED attributes" unless File.exist?(PATH)
|
15
15
|
|
16
16
|
@left_green = set_led_path("left" , "green")
|
@@ -25,32 +25,32 @@ module Ev3dev
|
|
25
25
|
@paths = @default_paths
|
26
26
|
end
|
27
27
|
|
28
|
-
def left
|
28
|
+
def left
|
29
29
|
@paths = @left_paths
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
33
|
-
def right
|
33
|
+
def right
|
34
34
|
@paths = @right_paths
|
35
35
|
self
|
36
36
|
end
|
37
37
|
|
38
|
-
def left_green
|
38
|
+
def left_green
|
39
39
|
@paths = [@left_green]
|
40
40
|
self
|
41
41
|
end
|
42
42
|
|
43
|
-
def left_red
|
43
|
+
def left_red
|
44
44
|
@paths = [@left_red]
|
45
45
|
self
|
46
46
|
end
|
47
47
|
|
48
|
-
def right_green
|
48
|
+
def right_green
|
49
49
|
@paths = [@right_green]
|
50
50
|
self
|
51
51
|
end
|
52
52
|
|
53
|
-
def right_red
|
53
|
+
def right_red
|
54
54
|
@paths = [@right_red]
|
55
55
|
self
|
56
56
|
end
|
@@ -63,7 +63,7 @@ module Ev3dev
|
|
63
63
|
@paths = @default_paths
|
64
64
|
end
|
65
65
|
|
66
|
-
def off
|
66
|
+
def off
|
67
67
|
self.on(0, 0)
|
68
68
|
end
|
69
69
|
|
@@ -116,7 +116,7 @@ module Ev3dev
|
|
116
116
|
@paths = @default_paths
|
117
117
|
end
|
118
118
|
|
119
|
-
def flash
|
119
|
+
def flash
|
120
120
|
raise "couldn't specify the left/right green/red LED" if @paths.size != 1
|
121
121
|
path = @paths[0]
|
122
122
|
write_value_to_file(path, "activate", 1)
|
@@ -178,5 +178,3 @@ module Ev3dev
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
181
|
-
|
182
|
-
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# http://www.ev3dev.org/docs/tutorials/using-ev3-lcd/
|
2
|
+
# LCD Mode : 178 x 128 pixel
|
3
|
+
# LineLength: 24 bytes (192 bits)
|
4
|
+
# Geometry : 1 (1 bit per pixel)
|
5
|
+
# Type : PACKED PIXELS
|
6
|
+
# Visual : MONO01 (0: white, 1: black)
|
7
|
+
# Frame Buffer directory: /dev/fb0
|
8
|
+
# Frame Buffer size : 24 * 128 = 3072 bytes
|
9
|
+
# 178 bits in a line (192 bits) and 128 rows are actually displayed
|
10
|
+
#
|
11
|
+
# image_file must be 192 x 128 pixel .mono format
|
12
|
+
# (raw bi-level bitmap in least-significant-byte(LSB) first order)
|
13
|
+
# http://www.imagemagick.org/script/formats.php
|
14
|
+
|
15
|
+
|
16
|
+
module Ev3dev
|
17
|
+
class Screen
|
18
|
+
PATH = "/dev/fb0"
|
19
|
+
|
20
|
+
FRAME_BUFFER_SIZE = 3072 # 24 line length * 128 rows
|
21
|
+
BLANK_IMAGE = Array.new(FRAME_BUFFER_SIZE){ 0 }.pack("C*")
|
22
|
+
|
23
|
+
attr_accessor :imgs
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
raise "couldn't find screen attributes" unless File.exist?(PATH)
|
27
|
+
@imgs = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def load(image_file)
|
31
|
+
raise "couldn't load a image file except .mono format" unless image_file.end_with?('.mono')
|
32
|
+
|
33
|
+
file_size = File.size(image_file)
|
34
|
+
raise "file size:#{file_size} is not correct:(#{FRAME_BUFFER_SIZE})" unless file_size == FRAME_BUFFER_SIZE
|
35
|
+
|
36
|
+
@imgs << File.binread(image_file)
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_blank
|
40
|
+
@imgs << BLANK_IMAGE
|
41
|
+
end
|
42
|
+
|
43
|
+
def show
|
44
|
+
if @imgs.size >= 2
|
45
|
+
File.binwrite(PATH, @imgs.shift)
|
46
|
+
else
|
47
|
+
File.binwrite(PATH, @imgs.first)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def show_blank
|
52
|
+
File.binwrite(PATH, BLANK_IMAGE)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/ev3dev/sound.rb
CHANGED
data/lib/ev3dev/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ev3dev_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- quake wang
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-06-
|
12
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- Display_API.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -56,8 +57,10 @@ files:
|
|
56
57
|
- lib/ev3dev/battery.rb
|
57
58
|
- lib/ev3dev/button.rb
|
58
59
|
- lib/ev3dev/device.rb
|
60
|
+
- lib/ev3dev/image.rb
|
59
61
|
- lib/ev3dev/led.rb
|
60
62
|
- lib/ev3dev/motor.rb
|
63
|
+
- lib/ev3dev/screen.rb
|
61
64
|
- lib/ev3dev/sensor.rb
|
62
65
|
- lib/ev3dev/sound.rb
|
63
66
|
- lib/ev3dev/version.rb
|