pilite 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/pilite +85 -0
  3. data/lib/pilite.rb +101 -0
  4. metadata +75 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c5c7ab018f82179585baf83f87f2d60509e4898
4
+ data.tar.gz: cf8cd824db98cf737c916898753c0b18250f8146
5
+ SHA512:
6
+ metadata.gz: 1a9d9234c309f4a49aab79cf210a9a7589f114063f44e39518869eed417bc490863c40177bc44a81e683287cbc6391614e28cba0a2ad3a6d793d790ef5f162d0
7
+ data.tar.gz: 31c48834a90c4b260d1610715b37a3cf92b458b0b3da57368ca1f739746ecfd854e0b55568ff88f32de566be3e73ad4655c5cfa4f2f94b9113b3991f17decc7b
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ # pilite
5
+ #
6
+ # excutable for pilite
7
+ #
8
+ # created on : 2013.08.12
9
+ # last update: 2013.08.12
10
+ #
11
+ # by meinside@gmail.com
12
+
13
+ require "thor"
14
+
15
+ require "pilite"
16
+
17
+ module PiLite
18
+ class Exec < Thor
19
+ desc "speed [VALUE]", "Changes scroll spped"
20
+ def speed(value)
21
+ PiLite::Commands::start{|lite|
22
+ lite.speed(value)
23
+ }
24
+ end
25
+
26
+ desc "fbuffer [BITS]", "Prints frame buffer with given BITS"
27
+ def fbuffer(bits)
28
+ PiLite::Commands::start{|lite|
29
+ lite.fbuffer(bits)
30
+ }
31
+ end
32
+
33
+ desc "bar [COLUMN] [VALUE]", "Draws a bar at given COLUMN with VALUE percentage"
34
+ def bar(column, value)
35
+ PiLite::Commands::start{|lite|
36
+ lite.bar(column, value)
37
+ }
38
+ end
39
+
40
+ desc "vumeter [ROW] [VALUE]", "Draws a VU meter on ROW with VALUE percentage"
41
+ def vumeter(row, value)
42
+ PiLite::Commands::start{|lite|
43
+ lite.vumeter(row, value)
44
+ }
45
+ end
46
+
47
+ desc "pixel [COLUMN] [ROW] [ACTION]", "Prints a pixel on (COLUMN, ROW) with ACTION(on/off/toggle)"
48
+ def pixel(column, row, action)
49
+ PiLite::Commands::start{|lite|
50
+ lite.pixel(column, row, action)
51
+ }
52
+ end
53
+
54
+ desc "all [ACTION]", "Turns on/off all LEDs"
55
+ def all(action)
56
+ PiLite::Commands::start{|lite|
57
+ lite.all(action)
58
+ }
59
+ end
60
+
61
+ desc "scroll [OFFSET]", "Scrolls to offset"
62
+ def scroll(offset)
63
+ PiLite::Commands::start{|lite|
64
+ lite.scroll(offset)
65
+ }
66
+ end
67
+
68
+ desc "char [COLUMN] [ROW] [CHAR]", "Prints CHAR on (COLUMN, ROW)"
69
+ def char(column, row, char)
70
+ PiLite::Commands::start{|lite|
71
+ lite.char(column, row, char)
72
+ }
73
+ end
74
+
75
+ desc "text [TEXT]", "Scrolls TEXT"
76
+ def text(str)
77
+ PiLite::Commands::start{|lite|
78
+ lite.text(str)
79
+ }
80
+ end
81
+ end
82
+ end
83
+
84
+ PiLite::Exec.start(ARGV)
85
+
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ # lib/pilite.rb
5
+ #
6
+ # ruby library for controlling Pi-LITE board
7
+ # (http://shop.ciseco.co.uk/pi-lite-lots-of-leds-for-the-raspberry-pi-0805-red/)
8
+ #
9
+ # created on : 2013.08.09
10
+ # last update: 2013.08.12
11
+ #
12
+ # by meinside@gmail.com
13
+
14
+ require "serialport"
15
+
16
+ module PiLite
17
+ class Commands
18
+ @@pilite = nil
19
+
20
+ private
21
+ def initialize(port, params)
22
+ @serial = SerialPort.new(port, params)
23
+ end
24
+ def command(cmd)
25
+ @serial.write("$$$#{cmd}\r")
26
+ end
27
+
28
+ public
29
+ def self.start(port = "/dev/ttyAMA0", params = {baudrate: 9600}, &block)
30
+ @@pilite = PiLite::Commands.new(port, params) unless @@pilite
31
+
32
+ if block_given?
33
+ yield @@pilite
34
+ else
35
+ return @@pilite
36
+ end
37
+ end
38
+
39
+ # change scroll speed
40
+ # @param value [Number] scrolling delay from 1ms to 1000ms (default: 80)
41
+ def speed(value)
42
+ command "SPEED#{value}"
43
+ end
44
+
45
+ # print framebuffer
46
+ # @param bits [String/Array] array of 0/1s for each LED's state (0:off, 1:on, 14 x 9 total)
47
+ def fbuffer(bits)
48
+ bits = bits.join if bits.kind_of? Array
49
+ command "F#{bits}"
50
+ end
51
+
52
+ # draw a bar at given column with provided value (this command does not overwrite the screen)
53
+ # @param column [Number] column number (1 ~ 14)
54
+ # @param value [Number] percentage (0 ~ 100)
55
+ def bar(column, value)
56
+ command "B#{column},#{value}"
57
+ end
58
+
59
+ # draw VU meter
60
+ # @param row [Number] row number (1 ~ 2)
61
+ # @param value [Number] percentage (0 ~ 100)
62
+ def vumeter(row, value)
63
+ command "V#{row},#{value}"
64
+ end
65
+
66
+ # do an action on a pixel at given column/row
67
+ # @param column [Number] column number (1 ~ 14)
68
+ # @param row [Number] row number (1 ~ 9)
69
+ # @param action [Symbol] :on / :off / :toggle
70
+ def pixel(column, row, action)
71
+ command "P#{column},#{row},#{action.to_s.upcase}"
72
+ end
73
+
74
+ # turn on/off all LEDs
75
+ # @param action [Symbol] :on / :off
76
+ def all(action)
77
+ command "ALL,#{action.to_s.upcase}"
78
+ end
79
+
80
+ # scroll to left or right with given offset
81
+ # @param offset [Number] -1 ~ -14: shift to right / 1 ~ 14: shift to left
82
+ def scroll(offset)
83
+ command "SCROLL#{offset}"
84
+ end
85
+
86
+ # print a character at given column/row
87
+ # @param column [Number] column number (1 ~ 14)
88
+ # @param row [Number] row number (1 ~ 9)
89
+ # @param char [String] character
90
+ def char(column, row, char)
91
+ command "T#{column},#{row},#{char}"
92
+ end
93
+
94
+ # print text (will be scrolled automatically)
95
+ # @param str [String] text
96
+ def text(str)
97
+ @serial.write("#{str}\r")
98
+ end
99
+ end
100
+ end
101
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pilite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sungjin Han
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: serialport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rubygem for sending commands to 'Pi-LITE' board through serial port communication
42
+ email: meinside@gmail.com
43
+ executables:
44
+ - pilite
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/pilite.rb
49
+ - bin/pilite
50
+ homepage: http://github.com/meinside/pilite-rb
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.6
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Rubygem for using 'Pi-LITE' board on the Raspberry Pi
75
+ test_files: []