Module: AvrUpload

Defined in:
lib/avrupload/avrdudeproxy.rb,
lib/avrupload.rb,
lib/avrupload/version.rb

Overview

AVRDude proxy class

Copyright (C) 2016, 2017  Michel Megens <[email protected]>

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

Defined Under Namespace

Classes: AvrDudeProxy

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/avrupload.rb', line 34

def parse(args)
  options = OpenStruct.new

  options.tty_fix = false
  options.hex = nil
  options.mcu = nil
  options.programmer = nil
  options.port = nil
  options.baud = 115200
  options.config = "/etc/avrdude.conf"

  parser = OptionParser.new do |p|
    p.banner = "Usage: avr_upload [options]"
    p.separator ""
    p.separator "Specific options:"

    p.on('-f', '--tty-fix', "Reset the TTY config before uploading") do
      options.tty_fix = true
    end

    p.on('-H [FILE]', '--hex [FILE]',
         'Hex file to upload to the AVR program memory') do |file|
      options.hex = file
    end

    p.on('-m [MCU]', '--mcu [MCU]',
         'The type of MCU you are trying to upload to') do |mcu|
      options.mcu = mcu
    end

    p.on('-p [PROGRAMMER]', '--programmer [PROGRAMMER]',
         'Programmer to use to upload the hex file to the AVR') do |prog|
      options.programmer = prog
    end

    p.on('-P [PORT]', '--port [PORT]',
         'Serial port to which the board is connected') do |port|
      options.port = port
    end

    p.on('-b [BAUD]', '--baud [BAUD]',
         'Serial baud rate to use') do |baud|
      options.baud = baud
    end

    p.on('-c [FILE]', '--config [FILE]',
         'Config file for avrdude, defaults to /etc/avrdude.conf') do |conf|
      options.config = conf
    end

    p.separator ""
    p.separator "Common options:"

    p.on_tail('-h', '--help', "Show this message") do
      puts p
      exit
    end

    p.on_tail('-v', '--version', 'Show the version number') do
      puts "AVR uploader #{AvrUpload::VERSION}"
      exit
    end
  end

  parser.parse!
  mandatory = [:programmer, :hex, :mcu, :port]
  missing = mandatory.select do |param|
    param if options[param].nil?
  end

  unless missing.empty?
    puts "Missing mandatory options: #{missing.to_s}"
    puts ""
    puts parser
    exit 1
  end

  options
end

.start(args) ⇒ Object



28
29
30
31
32
# File 'lib/avrupload.rb', line 28

def start(args)
	options = AvrUpload.parse(args)
	proxy = AvrDudeProxy.new(options)
	proxy.upload
end