farmbot-serial 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arduino/incoming_handler.rb +5 -1
- data/lib/arduino/outgoing_handler.rb +14 -6
- data/lib/arduino/status.rb +9 -12
- data/spec/lib/arduino/incoming_handler_spec.rb +9 -9
- data/spec/lib/arduino/outgoing_handler_spec.rb +1 -1
- data/spec/lib/arduino/status_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f70c1d389944aaf66a8f619de9b56b0c4810ac5
|
4
|
+
data.tar.gz: b2a4a401415b351b5c0fa0a2b6ed0f3a5f45d93f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67fe520ab93bd13b4deac3609b9ba9b5b5939e2ef8c0f3c38b6b5ec4b9bf721519067c868981e23f600bba307ee94d35f1c303665a1cda3c023a28e3c771405f
|
7
|
+
data.tar.gz: 543109b2e6d97f0fdade6e8935ccb422315e8d8adec7a681aa17423fdb21584f88859f83bc1af94f96eac4c62f158b42413774f92762add8dffb1f3bda699f16
|
@@ -25,7 +25,11 @@ module FB
|
|
25
25
|
bot.status.set(gcode.value_of(:P), gcode.value_of(:V))
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def report_pin_value(gcode)
|
29
|
+
bot.status.set_pin(gcode.value_of(:P), gcode.value_of(:V))
|
30
|
+
end
|
31
|
+
|
32
|
+
def report_end_stops(gcode)
|
29
33
|
bot.status.gcode_update(gcode)
|
30
34
|
end
|
31
35
|
|
@@ -51,21 +51,29 @@ module FB
|
|
51
51
|
write { "G28" }
|
52
52
|
end
|
53
53
|
|
54
|
+
# Parameters are settings, which is not to be confused with status.
|
54
55
|
def read_parameter(num)
|
55
56
|
write { "F21 P#{num}" }
|
56
57
|
end
|
57
58
|
|
58
|
-
def
|
59
|
-
|
59
|
+
def read_pin(pin, mode = :digital)
|
60
|
+
unless [:analog, :digital].include?(mode)
|
61
|
+
raise "Mode must be :analog or :digital"
|
62
|
+
end
|
63
|
+
write { "F42 P#{pin} M#{(mode == :digital) ? 0 : 1}" }
|
60
64
|
end
|
61
65
|
|
62
|
-
def read_status(
|
63
|
-
write { "F31 P#{
|
66
|
+
def read_status(num)
|
67
|
+
write { "F31 P#{num}" }
|
68
|
+
end
|
69
|
+
|
70
|
+
def write_parameter(num, val)
|
71
|
+
write { "F22 P#{num} V#{val}" }
|
64
72
|
end
|
65
73
|
|
66
|
-
def
|
74
|
+
def write_pin(pin:, value:, mode:)
|
67
75
|
write { "F41 P#{pin} V#{value} M#{mode}" }
|
68
|
-
bot.status.
|
76
|
+
bot.status.set_pin(pin, value)
|
69
77
|
end
|
70
78
|
|
71
79
|
def set_max_speed(axis, value)
|
data/lib/arduino/status.rb
CHANGED
@@ -2,7 +2,7 @@ require 'ostruct'
|
|
2
2
|
module FB
|
3
3
|
class Status
|
4
4
|
# Map of informational status and default values for status within Arduino.
|
5
|
-
DEFAULT_INFO = {X: 0, Y: 0, Z: 0, S: 10, BUSY: 1, LAST: 'none'}
|
5
|
+
DEFAULT_INFO = {X: 0, Y: 0, Z: 0, S: 10, BUSY: 1, LAST: 'none', PINS: {}}
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@changes = EM::Channel.new
|
@@ -22,7 +22,7 @@ module FB
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def [](value)
|
25
|
-
@info[value.upcase
|
25
|
+
@info[value.to_s.upcase] || :unknown
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_h
|
@@ -43,8 +43,13 @@ module FB
|
|
43
43
|
self[:BUSY] == 0
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
@info[
|
46
|
+
def get_pin(num)
|
47
|
+
@info.PINS[num] || :unknown
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_pin(num, val)
|
51
|
+
val = [true, 1, '1'].include?(val) ? :on : :off
|
52
|
+
transaction { |info| info.PINS[num] = val }
|
48
53
|
end
|
49
54
|
|
50
55
|
def set(key, val)
|
@@ -52,13 +57,5 @@ module FB
|
|
52
57
|
info[Gcode::PARAMETER_DICTIONARY.fetch(key, "PIN_#{key}".to_sym)] = val
|
53
58
|
end
|
54
59
|
end
|
55
|
-
|
56
|
-
def pin(num)
|
57
|
-
case get("PIN_#{num}")
|
58
|
-
when false, 0, :off then :off
|
59
|
-
when true, 1, :on then :on
|
60
|
-
else; :unknown
|
61
|
-
end
|
62
|
-
end
|
63
60
|
end
|
64
61
|
end
|
@@ -18,15 +18,15 @@ describe FB::IncomingHandler do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'reports the value of a parameter' do
|
21
|
-
handler.
|
22
|
-
expect(bot.status.
|
23
|
-
handler.
|
24
|
-
expect(bot.status.
|
21
|
+
handler.report_pin_value(FB::Gcode.new { "A1 P1 V0" })
|
22
|
+
expect(bot.status.get_pin(1)).to eq(:off)
|
23
|
+
handler.report_pin_value(FB::Gcode.new { "A1 P1 V1" })
|
24
|
+
expect(bot.status.get_pin(1)).to eq(:on)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'reports end stops' do
|
28
28
|
gcode = FB::Gcode.new { "LOL1 S99" }
|
29
|
-
handler.
|
29
|
+
handler.report_end_stops(gcode)
|
30
30
|
expect(bot.status[:S]).to eq(99)
|
31
31
|
end
|
32
32
|
|
@@ -37,10 +37,10 @@ describe FB::IncomingHandler do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'reports the value of a status' do
|
40
|
-
handler.
|
41
|
-
expect(bot.status.
|
42
|
-
handler.
|
43
|
-
expect(bot.status.
|
40
|
+
handler.report_pin_value(FB::Gcode.new { "A1 P1 V0" })
|
41
|
+
expect(bot.status.get_pin(1)).to eq(:off)
|
42
|
+
handler.report_pin_value(FB::Gcode.new { "A1 P1 V1" })
|
43
|
+
expect(bot.status.get_pin(1)).to eq(:on)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'responds to message received' do
|
@@ -46,9 +46,9 @@ describe FB::Status do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'reads known and unknow pin values' do
|
49
|
-
status.
|
50
|
-
expect(status.
|
51
|
-
expect(status.
|
49
|
+
status.set_pin(1, 1)
|
50
|
+
expect(status.get_pin(1)).to eq(:on)
|
51
|
+
expect(status.get_pin(2)).to eq(:unknown)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'serializes into a hash' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: farmbot-serial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Evers
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-08-
|
12
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|