def software_serial(rx, tx, opts={})
raise ArgumentError, "can only define rx from Fixnum, got #{rx.class}" unless rx.is_a?(Fixnum)
raise ArgumentError, "can only define tx from Fixnum, got #{tx.class}" unless tx.is_a?(Fixnum)
output_pin(tx)
rate = opts[:rate] ? opts[:rate] : 9600
if opts[:as]
@declarations << "SoftwareSerial _#{opts[ :as ]} = SoftwareSerial(#{rx}, #{tx});"
accessor = []
accessor << "SoftwareSerial& #{opts[ :as ]}() {"
accessor << "\treturn _#{opts[ :as ]};"
accessor << "}"
accessor << "int read(SoftwareSerial& s) {"
accessor << "\treturn s.read();"
accessor << "}"
accessor << "void println( SoftwareSerial& s, char* str ) {"
accessor << "\treturn s.println( str );"
accessor << "}"
accessor << "void print( SoftwareSerial& s, char* str ) {"
accessor << "\treturn s.print( str );"
accessor << "}"
accessor << "void println( SoftwareSerial& s, int i ) {"
accessor << "\treturn s.println( i );"
accessor << "}"
accessor << "void print( SoftwareSerial& s, int i ) {"
accessor << "\treturn s.print( i );"
accessor << "}"
@accessors << accessor.join( "\n" )
@signatures << "SoftwareSerial& #{opts[ :as ]}();"
@other_setup << "_#{opts[ :as ]}.begin(#{rate});"
end
end