add general project files
This commit is contained in:
parent
5d539b210d
commit
33c31324f8
|
@ -0,0 +1,125 @@
|
|||
require 'rake/clean'
|
||||
|
||||
# =================
|
||||
# project variables
|
||||
# =================
|
||||
|
||||
# main name used if filename
|
||||
target = "led-controller"
|
||||
# schema
|
||||
sch = "#{target}.sch"
|
||||
# project version, read from "version" file
|
||||
version = IO.read("version").chomp
|
||||
# current date for stamping output
|
||||
date = Time.now.strftime("%Y-%m-%d")
|
||||
# schematic revision, based on the number of schematic commits)
|
||||
sch_rev = `git log --pretty=oneline "#{sch}" | wc -l`.chomp.to_i
|
||||
# schema name with version and revition
|
||||
vsch = "#{target}_v#{version}.#{sch_rev.to_s.rjust(3,'0')}.sch"
|
||||
|
||||
# ==========
|
||||
# main tasks
|
||||
# ==========
|
||||
|
||||
task :default => [:version,:print,:notes]
|
||||
|
||||
desc "set version in schematic"
|
||||
task :version => vsch
|
||||
CLEAN.include(vsch)
|
||||
CLOBBER.include("#{target}_*.sch")
|
||||
|
||||
desc "print schematic (as pdf)"
|
||||
task :print => "#{target}_schematic.pdf"
|
||||
CLEAN.include("#{target}_schematic.pdf")
|
||||
|
||||
desc "export notes from schematic"
|
||||
task :notes => "notes.txt"
|
||||
CLOBBER.include("notes.txt")
|
||||
|
||||
desc "verify schematic attributes"
|
||||
task :verify => vsch do |t|
|
||||
["value","footprint"].each do |attribute|
|
||||
bom2(t.prerequisites[0],attribute).each do |data|
|
||||
next unless data[attribute]=="unknown"
|
||||
puts "#{attribute}s not defined for #{data[:refdes]*','}"
|
||||
end
|
||||
end
|
||||
uniq = true
|
||||
numbered = true
|
||||
bom2(t.prerequisites[0],"refdes").each do |data|
|
||||
uniq &= data[:refdes].size==1
|
||||
numbered &= !data["refdes"].include?("?")
|
||||
end
|
||||
puts "not all refdes uniq" unless uniq
|
||||
puts "not all refdes numbered" unless numbered
|
||||
end
|
||||
|
||||
# ================
|
||||
# helper functions
|
||||
# ================
|
||||
|
||||
# generate gnetlist bom2 and parse them
|
||||
# arguments: schematic=schematic to usse, attributes=the attributs to use for generating bom2
|
||||
# return [{:refdes => [refdes of component], <attributes> => text of attributes}]
|
||||
def bom2(schematic, attributes)
|
||||
to_return = []
|
||||
# force attributes to be an array
|
||||
attributes = case attributes.class
|
||||
when String
|
||||
[attributes]
|
||||
when Array
|
||||
attributes
|
||||
else
|
||||
[attributes.to_s]
|
||||
end
|
||||
# create gnetlist backend
|
||||
File.open("attribs","w") do |attribs|
|
||||
attributes.each do |attribute|
|
||||
attribs.puts attribute
|
||||
end
|
||||
end
|
||||
# generate bom2
|
||||
list = `gnetlist -g bom2 -q -o - #{schematic}`
|
||||
# parse bom2
|
||||
regex = /^(?<refdes>(\w+,?)+):(?<attributes>.*):(?<qty>\d+)$/
|
||||
list.each_line do |line|
|
||||
next unless line =~ regex
|
||||
data = line.match regex
|
||||
hash = {refdes: data[:refdes].split(',')}
|
||||
attributes.each_index do |i|
|
||||
hash.merge!({attributes[i] => data[:attributes].split(':')[i]})
|
||||
end
|
||||
to_return << hash
|
||||
end
|
||||
return to_return
|
||||
end
|
||||
CLEAN.include("attribs")
|
||||
|
||||
# ===============
|
||||
# file generation
|
||||
# ===============
|
||||
|
||||
file vsch => sch do |t|
|
||||
sh "cp #{t.prerequisites.join(' ')} #{t.name}"
|
||||
# on \ is to prevent ruby interpreting it, th other is for sed
|
||||
# the version
|
||||
sh "sed -i 's/\\(version=\\)\\$Version\\$/\\1#{version}/' #{vsch}"
|
||||
# the date
|
||||
sh "sed -i 's/\\(date=\\)\\$Date\\$/\\1#{date}/' #{vsch}"
|
||||
# the revision
|
||||
sh "sed -i 's/\\(revision=\\)\\$Revision\\$/\\1#{sch_rev}/' #{vsch}"
|
||||
end
|
||||
|
||||
file "#{target}_schematic.pdf" => vsch do |t|
|
||||
sh "gaf export -f pdf -c -o #{t.name} #{t.prerequisites.join(' ')} 2> /dev/null"
|
||||
end
|
||||
|
||||
file "notes.txt" => vsch do |t|
|
||||
notes_data = bom2(t.prerequisites[0],"note")
|
||||
File.open(t.name,"w") do |notes_file|
|
||||
notes_data.each do |note|
|
||||
next if note["note"]=="unknown"
|
||||
notes_file.puts "#{note[:refdes]*','}:\n#{note["note"]}\n\n"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
; .sch gEDA configuration file
|
||||
(define library "lib")
|
||||
(component-library (build-path library "symbols"))
|
||||
(component-library (build-path library "footprints"))
|
|
@ -0,0 +1,3 @@
|
|||
; gschem configuration file
|
||||
(paper-size 11.69 8.27) ; A4
|
||||
;(output-color "enabled") ; for color postscript output (black background)
|
|
@ -0,0 +1,5 @@
|
|||
# gEDA gsch2pcb configuration file
|
||||
schematics led-controller.sch
|
||||
elements-dir ./lib/footprints
|
||||
output-name led-controller
|
||||
skip-m4
|
|
@ -0,0 +1 @@
|
|||
0
|
Loading…
Reference in New Issue