farmbot-serial 0.1.0 → 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/lib/arduino.rb +2 -2
 - data/lib/arduino/outgoing_handler.rb +3 -3
 - data/lib/gcode.rb +19 -8
 - data/spec/lib/gcode_spec.rb +12 -5
 - 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: 5b9026a21d4da007da2bdc85509d68297763fce5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 78705810cdea9c1b98e6f217859b2be0a08e6090
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d02a8e074e6964ed3340b0450528b3caac103bc54734266cbd24db2d1db25c1516ed48fbd704cd17416f4a6c6f9134da4cbc1e8c18d0a467e560c13d27614aa6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1aa4ede5691439074cd5de2e269b52e18a405d65a2faac85aeac8d305b8643e50570de696fa58a72ee4a54468e0f42ad63dc4d688a8f5ce7d19d613710ef5f7f
         
     | 
    
        data/lib/arduino.rb
    CHANGED
    
    
| 
         @@ -20,7 +20,7 @@ module FB 
     | 
|
| 
       20 
20 
     | 
    
         
             
                  y += (bot.current_position.y || 0)
         
     | 
| 
       21 
21 
     | 
    
         
             
                  z += (bot.current_position.z || 0)
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                  write "G00 X#{x} Y#{y} Z#{z}"
         
     | 
| 
      
 23 
     | 
    
         
            +
                  write { FB::Gcode.new { "G00 X#{x} Y#{y} Z#{z}" } }
         
     | 
| 
       24 
24 
     | 
    
         
             
                end
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         
             
                def move_absolute(x: 0, y: 0, z: 0, s: 100)
         
     | 
| 
         @@ -61,8 +61,8 @@ module FB 
     | 
|
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
              private
         
     | 
| 
       63 
63 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
                def write(str)
         
     | 
| 
       65 
     | 
    
         
            -
                  bot.write(FB::Gcode.new 
     | 
| 
      
 64 
     | 
    
         
            +
                def write(str = "\n")
         
     | 
| 
      
 65 
     | 
    
         
            +
                  bot.write( block_given? ? yield : FB::Gcode.new{ str } )
         
     | 
| 
       66 
66 
     | 
    
         
             
                end
         
     | 
| 
       67 
67 
     | 
    
         
             
              end
         
     | 
| 
       68 
68 
     | 
    
         
             
            end
         
     | 
    
        data/lib/gcode.rb
    CHANGED
    
    | 
         @@ -3,18 +3,16 @@ module FB 
     | 
|
| 
       3 
3 
     | 
    
         
             
              class Gcode
         
     | 
| 
       4 
4 
     | 
    
         
             
                GCODE_DICTIONARY = YAML.load_file(File.join(File.dirname(__FILE__), 'gcode.yml'))
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                attr_accessor :cmd, :params, : 
     | 
| 
      
 6 
     | 
    
         
            +
                attr_accessor :cmd, :params, :block
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                def initialize( 
     | 
| 
       9 
     | 
    
         
            -
                  @ 
     | 
| 
       10 
     | 
    
         
            -
                  @params = str.split(' ').map { |line| GcodeToken.new(line) }
         
     | 
| 
       11 
     | 
    
         
            -
                  @cmd    = @params.shift || 'NULL'
         
     | 
| 
      
 8 
     | 
    
         
            +
                def initialize(&block)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @block  = block
         
     | 
| 
       12 
10 
     | 
    
         
             
                end
         
     | 
| 
       13 
11 
     | 
    
         | 
| 
       14 
12 
     | 
    
         
             
                # Turns a string of many gcodes into an array of many gcodes. Used to parse
         
     | 
| 
       15 
13 
     | 
    
         
             
                # incoming serial.
         
     | 
| 
       16 
14 
     | 
    
         
             
                def self.parse_lines(string)
         
     | 
| 
       17 
     | 
    
         
            -
                  string.gsub("\r", '').split("\n").map { |s| self.new 
     | 
| 
      
 15 
     | 
    
         
            +
                  string.gsub("\r", '').split("\n").map { |s| self.new { s } }
         
     | 
| 
       18 
16 
     | 
    
         
             
                end
         
     | 
| 
       19 
17 
     | 
    
         | 
| 
       20 
18 
     | 
    
         
             
                # Returns a symbolized english version of the gcode's name.
         
     | 
| 
         @@ -24,12 +22,25 @@ module FB 
     | 
|
| 
       24 
22 
     | 
    
         | 
| 
       25 
23 
     | 
    
         
             
                def to_s
         
     | 
| 
       26 
24 
     | 
    
         
             
                  # self.to_s # => "A12 B23 C45"
         
     | 
| 
       27 
     | 
    
         
            -
                  [ 
     | 
| 
      
 25 
     | 
    
         
            +
                  [cmd, *params].map(&:to_s).join(" ")
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def params
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @block
         
     | 
| 
      
 30 
     | 
    
         
            +
                    .call
         
     | 
| 
      
 31 
     | 
    
         
            +
                    .split(' ')
         
     | 
| 
      
 32 
     | 
    
         
            +
                    .map { |line| GcodeToken.new(line) }
         
     | 
| 
      
 33 
     | 
    
         
            +
                    .tap { |p| p.shift }
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                def cmd
         
     | 
| 
      
 37 
     | 
    
         
            +
                  cmd = @block.call.split(' ')
         
     | 
| 
      
 38 
     | 
    
         
            +
                  GcodeToken.new(cmd.any? ? cmd.first : "NULL0")
         
     | 
| 
       28 
39 
     | 
    
         
             
                end
         
     | 
| 
       29 
40 
     | 
    
         | 
| 
       30 
41 
     | 
    
         
             
                # A head/tail pair of a single node of GCode. Ex: R01 = [:R, '01']
         
     | 
| 
       31 
42 
     | 
    
         
             
                class GcodeToken
         
     | 
| 
       32 
     | 
    
         
            -
                  attr_reader :head, :tail 
     | 
| 
      
 43 
     | 
    
         
            +
                  attr_reader :head, :tail
         
     | 
| 
       33 
44 
     | 
    
         | 
| 
       34 
45 
     | 
    
         
             
                  def initialize(str)
         
     | 
| 
       35 
46 
     | 
    
         
             
                    nodes = str.scan(/\d+|\D+/) # ["R", "01"]
         
     | 
    
        data/spec/lib/gcode_spec.rb
    CHANGED
    
    | 
         @@ -1,17 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         
             
            describe FB::Gcode do
         
     | 
| 
       3 
     | 
    
         
            -
              let(:gcode) { FB::Gcode.new 
     | 
| 
      
 3 
     | 
    
         
            +
              let(:gcode) { FB::Gcode.new{ "F31 P8 " } }
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:null_token) { FB::Gcode::GcodeToken.new("NULL0") }
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
              it("initializes from string") { expect(gcode).to be_kind_of(FB::Gcode) }
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
              it("infers Gcode name") { expect(gcode.name).to eq(:read_status) }
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
              it "returns :unknown for bad Gcode tokens" do
         
     | 
| 
       10 
     | 
    
         
            -
                unknown = FB::Gcode.new 
     | 
| 
      
 11 
     | 
    
         
            +
                unknown = FB::Gcode.new{ "QQQ31 F32 " }.name
         
     | 
| 
       11 
12 
     | 
    
         
             
                expect(unknown).to eq(:unknown)
         
     | 
| 
       12 
13 
     | 
    
         
             
              end
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
              it("sets the original input string") { expect(gcode. 
     | 
| 
      
 15 
     | 
    
         
            +
              it("sets the original input string") { expect(gcode.block[]).to eq("F31 P8 ") }
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
              it("sets @cmd using the first Gcode node") do
         
     | 
| 
       17 
18 
     | 
    
         
             
                expect(gcode.cmd).to be_kind_of(FB::Gcode::GcodeToken)
         
     | 
| 
         @@ -39,8 +40,14 @@ describe FB::Gcode do 
     | 
|
| 
       39 
40 
     | 
    
         
             
              end
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
       41 
42 
     | 
    
         
             
              it 'handles parameterless Gcode' do
         
     | 
| 
       42 
     | 
    
         
            -
                expect(FB::Gcode.new 
     | 
| 
       43 
     | 
    
         
            -
                expect(FB::Gcode.new 
     | 
| 
      
 43 
     | 
    
         
            +
                expect(FB::Gcode.new{ "  " }.name).to be(:unknown)
         
     | 
| 
      
 44 
     | 
    
         
            +
                expect(FB::Gcode.new{ "  " }.cmd.head).to eq(null_token.head)
         
     | 
| 
      
 45 
     | 
    
         
            +
                expect(FB::Gcode.new{ "  " }.cmd.tail).to eq(null_token.tail)
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
              it 'sets dyanmic parameters' do
         
     | 
| 
      
 49 
     | 
    
         
            +
                random_gcode = FB::Gcode.new{ "Q#{Time.now.to_f.to_s[-2, 2]}" }
         
     | 
| 
      
 50 
     | 
    
         
            +
                expect(random_gcode.cmd.tail).to_not eq(random_gcode.cmd.tail)
         
     | 
| 
       44 
51 
     | 
    
         
             
              end
         
     | 
| 
       45 
52 
     | 
    
         
             
            end
         
     | 
| 
       46 
53 
     | 
    
         | 
    
        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.1 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.1
         
     | 
| 
       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-04- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2015-04-12 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: bundler
         
     |