eisental/Rubyc — Issue #25: wireless display - no method 'intToBitSet' for arguments 
Author: mstram
Created: 2012-02-03 21:45:37+00:00
State: open

Not sure what's going on here

distran1.rb
on init :(NameError) no method 'intToBitSet' for arguments
(org.jruby.RubyNil.org.jruby.RubyFixnum) on Java::OrgTalRedStoneChipsBitSet:BitSetUtils

/home/tcagame/MichaelS/36/plugins/Rubyc/lib/displayControllerXY.rb:52
in paint distran1.rb:106
in paint distran1.rb:141
in cleardisplay org/jruby/RubyRange.java:407
in each distran1.rb:140
in clear display org/jruby/RubyRange.java:407
in each distran1.rb:139
in cleardisplay distran1.rb.66z

===============
```ruby
require 'java'
import 'org.tal.rubychip.RubyCircuit'
require 'lib/displaycontrollerXY'

class Distran1 < RubyCircuit
def init
@board_disp = DisplayControllerXY.new()
#@status_disp = DisplayController.new()
info "(Distran1) args.size = #{args.size}"
x = 0
args.each {|a| info "args[#{x}] = #{a}"
x +=1
}

begin
@board_disp.initdisplay args[0].to_i,args[1].to_i , self, args[2]
rescue Exception
info "(info) (Distran1) @board_disp.initdisplay args[0].to_i,args[1].to_i , self, args[2]"
debug "(debug) (Distran1) @board_disp.initdisplay args[0].to_i,args[1].to_i , self, args[2]"
info "(info) err = #{$!}"
debug "(info) err = #{$!}"
end

@board_disp.clear 0
info "distran1 initialized."

def_color1= 15
def_color2 = 14

info "inputs = " + inputs.size.to_s
info "outputs = " + outputs.size.to_s

@clks = 0
if args.length<2
error("args: width height [color1 color2]")
return false
end

@dispWidth = args[0].to_i
@dispHeight = args[1].to_i
@direction = 1

cleardisplay

@x = 0
@y = 0
@lastX = -1
@lastY = -1

true
end

def input(idx, state)
if idx==0
@clks += 1
if state
step
end
end
end

def step
stepy
# debug((disp2:step) "x=#{@x} y=#{@y}")
if @lastX>=0
paint @lastX, @lastY, @color1
end

paint @x, @y, @color2

@lastX = @x
@lastY = @y
end

def paint(x, y, color)
debug "((disp2:paint) x=#{@x} y=#{@y}"
@board_disp.paint x,y,color
end

def stepy
@y += @direction
if @y>=@dispHeight
@y -= 1
@direction = -@direction
stepx
else
if @y<0
@y = 0
@direction = -@direction
stepx
end
end
end
############################
def stepx
@x += 1
if @x>=@dispWidth
@x = 0
end
end

# sets all display pixels to the background color.
def cleardisplay
for x in 0..@dispWidth-1
for y in 0..@dispHeight-1
paint x, y, @color1
end
end
end

end

Distran1.new()
```

----------------------------------------------------------------------
```ruby
# DisplayCircuit: rubyc class for controlling a display chip.

require 'java'
import 'org.tal.rubychip.RubyCircuit'
import 'org.tal.redstonechips.wireless.Transmitter'
#import 'org.tal.redstonechips.util.BitSet7'
#import 'org.tal.redstonechips.util.BitSetUtils'

import 'org.tal.redstonechips.bitset.BitSetUtils'
import 'org.tal.redstonechips.bitset.BitSet7'

class DisplayControllerXY
attr_reader :width, :height, :x_len, :y_len, :color_len, :tx

def initdisplay(width, height, rbcircuit, channel)
@rbcircuit = rbcircuit
@width = width
@height = height

puts "(DisplayControllerXY:initdisplay) @width = #{@width} @height =#{@height}"
@x_len = calc_bit_length(width)
@y_len = calc_bit_length(height)

if channel!=nil
@tx = Transmitter.new()
@tx.init rbcircuit.sender, channel, 1, rbcircuit.circuit
@color_len = 4
else
@color_len = rbcircuit.outputs.length - @x_len - @y_len - 1
if @color_len<=0
rbcircuit.error "Expecting at least #{@x_len+@y_len+1} outputs."
return false
end
end

rbcircuit.info "Display controller #{width}x#{height}. #{@x_len.to_s} x bits. #{@y_len.to_s} y bits. #{@color_len.to_s} color bits."

true
end

def paint(x, y, color)
if @tx!=nil
begin
xbits = BitSetUtils.intToBitSet x, @x_len
rescue Exception
debug "(displaycontrollerXY:paint) BitSetUtils.intToBitSet x, @x_len"
debug "err = #{$!}"
end

ybits = BitSetUtils.intToBitSet y, @y_len
cbits = BitSetUtils.intToBitSet color, @color_len
bits = BitSet7.new()
for i in 0..@x_len
bits.set i, xbits.get(i)
end

for i in 0..@y_len
bits.set @x_len+i, ybits.get(i)
end

for i in 0..@color_len
bits.set @x_len+@y_len+i, cbits.get(i)
end

begin
@tx.send bits, 0, @x_len+@y_len+@color_len
rescue Exception
puts "error (DisplayControllerXY) @tx.send bits, 0, @x_len+@y_len+@color_len"
puts "#{$!}"
end
else
begin
@rbcircuit.send 1, @x_len, x
@rbcircuit.send 1+@x_len, @y_len, y
@rbcircuit.send 1+@x_len+@y_len, @color_len, color
@rbcircuit.send 0, true
@rbcircuit.send 0, false
rescue Exception
puts "(DisplayControllerXY) send error"
puts "#{$!}"
end
end
end

def clear(color)
# debug "(DisplayControllerXY:clear) @width = #{@width}
for x in 0..@width-1
for y in 0..@height-1
paint x, y, color
end
end
end

def calc_bit_length(maxnum)
return (Math.log(maxnum)/Math.log(2)).ceil;
end
end
```