ext/cm17a_api/cm17a_api.c in x10-cm17a-0.9.0 vs ext/cm17a_api/cm17a_api.c in x10-cm17a-1.0.0

- old
+ new

@@ -30,10 +30,14 @@ static VALUE mX10; static VALUE mCm17a; static VALUE cCm17aController; static VALUE eX10Error; +static VALUE symON; +static VALUE symOFF; +static VALUE symDIM; +static VALUE symBRIGHTEN; /* * call-seq: * X10::Cm17a::Controller.new() * X10::Cm17a::Controller.new(device_name) @@ -60,17 +64,17 @@ * * Send a command to the CM17A controller. The X10 unit to get the * address is given by the +house+ code (0-15) and the +unit+ code * (0-15). The command must be one of the following constants: * - * * <tt>X10::Cm17a::ON</tt> -- Turn the device on. - * * <tt>X10::Cm17a::OFF</tt> -- Turn the device off. - * * <tt>X10::Cm17a::DIM</tt> -- Dim the device by +steps+ steps. - * * <tt>X10::Cm17a::BRIGHT</tt> -- Brighten the device by +steps+ steps. + * * <tt>:on</tt> -- Turn the device on. + * * <tt>:off</tt> -- Turn the device off. + * * <tt>:dim</tt> -- Dim the device by +steps+ steps. + * * <tt>:brighten</tt> -- Brighten the device by +steps+ steps. * - * Note that the unit code is ignored for the <tt>BRIGHT</tt> and - * <tt>DIM</tt> commands. The bright/dim commands will effect the + * Note that the unit code is ignored for the <tt>:brighten</tt> and + * <tt>:dim</tt> commands. The bright/dim commands will effect the * last addressed unit. */ static VALUE cm17a_ruby_command( VALUE self, VALUE rhouse, @@ -78,12 +82,24 @@ VALUE rcommand, VALUE rsteps) { int house = NUM2INT(rhouse); int device = NUM2INT(rdevice); - int command = NUM2INT(rcommand); int steps = NUM2INT(rsteps); + int command; + + if (rcommand == symON) + command = CM17A_ON; + else if (rcommand == symOFF) + command = CM17A_OFF; + else if (rcommand == symDIM) + command = CM17A_DIM; + else if (rcommand == symBRIGHTEN) + command = CM17A_BRIGHTEN; + else + command = NUM2INT(rcommand); + cm17a_command(fd, house, device, command, steps); return Qnil; } /* @@ -101,14 +117,14 @@ mCm17a = rb_define_module_under(mX10, "Cm17a"); cCm17aController = rb_define_class_under(mCm17a, "Controller", rb_cObject); eX10Error = rb_eval_string("X10::X10Error"); + symON = rb_eval_string(":on"); + symOFF = rb_eval_string(":off"); + symDIM = rb_eval_string(":dim"); + symBRIGHTEN = rb_eval_string(":brighton"); + rb_define_method(cCm17aController, "initialize", cm17a_init, -1); rb_define_method(cCm17aController, "close", cm17a_close, 0); rb_define_method(cCm17aController, "command", cm17a_ruby_command, 4); - - rb_define_const(mCm17a, "ON", INT2NUM(CM17A_ON)); - rb_define_const(mCm17a, "OFF", INT2NUM(CM17A_OFF)); - rb_define_const(mCm17a, "BRIGHTEN", INT2NUM(CM17A_BRIGHTEN)); - rb_define_const(mCm17a, "DIM", INT2NUM(CM17A_DIM)); }