farmbot-serial 0.7.1 → 0.7.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afc6e55de74753b25d80ecb3b1ad5ffab421dee2
4
- data.tar.gz: 24fcba6046ace193dc977be60e22240c65837c35
3
+ metadata.gz: 5f70c1d389944aaf66a8f619de9b56b0c4810ac5
4
+ data.tar.gz: b2a4a401415b351b5c0fa0a2b6ed0f3a5f45d93f
5
5
  SHA512:
6
- metadata.gz: 5ff97f82563c17b7bbf2eb59a480a0cca3404d715dd9dd7cd6732f8cce52627b613209b62190de03f62bd8849f8bfae2d5eb10e3184aab349d7fda90c75e63d0
7
- data.tar.gz: 48dba271d062b49875e2a79b1b8cad54097bf411fdac2fd223ff221e4d4820bc20ea5bef3fcc650c04f142621700e5d34a2904748e0dc6c467b56a117c3c1da2
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 reporting_end_stops(gcode)
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 write_parameter(num, val)
59
- write { "F22 P#{num} V#{val}" }
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(pin)
63
- write { "F31 P#{pin}" }
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 pin_write(pin:, value:, mode:)
74
+ def write_pin(pin:, value:, mode:)
67
75
  write { "F41 P#{pin} V#{value} M#{mode}" }
68
- bot.status.set(pin, value)
76
+ bot.status.set_pin(pin, value)
69
77
  end
70
78
 
71
79
  def set_max_speed(axis, value)
@@ -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.to_s]
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 get(val)
47
- @info[val.to_s.upcase] || :unknown
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.report_parameter_value(FB::Gcode.new { "A1 P1 V0" })
22
- expect(bot.status.pin(1)).to eq(:off)
23
- handler.report_parameter_value(FB::Gcode.new { "A1 P1 V1" })
24
- expect(bot.status.pin(1)).to eq(:on)
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.reporting_end_stops(gcode)
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.report_status_value(FB::Gcode.new { "A1 P1 V0" })
41
- expect(bot.status.pin(1)).to eq(:off)
42
- handler.report_status_value(FB::Gcode.new { "A1 P1 V1" })
43
- expect(bot.status.pin(1)).to eq(:on)
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
@@ -70,7 +70,7 @@ describe FB::OutgoingHandler do
70
70
  end
71
71
 
72
72
  it 'writes to a pin' do
73
- handler.pin_write(pin: 0, value: 1, mode: 3)
73
+ handler.write_pin(pin: 0, value: 1, mode: 3)
74
74
  expect(bot.next_cmd.to_s).to eq("F41 P0 V1 M3")
75
75
  end
76
76
 
@@ -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.set(1, 1)
50
- expect(status.pin(1)).to eq(:on)
51
- expect(status.pin(2)).to eq(:unknown)
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.1
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-05 00:00:00.000000000 Z
12
+ date: 2015-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler