Permalink
Browse files

Merge branch 'master' of git@github.com:atduskgreg/rad

  • Loading branch information...
2 parents 93e14c0 + 4767254 commit b0603cd723018b0cff6518cb1168093bacb2300c Greg Borenstein committed Aug 4, 2008
Showing with 28 additions and 29 deletions.
  1. +13 −17 lib/examples/hello_format_print.rb
  2. +3 −3 lib/plugins/blink_m.rb
  3. +12 −9 lib/rad/arduino_sketch.rb
@@ -5,18 +5,12 @@ class HelloFormatPrint < ArduinoSketch
# to do formatted printing. For now there are some absolutes:
# The write_line method atkes as arguemnst the formatting string
# and the appropriate arguments. It format them to an internal
- # buffer called _str which is by default 64 bytes but can be
- # adjusted (see below) and that buffer is pointed to, currently
- # (08/03/2008) a string pointer array with one element "xx[0]"
- # must be declared with that exact name. So to set up to use
- # formatted printing, you must declare the string pointer
- # array "char *xx[1]"
- # then invoke formatted printing
- # formatted_print :buffer_size => 80
+ # buffer sepcified and created when you invoke formatted printing
+ # formatted_print :as => :line_buf, :buffer_size => 80
# now, to actual do it you use write_line
- # write_line "Pies $%02d.%02d", pie_cents/100, pie_cents%100
- # then print the string pointed at by xx[0]
- # my_lcd.setxy 3, 2, xx[0]
+ # write_line "Pies $%02d.%02d", pie_cents/100, pie_cents%100
+ # then print the string pointed at by string_line
+ # my_lcd.setxy 3, 2, line_buf
#
# Brian Riley - Underhill Center, VT, USA Aug 2008
# <brianbr@wulfden.org>
@@ -30,15 +24,16 @@ class HelloFormatPrint < ArduinoSketch
@toggle = "0, int"
@pie_cents = "403, int"
- array "char *xx[1]"
+ @pie_price = "7.08"
+
input_pin 8, :as => :button_one, :device => :button
input_pin 9, :as => :button_two, :device => :button
input_pin 10, :as => :button_three, :device => :button
output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
- formatted_print :buffer_size => 80 # defaults to 64 bytes
+ formatted_print :as => :string_line, :buffer_size => 65
def setup
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
@@ -47,7 +42,7 @@ def setup
def loop
if millis % 500 == 0
write_line "millis()= %ld", millis
- my_lcd.setxy 1, 2, xx[0]
+ my_lcd.setxy 1, 2, string_line
end
say_hello if button_one.read_input
say_more if button_two.read_input
@@ -57,7 +52,7 @@ def loop
def say_hello
@toggle = true
write_line "This sketch has?nbeen running for?n %ld mins and %d secs", millis/60000, (millis/1000)%60
- my_lcd.clearscr xx[0]
+ my_lcd.clearscr string_line
delay 3000
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
end
@@ -66,8 +61,9 @@ def say_more # passing print strings to home and setxy (also works on clearscr)
@toggle = false
my_lcd.clearscr "is indistinguishablefrom magic"
write_line "Pies $%2d.%02d", @pie_cents/100, @pie_cents%100
- my_lcd.setxy 4, 2, xx[0]
- my_lcd.setxy 0,3, "toggle state: "
+# write_line "Pies $%6.2f", @pie_price
+ my_lcd.setxy 4, 2, string_line
+ my_lcd.setxy 0, 3, "toggle state: "
my_lcd.print @toggle
delay 3000
my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
View
@@ -49,7 +49,7 @@ class BlinkM < ArduinoPlugin
}
// Call this first when BlinkM is plugged directly into Arduino
-// The BlinkM's PWR (power) pins should line up with pins 2 and 3 of the connector,
+// The BlinkMs PWR (power) pins should line up with pins 2 and 3 of the connector,
// while the I2C (communications) pins should line up with pins 4 and 5.
static void BlinkM_beginWithPower()
@@ -134,7 +134,7 @@ class BlinkM < ArduinoPlugin
return -1;
}
-// Demonstrates how to verify you're talking to a BlinkM
+// Demonstrates how to verify you-re talking to a BlinkM
// and that you know its address -- message version
static char* blink_m_check_address_message(byte addr) // :as => :optional
@@ -158,7 +158,7 @@ class BlinkM < ArduinoPlugin
return strcat(message, status); // match, everything okay
}
-// Demonstrates how to verify you're talking to a BlinkM
+// Demonstrates how to verify you-re talking to a BlinkM
// and that you know its address -- digital version
static int BlinkM_checkAddress(byte addr)
View
@@ -549,16 +549,19 @@ def serial_begin(opts={})
end
def formatted_print(opts={})
- buffer_size = opts[:buffer_size] ? opts[:buffer_size] : 64
- @@sprintf_inc ||= FALSE
- if @@sprintf_inc == FALSE
- @@sprintf_inc = TRUE
- accessor = []
- accessor << "\n#undef int\n#include <stdio.h>"
- accessor << "char _str[#{buffer_size}];"
- accessor << "#define write_line(...) sprintf(_str,__VA_ARGS__); xx[0] = _str"
- @accessors << accessor.join( "\n" )
+ buffer_size = opts[:buffer_size] ? opts[:buffer_size] : 64
+
+ if opts[:as]
+ @@sprintf_inc ||= FALSE
+ if @@sprintf_inc == FALSE
+ @@sprintf_inc = TRUE
+ accessor = []
+ accessor << "\n#undef int\n#include <stdio.h>"
+ accessor << "#define write_line(...) sprintf(#{opts[:as]},__VA_ARGS__);"
+ @accessors << accessor.join( "\n" )
+ array("char #{opts[:as]}[#{buffer_size}]")
+ end
end
end

0 comments on commit b0603cd

Please sign in to comment.