From WiiLi
//EDmouse Wiimote Rawforces [by marsuten @gmail.com-any improvement is welcome]
//Variables
var.topx = 7 //Maximum speed X <->
var.topy = 12 //Maximum speed Y /\-\/
var.death = 0,1 //Death zone where mouse works
var.rumble = true //Wiimote rumbles when reaches the end
var.freezetime = 300 ms
pie.FrameRate = 100 hz //Leave between 60 and 100 Hz
var.trimx = 10 //Put the wiimote face up and write the
var.trimz = 9 //debug values here
if true //Debug for Trims
debug = "var.trimx: " + wiimote.RawForceX*-1 + " var.trimz: " + Wiimote.RawForceZ*-1
wait 300 ms
endif
//Buttons
mouse.LeftButton = wiimote.A
mouse.RightButton = wiimote.B
//Freeze
var.freeze = KeepDown(Pressed(wiimote.A or wiimote.B),var.freezetime)
// Mouse
//Movement and death zone
if var.active and not var.freeze
mouse.x=smooth((1/(screen.Width/var.x)), 1)
mouse.y=smooth((1/(screen.Height/var.y)), 1)
else
var.x = MapRange(Mouse.x, 0, 1, 1, screen.Width)
var.y = MapRange(Mouse.y, 0, 1, 1, screen.Height)
endif
var.active=not(var.rx>-var.death and var.rx<var.death and var.ry>-var.death and var.ry<var.death)
//Starts where is the pointer
if starting then var.x = MapRange(Mouse.x, 0, 1, 1, screen.Width)
if starting then var.y = MapRange(Mouse.y, 0, 1, 1, screen.Height)
//Rawforces to 1,-1
var.rx=(maprange( Wiimote.RawForceX + var.trimx, 28, -28, -1 , 1))
var.ry=(maprange( Wiimote.RawForceZ + var.trimz, 28, -28, -1 , 1))
//Multiply rawforces
var.x=var.x+smooth(var.rx*var.topx)
var.y=var.y+smooth(var.ry*var.topy)
//Rumble
if var.rumble and var.active then wiimote.Rumble = KeepDown(Pressed(var.x<0 or var.y<0 or var.x>screen.Width or var.y>screen.Height),80 ms)
//Limits
if var.x>screen.Width then var.x=screen.Width
if var.y>screen.Height then var.y=screen.Height
if var.x<0 then var.x=0
if var.y<0 then var.y=0