WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GlovePIE Wii-Mote Scripts
Goto page Previous  1, 2, 3, 4, 5 ... 53, 54, 55  Next
 
Post new topic   Reply to topic    WiiLi.org Forum Index -> GlovePie
View previous topic :: View next topic  
Author Message
Lukeage



Joined: 14 Dec 2006
Posts: 4

Digg It
PostPosted: Thu Dec 14, 2006 3:43 pm    Post subject: Wiimote Joystick/Mouse script

Script for Joystick/Mouse emulation, primaryly designed for MAME to use as a lightgun emulator.

Code:

// Joystick/Mouse script using IR sensor (Single Wiimote v1)
// Designed for use with MAME as a lightgun replacement
// by Lukeage
//
// Thanks to Carl Kenner for GlovePIE and help with the battery
//
// Requires PPJoy to work with the joystick!
//
// This script allows you to utilise both the mouse cursor and a joystick by
// switching between them using the 1 (mouse) and 2 (joystick) buttons on the
// Wiimote. By default, the joystick is set. To use as a lightgun in mame, you
// need to set it up to use a joystick as a lightgun. Setting it to the mouse
// does not work as GlovePIE cannot modify RawImput yet.
//
// Both Modes:
//
// Direction pad is mapped to the direction keys
// - and + together display the battery level on the LEDs
// LEDs indicate the number of the wiimote connected
// 1 = Mouse Mode
// 2 = Joystick Mode
//
// Mouse Mode:
//
// B = Left Mouse Button
// A = Right Mouse Button
// - = Volume Down
// Home = Mute
// + = Volume Up
//
// Joystick Mode:
//
// B = Button 1 (this causes the Wiimote to rumbles)
// A = Button 2
// - = Button 3
// Home = Button 4
// + = Button 5
//
// To add extra Wiimotes, There are a few things you need to add.
//
// 1) var.WiimoteX = X needs to be added (Where X is the new Wiimote number).
//    This is only used to display the correct and obviously is useless after
//    the 4th Wiimote
// 2) The Wiimote Variables need to be duplicated.
// 3) The Entire Wiimote code needs to be copied for each extra Wiimote.
// 4) In both the Wiimote variables and code, Wiimote1 needs to be replaced
//    with WiimoteX.
// 5) ppjoy1 needs to be replaced with ppjoyX.
// 6) mouse needs to be replaced with CursorX if the extra cursor is required.

// General Variables

// Wiimote Orientation
var.Wiimote.Up = 1
var.Wiimote.Right = 2
var.Wiimote.Down = 3
var.Wiimote.Left = 4

// These values are used to make it easy to add any addition Wiimotes. If you
// need to add Wiimotes, just make the new line equals of number of the Wiimote
var.Wiimote1 = 1

// Wiimote Settings

// Wiimote 1 Variables

// Used to change the angle at which the Wiimote direction is detected
var.Wiimote1.Rotation = 7

// You can scale the movement to either speed up the movement or allow for
// better coverage near the edges of the screen
var.Wiimote1.ScaleX = 1.1
var.Wiimote1.ScaleY = 1.1

// Number of pixels the pointer has to move before it is updated
var.Wiimote1.Deadzone = 5

//Adjust these to calibrate your remote
var.Wiimote1.xcal = 3
var.Wiimote1.ycal = -30
var.Wiimote1.zcal = 3

// Wiimote Control

// Wiimote 1 Code

// Debug code
if Wiimote1.One and Wiimote1.Two then
   debug = "Wiimote1 X: " + Wiimote1.RawForceX * -1 + " Wiimote1 Y: " + Wiimote1.RawForceY * -1 + " Wiimote1 Z: " + Wiimote1.RawForceZ * -1
endif

// Show battery meter
if Wiimote1.Minus & Wiimote1.Plus then
   Wiimote1.Report15 = 4 | int(Wiimote1.Rumble) // Thanks to Carl Kenner
   Wiimote1.Leds = 2 ^ ceil(Wiimote1.Battery / 48) - 1 // I assume the max battery value to be 192
else
    // Display which Wiimote is which
   Wiimote1.Leds = 2 ^ (var.Wiimote1 - 1)
endif

// Set the D-Pad to function as the Arrow Keys
if Wiimote1.Up
  Up = True
else
  Up = False
endif

if Wiimote1.Down
  Down = True
else
  Down = False
endif

if Wiimote1.Left
  Left = True
else
  Left = False
endif

if Wiimote1.Right
  Right = True
else
  Right = False
endif

// Set if mouse mode (1) or joystick mode (0)
if Wiimote1.One Then
   var.Wiimote1.Mode = 1
endif

if Wiimote1.Two Then
   var.Wiimote1.Mode = 0
endif

// Calibrate settings
var.Wiimote1.ForceX = Wiimote1.RawForceX + var.Wiimote1.xcal
var.Wiimote1.ForceY = Wiimote1.RawForceY + var.Wiimote1.ycal
var.Wiimote1.ForceZ = Wiimote1.RawForceZ + var.Wiimote1.zcal

// Find Orientation
if var.Wiimote1.ForceY > var.Wiimote1.ycal + var.Rotation then
   var.Wiimote1.Orientation = var.Wiimote.Up
elseif var.Wiimote1.ForceY < var.Wiimote1.ycal - var.Rotation then
   var.Wiimote1.Orientation = var.Wiimote.Down
else
   if var.Wiimote1.ForceX > 0 then
      var.Wiimote1.Orientation = var.Wiimote.Left
   else
      var.Wiimote1.Orientation = var.Wiimote.Right
   endif
endif

// Get absolute screen position
if var.Wiimote1.Orientation == var.Wiimote.Up then
   var.Wiimote1.X = (1024 - ((Wiimote1.Dot1x + Wiimote1.Dot2x) / 2)) / 1024 * Screen.DesktopWidth
   var.Wiimote1.Y = ((Wiimote1.Dot1y + Wiimote1.Dot2y) / 2) / 768 * Screen.DesktopHeight
elseif var.Wiimote1.Orientation == var.Wiimote.Down then
   var.Wiimote1.X = (Wiimote1.Dot1x + Wiimote1.Dot2x) / 2 / 1024 * Screen.DesktopWidth
   var.Wiimote1.Y = (768 - ((Wiimote1.Dot1y + Wiimote1.Dot2y) / 2)) / 768 * Screen.DesktopHeight
elseif var.Wiimote1.Orientation == var.Wiimote.Left then
   var.Wiimote1.X = (Wiimote1.Dot1y) / 768 * Screen.DesktopWidth
   var.Wiimote1.Y = (Wiimote1.Dot1x + Wiimote1.Dot2x) / 2 / 1024 * Screen.DesktopHeight
else
   var.Wiimote1.X = (768 - Wiimote1.Dot1y) / 768 * Screen.DesktopWidth
   var.Wiimote1.Y = (1024 - ((Wiimote1.Dot1x + Wiimote1.Dot2x) / 2)) / 1024 * Screen.DesktopHeight
endif

if var.Wiimote1.Mode then
   // Mouse Buttons
   mouse.LeftButton = Wiimote1.B
   mouse.RightButton = Wiimote1.B
   VolumeDown = Wiimote1.Minus
   VolumeUp = Wiimote1.Plus
   Mute = Wiimote1.Home

   // Set cursor
   if abs(mouse.CursorPosX - var.Wiimote1.X) > var.Wiimote1.Deadzone then
      mouse.CursorPosX = (var.Wiimote1.X - (Screen.DesktopWidth /2)) * var.Wiimote1.ScaleX + (Screen.DesktopWidth / 2)
   endif

   if abs(mouse.CursorPosY - var.Wiimote1.Y) > var.Wiimote1.Deadzone then
     mouse.CursorPosY = (var.Wiimote1.Y - (Screen.DesktopHeight /2)) * var.Wiimote1.ScaleY + (Screen.DesktopHeight / 2)
   endif
else
   // Joystick Buttons
   if not Wiimote1.B then
      var.Wiimote1.Pressed = false
      ppjoy1.Digital0 = false
   endif

   // Use this to only rumble once per press (since we are simulating a gun)
   if Wiimote1.B and not var.Wiimote1.Pressed then
      var.Wiimote1.Pressed = true
      Wiimote1.Rumble = true
      ppjoy1.Digital0 = true
      wait 100ms
      Wiimote1.Rumble = false
      ppjoy1.Digital0 = false
   endif

   // Use these to set coin insert and start buttons
   ppjoy1.Digital1 = Wiimote1.A
   ppjoy1.Digital2 = Wiimote1.Minus
   ppjoy1.Digital3 = Wiimote1.Home
   ppjoy1.Digital4 = Wiimote1.Plus

   // Joystick needs to be between  -1 and 1 so we can't use absolute values directly
   if abs(mouse.CursorPosX - var.Wiimote1.X) > var.Wiimote1.Deadzone then
      ppjoy1.Analog0 = (var.Wiimote1.X - (Screen.DesktopWidth /2)) * var.Wiimote1.ScaleX / (Screen.DesktopWidth / 2)
   endif

   if abs(mouse.CursorPosY - var.Wiimote1.Y) > var.Wiimote1.Deadzone then
     ppjoy1.Analog1 = (var.Wiimote1.Y - (Screen.DesktopHeight /2)) * var.Wiimote1.ScaleY / (Screen.DesktopHeight / 2)
   endif
endif


4 Wiimote version downloadable at http://www.filefactory.com/file/57aec2/
Back to top
View user's profile Send private message
CarlKenner
Site Admin


Joined: 29 Nov 2006
Posts: 614

Digg It
PostPosted: Thu Dec 14, 2006 7:23 pm    Post subject:

Actually sending report 15 won't update the battery level instantly. In this case you would need to press + and - together a second time to get the updated level.
Back to top
View user's profile Send private message Send e-mail
US of Anarchy



Joined: 13 Dec 2006
Posts: 41

Digg It
PostPosted: Thu Dec 14, 2006 9:31 pm    Post subject: Wiimote Midi Conductor

Here's a fun little program I made to screw around with and demonstrate Midi:

Code:
//Wiimote Midi Conductor by Freeman Speaketh/US of Anarchy
//Feel free to modify and redistribute, but leave this here

// set these to the offsets when the wiimote is at rest
// will be different for each wiimote
var.xOffset = 12
var.yOffset = -36
var.zOffset = 14

var.xRot = Wiimote.RawForceX + var.xOffset
var.yRot = Wiimote.RawForceY + var.yOffset
var.zRot = Wiimote.RawForceZ + var.zOffset

if Wiimote.Home
if doubleclicked(Wiimote.Home)
ExitPie
else
wait 200 ms
ExitProgram
endif
endif

if Wiimote.B = 1
wait 250 ms
if Wiimote.B = 0
if Keyboard.Apostrophe = 0
Keyboard.Apostrophe = 1
else
Keyboard.Apostrophe = 0
endif
endif
endif

if Keyboard.Apostrophe = 0
Debug = "Press B "
else
debug = "Instrument = " +var.Instrument + " Pitch = " + var.Pitch + " Rests = " + var.Time

var.Pitch = var.zRot + 60
var.Time = 12 * var.xRot + 300
Midi.Instrument = var.Instrument

Midi.FirstNote = var.Pitch
wait var.Time ms

if Wiimote.Plus =1
if var.Instrument < 129
   var.Instrument = var.Instrument + 1
else
    var.Instrument = 1
endif
else if Wiimote.Minus = 1
if var.Instrument > 0
   var.Instrument = var.Instrument - 1
else
    var.Instrument = 128
endif
else if Wiimote.Minus = 0 and Wiimote.Plus = 0
endif
endif



Controls:
-B to start/stop play
-Tilt up and down to adjust pitch
-Tilt left and right to adjust speed
-Plus and Minus switch instruments
-Home once to stop program, and twice to quit GlovePIE entirely.

Have fun.
Back to top
View user's profile Send private message Send e-mail
Lukeage



Joined: 14 Dec 2006
Posts: 4

Digg It
PostPosted: Thu Dec 14, 2006 11:40 pm    Post subject:

Thanks Carl.

I've updated the script to send the battery level update every 30 seconds. There were also issues with the parameters of Wiimtoes 2-4 which have been fixed. Get the updated 4 Wiimote script at:

http://www.filefactory.com/file/32fc73/
Back to top
View user's profile Send private message
JoCliMe



Joined: 15 Dec 2006
Posts: 16
Location: El Centro, CA

Digg It
PostPosted: Fri Dec 15, 2006 3:52 am    Post subject:

Here's one I made for iTunes for Windows...controls are in the comments
Code:

//            **Coded by JoCliMe**
//       ***iTunes Wiimote for Windows***

//Play/Pause as A button
space = wiimote.A

//Next/previous as Right and Left
control + right = wiimote.right
control + left = wiimote.left

//Volume up, mute, and down as +, home, and -
control + up = wiimote.Plus
control + down = wiimote.minus
control + alt + down = wiimote.Home

//Scrolling up and down as up and down
if wiimote.Up
Up = true
Wait 50 ms
Up = false
endif
if wiimote.Down
Down = true
Wait 50 ms
Down = false
endif

//Play selected song
Enter = wiimote.One

//Show Visualizer
control + T = wiimote.B

//Select All (in case iTunes playlist window loses focus for scrolling
control + A = wiimote.Two





Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Ellises



Joined: 15 Dec 2006
Posts: 1

Digg It
PostPosted: Fri Dec 15, 2006 7:52 am    Post subject: My LED script

Here is a script I made to get a feel for the GlovePIE language and the Wiimote code. It just simplys controls the controller's LEDs.

// Name: Simple LED Lighter
// Version: 0.1
// Author: Ellises
// Description: Made as a test program for myself, it lights the LEDs.
//
// Controls:
// Minus - Light previous LED.
// Plus - Light next LED.
// Home - Turn on/off the LED animation.

if var.setup = 0 then
var.setup = 1
var.lastLeds = 1
var.animate = 0
var.homeDown = 0
var.homePressed = 0
var.aniDir = 1
end if

if wiimote.home then
if var.homeDown = 1 then
var.homePressed = 0
else
var.homePressed = 1
var.homeDown = 1
end if
else
var.homePressed = 0
var.homeDown = 0
end if

if Wiimote.Minus then
if var.lastLeds = 1 then
var.lastLeds = 8
else if var.lastLeds = 2 then
var.lastLeds = 1
else if var.lastLeds = 4 then
var.lastLeds = 2
else if var.lastLeds = 8 then
var.lastLeds = 4
end if
wait 200ms
else if Wiimote.Plus then
if var.lastLeds = 1 then
var.lastLeds = 2
else if var.lastLeds = 2 then
var.lastLeds = 4
else if var.lastLeds = 4 then
var.lastLeds = 8
else if var.lastLeds = 8 then
var.lastLeds = 1
end if
wait 200ms
end if

if var.homePressed = 1 then
//if SingleClicked(wiimote.home) then //<-- SingleClicked() doesn't work as I would like.
if var.animate = 0 then
var.animate = 1
else if var.animate = 1 then
var.animate = 0
end if
end if

if var.animate = 1 then
if var.aniDir = 0 then
if var.lastLeds = 1 then
var.aniDir = 1
else if var.lastLeds = 2 then
var.lastLeds = 1
else if var.lastLeds = 4 then
var.lastLeds = 2
else if var.lastLeds = 8 then
var.lastLeds = 4
end if
else if var.aniDir = 1 then
if var.lastLeds = 1 then
var.lastLeds = 2
else if var.lastLeds = 2 then
var.lastLeds = 4
else if var.lastLeds = 4 then
var.lastLeds = 8
else if var.lastLeds = 8 then
var.aniDir = 0
end if
end if
wait 200ms
end if

wiimote.Leds = var.lastLeds
Back to top
View user's profile Send private message
deceased
Site Admin


Joined: 11 Dec 2006
Posts: 287
Location: Aurora, ON

Digg It
PostPosted: Fri Dec 15, 2006 4:13 pm    Post subject:

If you edit your post, you can select all you code and hit the code button to put [code] [/code] tags around it. Then it will appear all nice and green. Just so you know...
_________________
-deceased-

Wiili - a gnu revolution
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> GlovePie All times are GMT
Goto page Previous  1, 2, 3, 4, 5 ... 53, 54, 55  Next
Page 4 of 55

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group