1 // problem: communication with the event loop
3 // on MacOSX, I could use the EventLoopTimer instead, like in HID
5 // to try: put discovery within thread (so extra command in manager)
11 * Created by Marije Baalman on Fri 18 May 2007.
12 * Copyright (c) 2007 Marije Baalman All rights reserved.
14 SuperCollider real time audio synthesis system
15 Copyright (c) 2002 James McCartney. All rights reserved.
16 http://www.audiosynth.com
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 #include <Carbon/Carbon.h>
39 #include "VMGlobals.h"
40 #include "PyrSymbolTable.h"
41 #include "PyrInterpreter.h"
42 #include "PyrKernel.h"
44 #include "PyrObjectProto.h"
45 #include "PyrPrimitiveProto.h"
46 #include "PyrKernelProto.h"
47 #include "SC_InlineUnaryOp.h"
48 #include "SC_InlineBinaryOp.h"
56 #include <mach/mach.h>
57 #include <mach/mach_error.h>
60 #include "WiiMote_OSX/wiiremote.h"
71 // #include <wiimote.h>
72 // #include <wiimote_api.h>
73 // #include <wiimote_event.h>
74 // #include <wiimote_link.h>
83 //--------- PyrSymbols ------------
84 PyrSymbol
* s_wiiDisconnected
;
85 PyrSymbol
* s_wiiConnected
;
86 PyrSymbol
* s_handleEvent
;
88 PyrSymbol
* s_handleBatteryEvent
;
89 PyrSymbol
* s_handleExtensionEvent
;
90 PyrSymbol
* s_handleNunchukEvent
;
91 PyrSymbol
* s_handleClassicEvent
;
92 PyrSymbol
* s_handleIREvent
;
93 PyrSymbol
* s_handleAccEvent
;
94 PyrSymbol
* s_handleButtonEvent
;
96 static PyrSymbol
* s_wii
= 0;
97 static PyrSymbol
* s_wiiCalibrationInfoClass
= 0;
98 static PyrSymbol
* s_wiiLEDStateClass
= 0;
99 static PyrSymbol
* s_readError
= 0;
101 extern bool compiledOK
;
102 //int gNumberOfWiiDevices = 0;
105 EventLoopTimerRef gWiiTimer
= NULL
; // timer for element data updates
109 // --------------- SC_WII structure --------------
112 SC_WII(PyrObject
*obj
);
118 bool wii_disconnect();
119 int enable( bool enab
);
123 // void set_address( char * addr );
124 // void speaker_init( int format );
129 void handleBatteryEvent( uint8_t battery
);
130 void handleButtonEvent( uint16_t buttons
);
131 void handleAccEvent( uint8_t acc
[3] );
132 void handleIREvent( int id
, cwiid_ir_src ir
);
133 void handleNunchukEvent( struct cwiid_nunchuk_mesg nunchuk
);
134 void handleClassicEvent( struct cwiid_classic_mesg classic
);
135 void handleExtensionEvent( int ext_type
);
138 // void handleBatteryEvent( );
139 // void handleButtonEvent( );
140 // void handleAccEvent( );
141 // void handleIREvent( );
142 // void handleNunchukEvent( );
143 // void handleClassicEvent( );
149 static PyrObject
* getObject(PyrSlot
* slot
)
151 return isKindOfSlot(slot
, s_wii
->u
.classobj
) ? slotRawObject(slot
) : 0;
154 static SC_WII
* getDevice(PyrObject
* obj
)
156 return (SC_WII
*)slotRawPtr(obj
->slots
);
160 WiiRemoteRef m_wiiremote
;
164 cwiid_wiimote_t
*m_wiiremote
;
166 unsigned char rpt_mode
;
167 unsigned char led_state
;
177 // ---------------- SC_WIIManager structure --------------
182 static SC_WIIManager
& instance();
184 int start( float updtime
);
187 cwiid_wiimote_t
* discover();
190 WiiRemoteRef
discover();
193 int add(SC_WII
*dev
);
194 int remove(SC_WII
*dev
);
196 /// kind of private, but used in callback function and getWiiData
211 /// linux specific cwiid functions
212 #define toggle_bit(bf,b) \
217 void set_bit( unsigned char * bf
, unsigned char b
)
220 toggle_bit( *bf
, b
);
223 void clear_bit( unsigned char * bf
, unsigned char b
)
226 toggle_bit( *bf
, b
);
229 cwiid_mesg_callback_t cwiid_callback
;
230 void set_led_state(cwiid_wiimote_t
*wiimote
, unsigned char led_state
);
231 void set_rpt_mode(cwiid_wiimote_t
*wiimote
, unsigned char rpt_mode
);
234 void err(cwiid_wiimote_t
*wiimote
, const char *s
, va_list ap
)
236 if (wiimote
) printf("%d:", cwiid_get_id(wiimote
));
242 void set_led_state(cwiid_wiimote_t
*wiimotet
, unsigned char led_state
)
244 // printf( "set_led_state %i\n", led_state );
245 if (cwiid_set_led(wiimotet
, led_state
)) {
246 post( "WII Error: Unable to set led state\n");
250 void set_rpt_mode(cwiid_wiimote_t
*wiimotet
, unsigned char rpt_mode
)
252 if (cwiid_set_rpt_mode(wiimotet
, rpt_mode
)) {
253 post( "WII Error: Unable to set report mode\n");
260 void GetWii_Events();
261 static pascal void IdleTimerWii (EventLoopTimerRef inTimer
, void* userData
);
262 static EventLoopTimerUPP
GetTimerUPPWii (void);
264 static pascal void IdleTimerWii (EventLoopTimerRef inTimer
, void* userData
)
266 #pragma unused (inTimer, userData)
270 static EventLoopTimerUPP
GetTimerUPPWii (void)
272 static EventLoopTimerUPP sTimerUPP
= NULL
;
274 if (sTimerUPP
== NULL
)
275 sTimerUPP
= NewEventLoopTimerUPP (IdleTimerWii
);
283 //------------ SC_WIIManager functions --------
284 SC_WIIManager
& SC_WIIManager::instance()
286 static SC_WIIManager instance
;
290 SC_WIIManager::SC_WIIManager()
299 NumVersion outSoftwareVersion
;
300 BluetoothHCIVersionInfo outHardwareVersion
;
302 // post("aka.wiiremote 1.0B6-UB by Masayuki Akamatsu");
304 if (IOBluetoothGetVersion(&outSoftwareVersion
, &outHardwareVersion
)==kIOReturnSuccess
)
306 if (outSoftwareVersion
.majorRev
< 1 && outSoftwareVersion
.minorAndBugRev
< 0x63)
308 error("WII: requires Bluetooth version 1.6.3 or later.");
314 error("WII: can't get Bluetooth version.");
321 SC_WIIManager::~SC_WIIManager()
326 RemoveEventLoopTimer(gWiiTimer
);
332 int SC_WIIManager::start( float updtime
)
335 /// nothing to do for Linux
338 m_updatetime
= (updtime
/ 1000); // convert to seconds
339 post( "WII: eventloop updatetime %f\n", m_updatetime
);
340 //double eventtime = (double) updtime;
343 RemoveEventLoopTimer(gWiiTimer
);
346 InstallEventLoopTimer (GetCurrentEventLoop(), 0, (EventTimerInterval
) m_updatetime
, GetTimerUPPWii (), 0, &gWiiTimer
);
353 cwiid_wiimote_t
* SC_WIIManager::discover()
355 bdaddr_t bdaddr
= {0, 0, 0, 0, 0, 0};
356 cwiid_wiimote_t
* wiimotediscovered
;
358 if ( (wiimotediscovered
= cwiid_open(&bdaddr
, 0)) == NULL
) {
361 if (cwiid_set_mesg_callback(wiimotediscovered
, cwiid_callback
)) {
362 post("ERROR: WII: Unable to set message callback\n");
363 if ( cwiid_close(wiimotediscovered
) ){
364 post("ERROR: WII: Unable to close Wii\n");
369 /// adding these as devices in the primitive! this is the only way to be able to connect, as the connection uses much more info than I thought!
371 return( wiimotediscovered
);
376 WiiRemoteRef
SC_WIIManager::discover()
378 /* WiiRemoteRef newwii;
380 newwii = (WiiRemoteRef)malloc(sizeof(WiiRemoteRec));
383 wiiremote_init(newwii);
385 result = wiiremote_search( newwii, address); // start searching the device
387 post("WII: searching wiimote %i\n",result);
396 int SC_WIIManager::stop()
398 /// nothing to do on LINUX
402 RemoveEventLoopTimer(gWiiTimer
);
409 int SC_WIIManager::add(SC_WII
* dev
)
411 // post("WII: SC_WIIManager::add\n");
413 if (dev
->m_next
) return false;
414 if (m_devices
== dev
) {
418 dev
->m_next
= m_devices
;
423 dev
->id
= cwiid_get_id( dev
->m_wiiremote
);
425 if (cwiid_enable(dev
->m_wiiremote
, CWIID_FLAG_MESG_IFC
)) {
426 post("ERROR: WII: Unable to enable Wii\n");
429 dev
->rpt_mode
= CWIID_RPT_STATUS
;
431 set_rpt_mode( dev
->m_wiiremote
, dev
->rpt_mode
);
432 set_led_state( dev
->m_wiiremote
, dev
->led_state
);
436 // dev->wii_connect();
443 int SC_WIIManager::remove(SC_WII
* dev
)
445 SC_WII
*prev
= 0, *cur
= m_devices
;
449 if (prev
) prev
->m_next
= dev
->m_next
;
450 else m_devices
= dev
->m_next
;
463 void cwiid_callback(cwiid_wiimote_t
*wiimotet
, int mesg_count
,
464 union cwiid_mesg mesg
[], struct timespec
*timestamp
)
470 SC_WII
*dev
= SC_WIIManager::instance().m_devices
;
473 thisid
= cwiid_get_id( wiimotet
);
475 if ( thisid
== dev
->id
)
482 for (i
=0; i
< mesg_count
; i
++)
484 switch (mesg
[i
].type
) {
485 case CWIID_MESG_STATUS
:
486 dev
->handleBatteryEvent( mesg
[i
].status_mesg
.battery
);
487 dev
->handleExtensionEvent( mesg
[i
].status_mesg
.ext_type
);
490 dev
->handleButtonEvent( mesg
[i
].btn_mesg
.buttons
);
493 dev
->handleAccEvent( mesg
[i
].acc_mesg
.acc
);
496 for (j
= 0; j
< CWIID_IR_SRC_COUNT
; j
++) {
497 dev
->handleIREvent( j
, mesg
[i
].ir_mesg
.src
[j
] );
500 case CWIID_MESG_NUNCHUK
:
501 dev
->handleNunchukEvent( mesg
[i
].nunchuk_mesg
);
503 case CWIID_MESG_CLASSIC
:
504 dev
->handleClassicEvent( mesg
[i
].classic_mesg
);
506 case CWIID_MESG_ERROR
:
511 post("WII: Unknown Report");
519 void GetWii_Events (){
520 SC_WII
*dev
= SC_WIIManager::instance().m_devices
;
525 // post( "WII: device %i, t %p, w %p, n %p\n", debugcnt, dev, dev->m_wiiremote, dev->m_next);
527 if ( dev
->m_wiiremote
!= NULL
)
529 connection
= wiiremote_isconnected(dev
->m_wiiremote
);
530 if ( dev
->m_connected
== false && connection
== true) // if the device is connected, but wasn't before
532 // post( "WII: wiimote got connected\n");
533 wiiremote_getstatus(dev
->m_wiiremote
);
536 else if (dev
->m_connected
== true && connection
== false) // if device was disconnected
538 // post( "WII: wiimote got disconnected\n");
541 else if ( dev
->m_searching
> 0 )
545 if ( dev
->m_connected
) {
546 // post( "WII: wiimote is connected\n");
547 wiiremote_getstatus(dev
->m_wiiremote
);
551 // post("WII: wiimote not connected\n");
556 // post("WII: read error\n");
564 //---------------- SC_WII functions -----------------
566 SC_WII::SC_WII(PyrObject
* obj
)
577 SetPtr(obj
->slots
+0, this);
588 m_wiiremote
= (WiiRemoteRef
)malloc(sizeof(WiiRemoteRec
));
589 if (m_wiiremote
!= NULL
)
591 wiiremote_init(m_wiiremote
);
592 m_wiiremote
->isMotionSensorEnabled
= true;
593 m_wiiremote
->isIRSensorEnabled
= false;
594 m_wiiremote
->isVibrationEnabled
= false;
595 m_wiiremote
->isExpansionPortEnabled
= false;
596 m_wiiremote
->isLED1Illuminated
= false;
597 m_wiiremote
->isLED2Illuminated
= false;
598 m_wiiremote
->isLED3Illuminated
= false;
599 m_wiiremote
->isLED4Illuminated
= false;
602 // return SC_WIIManager::instance().add(this);
606 // m_wiiremote = (wiimote_t*)malloc(sizeof(wiimote_t));
607 // m_report = (wiimote_report_t)malloc(sizeof(wiimote_report_t));
608 // if ( m_wiiremote != NULL )
610 // *m_wiiremote = WIIMOTE_INIT;
611 // m_report = WIIMOTE_REPORT_INIT;
612 // m_connected = false;
613 // return SC_WIIManager::instance().add(this);
621 if (m_wiiremote
!= NULL
)
624 if (wiiremote_isconnected(m_wiiremote
))
625 wiiremote_disconnect(m_wiiremote
);
626 ; //m_wiiremote, sizeof(WiiRemoteRec));
631 if ( cwiid_close( m_wiiremote
) ){
632 // m_wiiremote = NULL;
633 post( "error closing device\n" );
639 // if (wiimote_is_open(m_wiiremote))
640 // wiimote_disconnect(m_wiiremote);
644 // SetNil(m_obj->slots+0);
645 return SC_WIIManager::instance().remove(this);
648 bool SC_WII::wii_connect()
651 if (wiiremote_isconnected(m_wiiremote
))
653 post("WII: wiimote is already connected\n");
659 result
= wiiremote_search( m_wiiremote
, m_address
); // start searching the device
661 post("WII: searching wiimote %i\n",result
);
669 // if (wiimote_connect(m_wiiremote, m_address) < 0) {
670 // post("WII: unable to open wiimote: %s at address %s\n", wiimote_get_error(), m_address);
671 // post("WII: unable to open wiimote at address %s\n",m_address);
672 // m_connected = false;
677 return( m_connected
);
680 void SC_WII::connected()
686 result
= wiiremote_led( m_wiiremote
, 0, 0, 0, 0);
690 // post("WII: wiiremote connected\n");
691 pthread_mutex_lock(&gLangMutex
);
693 VMGlobals
* g
= gMainVMGlobals
;
694 g
->canCallOS
= false;
695 ++g
->sp
; SetObject(g
->sp
, m_obj
);
696 runInterpreter(g
, s_wiiConnected
, 1);
697 g
->canCallOS
= false;
699 pthread_mutex_unlock(&gLangMutex
);
702 bool SC_WII::wii_disconnect()
706 /// TODO: remove from wii_manager
709 wiiremote_stopsearch( m_wiiremote
);
710 result
= wiiremote_disconnect( m_wiiremote
);
713 // result = wiimote_disconnect(m_wiiremote);
716 // call disconnect action
722 int SC_WII::enable( bool enab
)
726 if (cwiid_enable(m_wiiremote
, CWIID_FLAG_MESG_IFC
)) {
730 if (cwiid_disable(m_wiiremote
, CWIID_FLAG_MESG_IFC
)) {
739 void SC_WII::disconnected()
743 pthread_mutex_lock(&gLangMutex
);
745 VMGlobals
* g
= gMainVMGlobals
;
746 g
->canCallOS
= false;
747 ++g
->sp
; SetObject(g
->sp
, m_obj
);
748 runInterpreter(g
, s_wiiDisconnected
, 1);
749 g
->canCallOS
= false;
751 pthread_mutex_unlock(&gLangMutex
);
754 // void SC_WII::speaker_init( int format )
756 // if ( format == 4 )
757 // wiimote_speaker_init(m_wiiremote, WIIMOTE_FMT_S4, 0xff);
758 // else if ( format == 8 )
759 // wiimote_speaker_init(m_wiiremote, WIIMOTE_FMT_S8, 0xff);
762 void SC_WII::get_address()
765 if (m_wiiremote
->device
== NULL
)
772 wiiremote_getaddress(m_wiiremote
, str
);
773 strcpy(m_address
, str
);
778 // bool SC_WII::update()
780 // if (wiimote_update(m_wiiremote) < 0) {
781 // wiimote_disconnect(m_wiiremote);
782 // post( "WII: wiimote got disconnected\n");
789 // void SC_WII::set_address( char * addr )
791 // strcpy( m_address, addr );
792 // // post( "WII: addr %s, m_address %s\n", addr, m_address );
796 void SC_WII::handleEvent()
798 if (m_wiiremote
->device
== NULL
)
799 return; // do nothing
801 pthread_mutex_lock(&gLangMutex
);
803 VMGlobals
* g
= gMainVMGlobals
;
804 g
->canCallOS
= false;
805 ++g
->sp
; SetObject(g
->sp
, m_obj
);
807 // post( "buttondata %i\n", m_wiiremote->buttonData);
808 // ++g->sp; SetInt(g->sp, m_wiiremote->buttonData);
809 PyrObject
*butArray
= newPyrArray(g
->gc
, 11 * sizeof(int), 0, true);
810 PyrSlot
*butArraySlots
= butArray
->slots
;
811 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0008 & m_wiiremote
->buttonData
) > 0) ); //A
812 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0004 & m_wiiremote
->buttonData
) > 0) ); //B
813 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0002 & m_wiiremote
->buttonData
) > 0) ); //1
814 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0001 & m_wiiremote
->buttonData
) > 0) ); //2
815 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0010 & m_wiiremote
->buttonData
) > 0) ); //minus
816 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0080 & m_wiiremote
->buttonData
) > 0) ); //home
817 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x1000 & m_wiiremote
->buttonData
) > 0) ); // plus
818 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0800 & m_wiiremote
->buttonData
) > 0) ); // up
819 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0400 & m_wiiremote
->buttonData
) > 0) ); // down
820 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0100 & m_wiiremote
->buttonData
) > 0) ); // left
821 SetInt(butArray
->slots
+butArray
->size
++, (int) ((0x0200 & m_wiiremote
->buttonData
) > 0) ); // right
823 ++g
->sp
; SetObject(g
->sp
, butArray
);
826 if (m_wiiremote
->isIRSensorEnabled
)
828 ++g
->sp
; SetFloat(g
->sp
, m_wiiremote
->posX
);
829 ++g
->sp
; SetFloat(g
->sp
, m_wiiremote
->posY
);
830 ++g
->sp
; SetFloat(g
->sp
, m_wiiremote
->angle
);
831 ++g
->sp
; SetInt(g
->sp
, m_wiiremote
->tracking
);
833 ++g
->sp
; SetFloat(g
->sp
, 0);
834 ++g
->sp
; SetFloat(g
->sp
, 0);
835 ++g
->sp
; SetFloat(g
->sp
, 0);
836 ++g
->sp
; SetInt(g
->sp
, 0);
838 if (m_wiiremote
->isMotionSensorEnabled
)
840 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->accX
/ 256);
841 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->accY
/ 256);
842 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->accZ
/ 256);
843 ++g
->sp
; SetInt(g
->sp
, m_wiiremote
->orientation
);
845 ++g
->sp
; SetFloat(g
->sp
, 0);
846 ++g
->sp
; SetFloat(g
->sp
, 0);
847 ++g
->sp
; SetFloat(g
->sp
, 0);
848 ++g
->sp
; SetInt(g
->sp
, 0);
850 if (m_wiiremote
->isExpansionPortAttached
&& m_wiiremote
->isExpansionPortEnabled
)
852 ++g
->sp
; SetInt(g
->sp
, m_wiiremote
->expType
);
853 // Classic Controller
854 if (m_wiiremote
->expType
== WiiClassicController
)
857 //++g->sp; SetInt(g->sp, m_wiiremote->cButtonData);
858 PyrObject
*outArray
= newPyrArray(g
->gc
, 15 * sizeof(char), 0, true);
859 PyrSlot
*outArraySlots
= outArray
->slots
;
860 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0008 & m_wiiremote
->cButtonData
) > 0) ); //X
861 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0020 & m_wiiremote
->cButtonData
) > 0) ); //Y
862 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0010 & m_wiiremote
->cButtonData
) > 0) ); //A
863 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0040 & m_wiiremote
->cButtonData
) > 0) ); //B
864 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x2000 & m_wiiremote
->cButtonData
) > 0) ); //L
866 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0200 & m_wiiremote
->cButtonData
) > 0) ); //R
867 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0080 & m_wiiremote
->cButtonData
) > 0) ); //ZL
868 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0004 & m_wiiremote
->cButtonData
) > 0) ); //ZR
869 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0001 & m_wiiremote
->cButtonData
) > 0) ); //Up
870 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x4000 & m_wiiremote
->cButtonData
) > 0) ); //Down
872 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0002 & m_wiiremote
->cButtonData
) > 0) ); //Left
873 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x8000 & m_wiiremote
->cButtonData
) > 0) );//Right
874 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x1000 & m_wiiremote
->cButtonData
) > 0) );//Minus
875 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0800 & m_wiiremote
->cButtonData
) > 0) );//Home
876 SetInt(outArray
->slots
+outArray
->size
++, (int) ((0x0400 & m_wiiremote
->cButtonData
) > 0) );//Plus
879 ++g
->sp
; SetObject(g
->sp
, outArray
);
882 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->cStickX1
/ 0x3F);
883 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->cStickY1
/ 0x3F);
886 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->cStickX2
/ 0x1F);
887 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->cStickY2
/ 0x1F);
890 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->cAnalogL
/ 0x1F);
891 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->cAnalogR
/ 0x1F);
894 if (m_wiiremote
->expType
== WiiNunchuk
)
897 //++g->sp; SetInt(g->sp, m_wiiremote->nButtonData);
898 PyrObject
*butArrayN
= newPyrArray(g
->gc
, 2 * sizeof(int), 0, true);
899 PyrSlot
*butArraySlotsN
= butArrayN
->slots
;
900 SetInt(butArrayN
->slots
+butArrayN
->size
++, (int) ((0x01 & m_wiiremote
->nButtonData
) < 1) );
901 SetInt(butArrayN
->slots
+butArrayN
->size
++, (int) ((0x02 & m_wiiremote
->nButtonData
) < 1) );
903 ++g
->sp
; SetObject(g
->sp
, butArrayN
);
906 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->nStickX
/ 256);
907 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->nStickY
/ 256);
910 if (m_wiiremote
->isMotionSensorEnabled
)
912 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->nAccX
/ 256);
913 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->nAccY
/ 256);
914 ++g
->sp
; SetFloat(g
->sp
, (float) m_wiiremote
->nAccZ
/ 256);
915 ++g
->sp
; SetInt(g
->sp
, m_wiiremote
->nOrientation
);
917 ++g
->sp
; SetFloat(g
->sp
, 0);
918 ++g
->sp
; SetFloat(g
->sp
, 0);
919 ++g
->sp
; SetFloat(g
->sp
, 0);
920 ++g
->sp
; SetInt(g
->sp
, 0);
924 ++g
->sp
; SetInt(g
->sp
, 0);
925 ++g
->sp
; SetInt(g
->sp
, 0);
926 ++g
->sp
; SetInt(g
->sp
, 0);
927 ++g
->sp
; SetInt(g
->sp
, 0);
928 ++g
->sp
; SetInt(g
->sp
, 0);
929 ++g
->sp
; SetInt(g
->sp
, 0);
930 ++g
->sp
; SetInt(g
->sp
, 0);
931 ++g
->sp
; SetInt(g
->sp
, 0);
933 ++g
->sp
; SetFloat(g
->sp
, m_wiiremote
->batteryLevel
);
934 runInterpreter(g
, s_handleEvent
, 19);
935 g
->canCallOS
= false;
937 pthread_mutex_unlock(&gLangMutex
);
942 void SC_WII::handleBatteryEvent( uint8_t battery
){
943 pthread_mutex_lock(&gLangMutex
);
945 VMGlobals
* g
= gMainVMGlobals
;
946 g
->canCallOS
= false;
947 ++g
->sp
; SetObject(g
->sp
, m_obj
);
948 ++g
->sp
; SetFloat(g
->sp
, (float) battery
/ CWIID_BATTERY_MAX
);
949 runInterpreter(g
, s_handleBatteryEvent
, 2);
950 g
->canCallOS
= false;
952 pthread_mutex_unlock(&gLangMutex
);
957 void SC_WII::handleExtensionEvent( int ext_type
){
958 pthread_mutex_lock(&gLangMutex
);
960 VMGlobals
* g
= gMainVMGlobals
;
961 g
->canCallOS
= false;
962 ++g
->sp
; SetObject(g
->sp
, m_obj
);
963 ++g
->sp
; SetInt(g
->sp
, ext_type
);
964 runInterpreter(g
, s_handleExtensionEvent
, 2);
965 g
->canCallOS
= false;
967 pthread_mutex_unlock(&gLangMutex
);
972 void SC_WII::handleButtonEvent( uint16_t buttons
){
973 pthread_mutex_lock(&gLangMutex
);
975 VMGlobals
* g
= gMainVMGlobals
;
976 g
->canCallOS
= false;
977 ++g
->sp
; SetObject(g
->sp
, m_obj
);
979 // post( "handle Button Event\n" );
982 // ++g->sp; SetInt(g->sp, (int) buttons );
983 PyrObject
*outArray
= newPyrArray(g
->gc
, 11 * sizeof(int), 0, true);
984 PyrSlot
*outArraySlots
= outArray
->slots
;
985 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_A
& buttons
) > 0) );
986 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_B
& buttons
) > 0) );
987 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_1
& buttons
) > 0) );
988 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_2
& buttons
) > 0) );
989 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_MINUS
& buttons
) > 0) );
990 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_HOME
& buttons
) > 0) );
991 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_PLUS
& buttons
) > 0) );
992 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_UP
& buttons
) > 0) );
993 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_DOWN
& buttons
) > 0) );
994 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_LEFT
& buttons
) > 0) );
995 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_BTN_RIGHT
& buttons
) > 0) );
997 ++g
->sp
; SetObject(g
->sp
, outArray
);
999 runInterpreter(g
, s_handleButtonEvent
, 2);
1000 g
->canCallOS
= false;
1002 pthread_mutex_unlock(&gLangMutex
);
1007 void SC_WII::handleAccEvent( uint8_t acc
[3] ){
1008 pthread_mutex_lock(&gLangMutex
);
1010 VMGlobals
* g
= gMainVMGlobals
;
1011 g
->canCallOS
= false;
1012 ++g
->sp
; SetObject(g
->sp
, m_obj
);
1013 ++g
->sp
; SetFloat(g
->sp
, (float) acc
[CWIID_X
]/CWIID_ACC_MAX
);
1014 ++g
->sp
; SetFloat(g
->sp
, (float) acc
[CWIID_Y
]/CWIID_ACC_MAX
);
1015 ++g
->sp
; SetFloat(g
->sp
, (float) acc
[CWIID_Z
]/CWIID_ACC_MAX
);
1016 runInterpreter(g
, s_handleAccEvent
, 4);
1017 g
->canCallOS
= false;
1019 pthread_mutex_unlock(&gLangMutex
);
1024 void SC_WII::handleNunchukEvent( struct cwiid_nunchuk_mesg nunchuk
){
1025 pthread_mutex_lock(&gLangMutex
);
1027 VMGlobals
* g
= gMainVMGlobals
;
1028 g
->canCallOS
= false;
1029 ++g
->sp
; SetObject(g
->sp
, m_obj
);
1031 PyrObject
*outArray
= newPyrArray(g
->gc
, 2 * sizeof(int), 0, true);
1032 PyrSlot
*outArraySlots
= outArray
->slots
;
1033 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_NUNCHUK_BTN_Z
& nunchuk
.buttons
) > 0) );
1034 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_NUNCHUK_BTN_C
& nunchuk
.buttons
) > 0) );
1036 ++g
->sp
; SetObject(g
->sp
, outArray
);
1037 // ++g->sp; SetInt(g->sp, (int) nunchuk.buttons);
1038 ++g
->sp
; SetFloat(g
->sp
, (float) nunchuk
.stick
[CWIID_X
]/256);
1039 ++g
->sp
; SetFloat(g
->sp
, (float) nunchuk
.stick
[CWIID_Y
]/256);
1040 ++g
->sp
; SetFloat(g
->sp
, (float) nunchuk
.acc
[CWIID_X
]/CWIID_ACC_MAX
);
1041 ++g
->sp
; SetFloat(g
->sp
, (float) nunchuk
.acc
[CWIID_Y
]/CWIID_ACC_MAX
);
1042 ++g
->sp
; SetFloat(g
->sp
, (float) nunchuk
.acc
[CWIID_Z
]/CWIID_ACC_MAX
);
1043 runInterpreter(g
, s_handleNunchukEvent
, 7);
1044 g
->canCallOS
= false;
1046 pthread_mutex_unlock(&gLangMutex
);
1051 void SC_WII::handleClassicEvent( struct cwiid_classic_mesg classic
){
1052 pthread_mutex_lock(&gLangMutex
);
1054 VMGlobals
* g
= gMainVMGlobals
;
1055 g
->canCallOS
= false;
1056 ++g
->sp
; SetObject(g
->sp
, m_obj
);
1057 PyrObject
*outArray
= newPyrArray(g
->gc
, 15 * sizeof(char), 0, true);
1058 PyrSlot
*outArraySlots
= outArray
->slots
;
1059 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_X
& classic
.buttons
) > 0) );
1060 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_Y
& classic
.buttons
) > 0) );
1061 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_A
& classic
.buttons
) > 0) );
1062 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_B
& classic
.buttons
) > 0) );
1063 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_L
& classic
.buttons
) > 0) );
1065 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_R
& classic
.buttons
) > 0) );
1066 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_ZL
& classic
.buttons
) > 0) );
1067 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_ZR
& classic
.buttons
) > 0) );
1068 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_UP
& classic
.buttons
) > 0) );
1069 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_DOWN
& classic
.buttons
) > 0) );
1071 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_LEFT
& classic
.buttons
) > 0) );
1072 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_RIGHT
& classic
.buttons
) > 0) );
1073 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_MINUS
& classic
.buttons
) > 0) );
1074 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_HOME
& classic
.buttons
) > 0) );
1075 SetInt(outArray
->slots
+outArray
->size
++, (int) ((CWIID_CLASSIC_BTN_PLUS
& classic
.buttons
) > 0) );
1077 outArray
->size
= 15;
1078 ++g
->sp
; SetObject(g
->sp
, outArray
);
1080 // ++g->sp; SetInt(g->sp, (int) classic.buttons);
1081 ++g
->sp
; SetFloat(g
->sp
, (float) classic
.l_stick
[CWIID_X
]/CWIID_CLASSIC_L_STICK_MAX
);
1082 ++g
->sp
; SetFloat(g
->sp
, (float) classic
.l_stick
[CWIID_Y
]/CWIID_CLASSIC_L_STICK_MAX
);
1083 ++g
->sp
; SetFloat(g
->sp
, (float) classic
.r_stick
[CWIID_X
]/CWIID_CLASSIC_R_STICK_MAX
);
1084 ++g
->sp
; SetFloat(g
->sp
, (float) classic
.r_stick
[CWIID_Y
]/CWIID_CLASSIC_R_STICK_MAX
);
1085 ++g
->sp
; SetFloat(g
->sp
, (float) classic
.l
/CWIID_CLASSIC_LR_MAX
);
1086 ++g
->sp
; SetFloat(g
->sp
, (float) classic
.r
/CWIID_CLASSIC_LR_MAX
);
1087 runInterpreter(g
, s_handleClassicEvent
, 8);
1088 g
->canCallOS
= false;
1090 pthread_mutex_unlock(&gLangMutex
);
1095 void SC_WII::handleIREvent( int id
, cwiid_ir_src ir
){
1096 pthread_mutex_lock(&gLangMutex
);
1098 VMGlobals
* g
= gMainVMGlobals
;
1099 g
->canCallOS
= false;
1100 ++g
->sp
; SetObject(g
->sp
, m_obj
);
1101 ++g
->sp
; SetInt(g
->sp
, id
);
1102 ++g
->sp
; SetInt(g
->sp
, ir
.valid
);
1103 ++g
->sp
; SetFloat(g
->sp
, (float) ir
.pos
[CWIID_X
]/CWIID_IR_X_MAX
);
1104 ++g
->sp
; SetFloat(g
->sp
, (float) ir
.pos
[CWIID_Y
]/CWIID_IR_Y_MAX
);
1105 ++g
->sp
; SetFloat(g
->sp
, (float) ir
.size
/256);
1106 runInterpreter(g
, s_handleIREvent
, 6);
1107 g
->canCallOS
= false;
1109 pthread_mutex_unlock(&gLangMutex
);
1113 void SC_WII::readError()
1115 pthread_mutex_lock(&gLangMutex
);
1117 VMGlobals
* g
= gMainVMGlobals
;
1118 g
->canCallOS
= false;
1119 ++g
->sp
; SetObject(g
->sp
, m_obj
);
1120 runInterpreter(g
, s_readError
, 1);
1121 g
->canCallOS
= false;
1123 pthread_mutex_unlock(&gLangMutex
);
1124 // SC_WIIManager::instance().remove( this );
1129 //------------ primitives ---------------
1131 int prWii_Start(VMGlobals
* g
, int numArgsPushed
)
1135 PyrSlot
* args
= g
->sp
- 1;
1136 // PyrSlot* args = g->sp;
1138 err
= slotFloatVal(args
+1, &updtime
);
1139 if (err
) return err
;
1141 post( "update time %f", updtime
);
1143 // if (!g->canCallOS) return errCantCallOS;
1144 // return SC_WIIManager::instance().start();
1145 return SC_WIIManager::instance().start(updtime
);
1148 int prWii_Stop(VMGlobals
* g
, int numArgsPushed
)
1150 // if (!g->canCallOS) return errCantCallOS;
1151 return SC_WIIManager::instance().stop();
1154 int prWii_Discover(VMGlobals
* g
, int numArgsPushed
)
1158 PyrSlot
* args
= g
->sp
- 1;
1160 err
= slotIntVal(args
, &curid
);
1161 if (err
) return err
;
1163 if (!isKindOfSlot(args
+1, class_array
))
1164 return errWrongType
;
1165 PyrObject
* allDevsArray
= slotRawObject(&args
[1]);
1166 PyrSlot
* slotsArray
= allDevsArray
->slots
;
1169 cwiid_wiimote_t
* thiswii
;
1171 thiswii
= SC_WIIManager::instance().discover();
1172 if ( thiswii
== NULL
){
1174 post( "no device found\n" );
1179 if ( !isKindOfSlot(slotsArray
+curid
, s_wii
->u
.classobj
) ) {
1181 return errWrongType
;
1183 PyrObject
* obj
= SC_WII::getObject(slotsArray
+curid
);
1184 SC_WII
* dev
= SC_WII::getDevice(obj
);
1190 // post( "dev %p, wii %p\n", dev, dev->m_wiiremote );
1192 // if (!dev) return errFailed;
1193 // free( dev->m_wiiremote );
1195 dev
->m_wiiremote
= thiswii
;
1197 if ( SC_WIIManager::instance().add( dev
) ) {
1198 post( "device added\n" );
1202 post( "device was already added\n" );
1208 int prWii_Open(VMGlobals
*g
, int numArgsPushed
)
1210 PyrSlot
* args
= g
->sp
;
1213 PyrObject
* obj
= SC_WII::getObject(args
+0);
1214 if (!obj
) return errWrongType
;
1216 SC_WII
* dev
= new SC_WII(obj
);
1226 int prWii_Close(VMGlobals
*g
, int numArgsPushed
)
1228 PyrSlot
* args
= g
->sp
;
1230 PyrObject
* obj
= SC_WII::getObject(args
+0);
1231 if (!obj
) return errWrongType
;
1233 SC_WII
* dev
= SC_WII::getDevice(obj
);
1234 if (!dev
) return errFailed
;
1236 return dev
->close();
1239 int prWiiAddress(VMGlobals
*g
, int numArgsPushed
)
1241 PyrSlot
* args
= g
->sp
;
1244 PyrObject
* obj
= SC_WII::getObject(args
+0);
1245 if (!obj
) return errWrongType
;
1247 SC_WII
* dev
= SC_WII::getDevice(obj
);
1248 if (!dev
) return errFailed
;
1252 SetSymbol(args
, getsym(dev
->m_address
));
1258 // int prWiiSetAddress(VMGlobals *g, int numArgsPushed)
1260 // PyrSlot* args = g->sp - 1;
1263 // PyrObject* obj = SC_WII::getObject(args+0);
1264 // if (!obj) return errWrongType;
1266 // SC_WII* dev = SC_WII::getDevice(obj);
1267 // if (!dev) return errFailed;
1275 // err = slotStrVal(args+1, path, sizeof(path));
1276 // if (err) return err;
1277 // // post( "WII: address %s\n", path );
1279 // dev->set_address( path );
1284 int prWiiConnect(VMGlobals
*g
, int numArgsPushed
)
1286 PyrSlot
* args
= g
->sp
;
1289 PyrObject
* obj
= SC_WII::getObject(args
+0);
1290 if (!obj
) return errWrongType
;
1292 SC_WII
* dev
= SC_WII::getDevice(obj
);
1293 if (!dev
) return errFailed
;
1300 int prWiiDisconnect(VMGlobals
*g
, int numArgsPushed
)
1302 PyrSlot
* args
= g
->sp
;
1305 PyrObject
* obj
= SC_WII::getObject(args
+0);
1306 if (!obj
) return errWrongType
;
1308 SC_WII
* dev
= SC_WII::getDevice(obj
);
1309 if (!dev
) return errFailed
;
1311 dev
->wii_disconnect();
1316 int prWiiCalibration(VMGlobals
*g
, int numArgsPushed
)
1318 PyrSlot
* args
= g
->sp
- 1;
1321 PyrObject
* obj
= SC_WII::getObject(args
+0);
1322 if (!obj
) return errWrongType
;
1324 if (!isKindOfSlot(args
+1, s_wiiCalibrationInfoClass
->u
.classobj
))
1325 return errWrongType
;
1326 PyrObject
* infoObj
= slotRawObject(&args
[1]);
1328 SC_WII
* dev
= SC_WII::getDevice(obj
);
1329 if (!dev
) return errFailed
;
1331 if (dev
->m_wiiremote
== NULL
)
1338 SetFloat(infoObj
->slots
+0, dev
->m_wiiremote
->wiiCalibData
.accX_zero
);
1339 SetFloat(infoObj
->slots
+1, dev
->m_wiiremote
->wiiCalibData
.accY_zero
);
1340 SetFloat(infoObj
->slots
+2, dev
->m_wiiremote
->wiiCalibData
.accZ_zero
);
1341 SetFloat(infoObj
->slots
+3, dev
->m_wiiremote
->wiiCalibData
.accX_1g
);
1342 SetFloat(infoObj
->slots
+4, dev
->m_wiiremote
->wiiCalibData
.accY_1g
);
1343 SetFloat(infoObj
->slots
+5, dev
->m_wiiremote
->wiiCalibData
.accZ_1g
);
1345 if (dev
->m_wiiremote
->isExpansionPortAttached
)
1347 SetFloat(infoObj
->slots
+6, dev
->m_wiiremote
->nunchukCalibData
.accX_zero
);
1348 SetFloat(infoObj
->slots
+7, dev
->m_wiiremote
->nunchukCalibData
.accY_zero
);
1349 SetFloat(infoObj
->slots
+8, dev
->m_wiiremote
->nunchukCalibData
.accZ_zero
);
1350 SetFloat(infoObj
->slots
+9, dev
->m_wiiremote
->nunchukCalibData
.accX_1g
);
1351 SetFloat(infoObj
->slots
+10, dev
->m_wiiremote
->nunchukCalibData
.accY_1g
);
1352 SetFloat(infoObj
->slots
+11, dev
->m_wiiremote
->nunchukCalibData
.accZ_1g
);
1354 SetFloat(infoObj
->slots
+12, dev
->m_wiiremote
->nunchukJoyStickCalibData
.x_max
);
1355 SetFloat(infoObj
->slots
+13, dev
->m_wiiremote
->nunchukJoyStickCalibData
.x_min
);
1356 SetFloat(infoObj
->slots
+14, dev
->m_wiiremote
->nunchukJoyStickCalibData
.x_center
);
1357 SetFloat(infoObj
->slots
+15, dev
->m_wiiremote
->nunchukJoyStickCalibData
.y_max
);
1358 SetFloat(infoObj
->slots
+16, dev
->m_wiiremote
->nunchukJoyStickCalibData
.y_min
);
1359 SetFloat(infoObj
->slots
+17, dev
->m_wiiremote
->nunchukJoyStickCalibData
.y_center
);
1363 /* SetInt(infoObj->slots+0, dev->m_wiiremote->cal.x_zero);
1364 SetInt(infoObj->slots+1, dev->m_wiiremote->cal.y_zero);
1365 SetInt(infoObj->slots+2, dev->m_wiiremote->cal.z_zero);
1366 SetInt(infoObj->slots+3, dev->m_wiiremote->cal.x_scale);
1367 SetInt(infoObj->slots+4, dev->m_wiiremote->cal.y_scale);
1368 SetInt(infoObj->slots+5, dev->m_wiiremote->cal.z_scale);
1370 if (dev->m_wiiremote->mode.ext == 1)
1372 SetInt(infoObj->slots+6, dev->m_wiiremote->ext.nunchuk.cal.x_zero);
1373 SetInt(infoObj->slots+7, dev->m_wiiremote->ext.nunchuk.cal.y_zero);
1374 SetInt(infoObj->slots+8, dev->m_wiiremote->ext.nunchuk.cal.z_zero);
1375 SetInt(infoObj->slots+9, dev->m_wiiremote->ext.nunchuk.cal.x_scale);
1376 SetInt(infoObj->slots+10, dev->m_wiiremote->ext.nunchuk.cal.y_scale);
1377 SetInt(infoObj->slots+11, dev->m_wiiremote->ext.nunchuk.cal.z_scale);
1379 SetInt(infoObj->slots+12, dev->m_wiiremote->ext.nunchuk.cal.joyx_max);
1380 SetInt(infoObj->slots+13, dev->m_wiiremote->ext.nunchuk.cal.joyx_min);
1381 SetInt(infoObj->slots+14, dev->m_wiiremote->ext.nunchuk.cal.joyx_center);
1382 SetInt(infoObj->slots+15, dev->m_wiiremote->ext.nunchuk.cal.joyy_max);
1383 SetInt(infoObj->slots+16, dev->m_wiiremote->ext.nunchuk.cal.joyy_min);
1384 SetInt(infoObj->slots+17, dev->m_wiiremote->ext.nunchuk.cal.joyy_center);
1389 slotCopy(&args
[0], &args
[1]);
1393 // int prWiiGetLED(VMGlobals *g, int numArgsPushed)
1395 // PyrSlot* args = g->sp - 1;
1398 // PyrObject* obj = SC_WII::getObject(args+0);
1399 // if (!obj) return errWrongType;
1401 // SC_WII* dev = SC_WII::getDevice(obj);
1402 // if (!dev) return errFailed;
1404 // if (!isKindOfSlot(args+1, class_array))
1405 // return errWrongType;
1406 // PyrObject* leds = slotRawObject(&args[1]);
1407 // PyrSlot* bslots = leds->slots;
1409 // if (dev->m_wiiremote == NULL)
1411 // return errFailed;
1416 // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1417 // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1418 // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1419 // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1422 // SetInt(bslots+0, dev->m_wiiremote->led.one);
1423 // SetInt(bslots+1, dev->m_wiiremote->led.two);
1424 // SetInt(bslots+2, dev->m_wiiremote->led.three);
1425 // SetInt(bslots+3, dev->m_wiiremote->led.four);
1432 // int prWiiGetButtons(VMGlobals *g, int numArgsPushed)
1434 // PyrSlot* args = g->sp - 1;
1437 // PyrObject* obj = SC_WII::getObject(args+0);
1438 // if (!obj) return errWrongType;
1440 // // if (!isKindOfSlot(args+1, s_wiiLEDStateClass->u.classobj))
1441 // // return errWrongType;
1442 // // PyrObject* infoObj = slotRawObject(&args[1]);
1444 // SC_WII* dev = SC_WII::getDevice(obj);
1445 // if (!dev) return errFailed;
1447 // if (!isKindOfSlot(args+1, class_array))
1448 // return errWrongType;
1449 // PyrObject* buttons = slotRawObject(&args[1]);
1450 // PyrSlot* bslots = buttons->slots;
1452 // if (dev->m_wiiremote == NULL)
1454 // return errFailed;
1459 // // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1460 // // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1461 // // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1462 // // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1465 // SetInt(bslots+0, dev->m_wiiremote->keys.left);
1466 // SetInt(bslots+1, dev->m_wiiremote->keys.right);
1467 // SetInt(bslots+2, dev->m_wiiremote->keys.down);
1468 // SetInt(bslots+3, dev->m_wiiremote->keys.up);
1469 // SetInt(bslots+4, dev->m_wiiremote->keys.plus);
1470 // SetInt(bslots+5, dev->m_wiiremote->keys.two);
1471 // SetInt(bslots+6, dev->m_wiiremote->keys.one);
1472 // SetInt(bslots+7, dev->m_wiiremote->keys.b);
1473 // SetInt(bslots+8, dev->m_wiiremote->keys.a);
1474 // SetInt(bslots+9, dev->m_wiiremote->keys.minus);
1475 // SetInt(bslots+10, dev->m_wiiremote->keys.home);
1482 // int prWiiGetMotion(VMGlobals *g, int numArgsPushed)
1484 // PyrSlot* args = g->sp - 1;
1487 // PyrObject* obj = SC_WII::getObject(args+0);
1488 // if (!obj) return errWrongType;
1490 // // if (!isKindOfSlot(args+1, s_wiiLEDStateClass->u.classobj))
1491 // // return errWrongType;
1492 // // PyrObject* infoObj = slotRawObject(&args[1]);
1494 // SC_WII* dev = SC_WII::getDevice(obj);
1495 // if (!dev) return errFailed;
1497 // if (!isKindOfSlot(args+1, class_array))
1498 // return errWrongType;
1499 // PyrObject* buttons = slotRawObject(&args[1]);
1500 // PyrSlot* bslots = buttons->slots;
1502 // if (dev->m_wiiremote == NULL)
1504 // return errFailed;
1509 // // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1510 // // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1511 // // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1512 // // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1515 // SetInt(bslots+0, dev->m_wiiremote->axis.x);
1516 // SetInt(bslots+1, dev->m_wiiremote->axis.y);
1517 // SetInt(bslots+2, dev->m_wiiremote->axis.z);
1524 // int prWiiGetIR(VMGlobals *g, int numArgsPushed)
1526 // PyrSlot* args = g->sp - 1;
1529 // PyrObject* obj = SC_WII::getObject(args+0);
1530 // if (!obj) return errWrongType;
1532 // // if (!isKindOfSlot(args+1, s_wiiLEDStateClass->u.classobj))
1533 // // return errWrongType;
1534 // // PyrObject* infoObj = slotRawObject(&args[1]);
1536 // SC_WII* dev = SC_WII::getDevice(obj);
1537 // if (!dev) return errFailed;
1539 // if (!isKindOfSlot(args+1, class_array))
1540 // return errWrongType;
1541 // PyrObject* buttons = slotRawObject(&args[1]);
1542 // PyrSlot* bslots = buttons->slots;
1544 // if (dev->m_wiiremote == NULL)
1546 // return errFailed;
1551 // // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1552 // // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1553 // // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1554 // // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1557 // SetInt(bslots+0, dev->m_wiiremote->ir1.x);
1558 // SetInt(bslots+1, dev->m_wiiremote->ir1.y);
1559 // SetInt(bslots+2, dev->m_wiiremote->ir1.size);
1566 // int prWiiGetNunchukButtons(VMGlobals *g, int numArgsPushed)
1568 // PyrSlot* args = g->sp - 1;
1571 // PyrObject* obj = SC_WII::getObject(args+0);
1572 // if (!obj) return errWrongType;
1574 // // if (!isKindOfSlot(args+1, s_wiiLEDStateClass->u.classobj))
1575 // // return errWrongType;
1576 // // PyrObject* infoObj = slotRawObject(&args[1]);
1578 // SC_WII* dev = SC_WII::getDevice(obj);
1579 // if (!dev) return errFailed;
1581 // if (!isKindOfSlot(args+1, class_array))
1582 // return errWrongType;
1583 // PyrObject* buttons = slotRawObject(&args[1]);
1584 // PyrSlot* bslots = buttons->slots;
1586 // if (dev->m_wiiremote == NULL)
1588 // return errFailed;
1593 // // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1594 // // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1595 // // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1596 // // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1599 // SetInt(bslots+0, dev->m_wiiremote->ext.nunchuk.keys.z);
1600 // SetInt(bslots+1, dev->m_wiiremote->ext.nunchuk.keys.c);
1607 // int prWiiGetNunchukJoy(VMGlobals *g, int numArgsPushed)
1609 // PyrSlot* args = g->sp - 1;
1612 // PyrObject* obj = SC_WII::getObject(args+0);
1613 // if (!obj) return errWrongType;
1615 // // if (!isKindOfSlot(args+1, s_wiiLEDStateClass->u.classobj))
1616 // // return errWrongType;
1617 // // PyrObject* infoObj = slotRawObject(&args[1]);
1619 // SC_WII* dev = SC_WII::getDevice(obj);
1620 // if (!dev) return errFailed;
1622 // if (!isKindOfSlot(args+1, class_array))
1623 // return errWrongType;
1624 // PyrObject* buttons = slotRawObject(&args[1]);
1625 // PyrSlot* bslots = buttons->slots;
1627 // if (dev->m_wiiremote == NULL)
1629 // return errFailed;
1634 // // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1635 // // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1636 // // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1637 // // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1640 // SetInt(bslots+0, dev->m_wiiremote->ext.nunchuk.joyx);
1641 // SetInt(bslots+1, dev->m_wiiremote->ext.nunchuk.joyy);
1648 // int prWiiGetNunchukMotion(VMGlobals *g, int numArgsPushed)
1650 // PyrSlot* args = g->sp - 1;
1653 // PyrObject* obj = SC_WII::getObject(args+0);
1654 // if (!obj) return errWrongType;
1656 // // if (!isKindOfSlot(args+1, s_wiiLEDStateClass->u.classobj))
1657 // // return errWrongType;
1658 // // PyrObject* infoObj = slotRawObject(&args[1]);
1660 // SC_WII* dev = SC_WII::getDevice(obj);
1661 // if (!dev) return errFailed;
1663 // if (!isKindOfSlot(args+1, class_array))
1664 // return errWrongType;
1665 // PyrObject* buttons = slotRawObject(&args[1]);
1666 // PyrSlot* bslots = buttons->slots;
1668 // if (dev->m_wiiremote == NULL)
1670 // return errFailed;
1675 // // SetInt(bslots+0, dev->m_wiiremote->isLED1Illuminated);
1676 // // SetInt(bslots+1, dev->m_wiiremote->isLED2Illuminated);
1677 // // SetInt(bslots+2, dev->m_wiiremote->isLED3Illuminated);
1678 // // SetInt(bslots+3, dev->m_wiiremote->isLED4Illuminated);
1681 // SetInt(bslots+0, dev->m_wiiremote->ext.nunchuk.axis.x);
1682 // SetInt(bslots+1, dev->m_wiiremote->ext.nunchuk.axis.y);
1683 // SetInt(bslots+2, dev->m_wiiremote->ext.nunchuk.axis.z);
1690 // int prWiiGetExpansion(VMGlobals *g, int numArgsPushed)
1692 // PyrSlot* args = g->sp;
1695 // PyrObject* obj = SC_WII::getObject(args+0);
1696 // if (!obj) return errWrongType;
1698 // SC_WII* dev = SC_WII::getDevice(obj);
1699 // if (!dev) return errFailed;
1701 // if (dev->m_wiiremote == NULL)
1703 // return errFailed;
1708 // if (dev->m_wiiremote->isExpansionPortAttached)
1709 // SetInt( args, dev->m_wiiremote->expType );
1711 // SetInt( args, 0 );
1713 // // #ifdef SC_LINUX
1714 // // if ( dev->m_wiiremote->mode.ext == 1 )
1715 // // SetInt( args, dev->m_wiiremote->ext.id );
1717 // // SetInt( args, 0 );
1724 // int prWiiGetBattery(VMGlobals *g, int numArgsPushed)
1726 // PyrSlot* args = g->sp;
1729 // PyrObject* obj = SC_WII::getObject(args+0);
1730 // if (!obj) return errWrongType;
1732 // SC_WII* dev = SC_WII::getDevice(obj);
1733 // if (!dev) return errFailed;
1735 // if (dev->m_wiiremote == NULL)
1737 // return errFailed;
1742 // if (dev->m_wiiremote->batteryLevel)
1743 // SetFloat( args, dev->m_wiiremote->batteryLevel );
1745 // SetFloat( args, 0 );
1747 // // #ifdef SC_LINUX
1748 // // SetFloat( args, dev->m_wiiremote->battery );
1755 int prWiiSetLED(VMGlobals
*g
, int numArgsPushed
)
1757 PyrSlot
* args
= g
->sp
- 1;
1760 int enable1
, enable2
, enable3
, enable4
;
1762 PyrObject
* obj
= SC_WII::getObject(args
+0);
1763 if (!obj
) return errWrongType
;
1765 SC_WII
* dev
= SC_WII::getDevice(obj
);
1766 if (!dev
) return errFailed
;
1768 if (!isKindOfSlot(args
+1, class_array
))
1769 return errWrongType
;
1770 PyrObject
* leds
= slotRawObject(&args
[1]);
1771 PyrSlot
* bslots
= leds
->slots
;
1773 err
= slotIntVal( bslots
+0, &enable1
);
1774 if (err
) return err
;
1776 err
= slotIntVal( bslots
+1, &enable2
);
1777 if (err
) return err
;
1779 err
= slotIntVal( bslots
+2, &enable3
);
1780 if (err
) return err
;
1782 err
= slotIntVal( bslots
+3, &enable4
);
1783 if (err
) return err
;
1785 if (dev
->m_wiiremote
== NULL
)
1792 result
= wiiremote_led( dev
->m_wiiremote
, enable1
, enable2
, enable3
, enable4
);
1794 // dev->wii_disconnect();
1798 set_bit(&dev
->led_state
, CWIID_LED1_ON
);
1800 clear_bit(&dev
->led_state
, CWIID_LED1_ON
);
1802 set_bit(&dev
->led_state
, CWIID_LED2_ON
);
1804 clear_bit(&dev
->led_state
, CWIID_LED2_ON
);
1806 set_bit(&dev
->led_state
, CWIID_LED3_ON
);
1808 clear_bit(&dev
->led_state
, CWIID_LED3_ON
);
1810 set_bit(&dev
->led_state
, CWIID_LED4_ON
);
1812 clear_bit(&dev
->led_state
, CWIID_LED4_ON
);
1813 set_led_state(dev
->m_wiiremote
, dev
->led_state
);
1814 // post( "WII: led %i %i %i %i", dev->m_wiiremote->led.one, dev->m_wiiremote->led.two, dev->m_wiiremote->led.three, dev->m_wiiremote->led.four );
1822 int prWiiSetVibration(VMGlobals
*g
, int numArgsPushed
)
1824 PyrSlot
* args
= g
->sp
- 1;
1829 PyrObject
* obj
= SC_WII::getObject(args
+0);
1830 if (!obj
) return errWrongType
;
1832 SC_WII
* dev
= SC_WII::getDevice(obj
);
1833 if (!dev
) return errFailed
;
1835 err
= slotIntVal(args
+1, &enable1
);
1836 if (err
) return err
;
1838 if (dev
->m_wiiremote
== NULL
)
1845 result
= wiiremote_vibration( dev
->m_wiiremote
, enable1
);
1847 // dev->wii_disconnect();
1848 // post( "WII: rumble %i %i", enable1, result );
1851 if (cwiid_set_rumble(dev
->m_wiiremote
, (unsigned char) enable1
)) {
1854 // post( "WII: rumble %i %i", dev->m_wiiremote->rumble, enable1 );
1860 int prWiiSetExpansion(VMGlobals
*g
, int numArgsPushed
)
1862 PyrSlot
* args
= g
->sp
- 1;
1867 PyrObject
* obj
= SC_WII::getObject(args
+0);
1868 if (!obj
) return errWrongType
;
1870 SC_WII
* dev
= SC_WII::getDevice(obj
);
1871 if (!dev
) return errFailed
;
1873 err
= slotIntVal(args
+1, &enable1
);
1874 if (err
) return err
;
1876 if (dev
->m_wiiremote
== NULL
)
1883 result
= wiiremote_expansion( dev
->m_wiiremote
, enable1
);
1885 // dev->wii_disconnect();
1889 set_bit(&dev
->rpt_mode
, CWIID_RPT_EXT
);
1891 clear_bit(&dev
->rpt_mode
, CWIID_RPT_EXT
);
1892 set_rpt_mode(dev
->m_wiiremote
, dev
->rpt_mode
);
1893 // post( "WII: expansion %i %i", dev->m_wiiremote->mode.ext, enable1 );
1900 int prWiiSetIRSensor(VMGlobals
*g
, int numArgsPushed
)
1902 PyrSlot
* args
= g
->sp
- 1;
1907 PyrObject
* obj
= SC_WII::getObject(args
+0);
1908 if (!obj
) return errWrongType
;
1910 SC_WII
* dev
= SC_WII::getDevice(obj
);
1911 if (!dev
) return errFailed
;
1913 err
= slotIntVal(args
+1, &enable1
);
1914 if (err
) return err
;
1916 if (dev
->m_wiiremote
== NULL
)
1923 result
= wiiremote_irsensor( dev
->m_wiiremote
, enable1
);
1925 // dev->wii_disconnect();
1930 set_bit(&dev
->rpt_mode
, CWIID_RPT_IR
);
1932 clear_bit(&dev
->rpt_mode
, CWIID_RPT_IR
);
1933 set_rpt_mode(dev
->m_wiiremote
, dev
->rpt_mode
);
1934 // post( "WII: ir sensor %i %i", dev->m_wiiremote->mode.ir, enable1 );
1941 int prWiiSetMotionSensor(VMGlobals
*g
, int numArgsPushed
)
1943 PyrSlot
* args
= g
->sp
- 1;
1948 PyrObject
* obj
= SC_WII::getObject(args
+0);
1949 if (!obj
) return errWrongType
;
1951 SC_WII
* dev
= SC_WII::getDevice(obj
);
1952 if (!dev
) return errFailed
;
1954 err
= slotIntVal(args
+1, &enable1
);
1955 if (err
) return err
;
1957 if (dev
->m_wiiremote
== NULL
)
1964 result
= wiiremote_motionsensor( dev
->m_wiiremote
, enable1
);
1966 // dev->wii_disconnect();
1970 set_bit(&dev
->rpt_mode
, CWIID_RPT_ACC
);
1972 clear_bit(&dev
->rpt_mode
, CWIID_RPT_ACC
);
1973 set_rpt_mode(dev
->m_wiiremote
, dev
->rpt_mode
);
1980 int prWiiSetButtons(VMGlobals
*g
, int numArgsPushed
)
1982 PyrSlot
* args
= g
->sp
- 1;
1987 PyrObject
* obj
= SC_WII::getObject(args
+0);
1988 if (!obj
) return errWrongType
;
1990 SC_WII
* dev
= SC_WII::getDevice(obj
);
1991 if (!dev
) return errFailed
;
1993 err
= slotIntVal(args
+1, &enable1
);
1994 if (err
) return err
;
1996 if (dev
->m_wiiremote
== NULL
)
2003 // buttons are always enabled
2004 // result = wiiremote_motionsensor( dev->m_wiiremote, enable1 );
2008 set_bit(&dev
->rpt_mode
, CWIID_RPT_BTN
);
2010 clear_bit(&dev
->rpt_mode
, CWIID_RPT_BTN
);
2011 set_rpt_mode(dev
->m_wiiremote
, dev
->rpt_mode
);
2018 int prWiiEnable(VMGlobals
*g
, int numArgsPushed
)
2020 PyrSlot
* args
= g
->sp
- 1;
2025 PyrObject
* obj
= SC_WII::getObject(args
+0);
2026 if (!obj
) return errWrongType
;
2028 SC_WII
* dev
= SC_WII::getDevice(obj
);
2029 if (!dev
) return errFailed
;
2031 err
= slotIntVal(args
+1, &enable1
);
2032 if (err
) return err
;
2034 if (dev
->m_wiiremote
== NULL
)
2041 // is always enabled
2042 // result = wiiremote_motionsensor( dev->m_wiiremote, enable1 );
2045 dev
->enable( enable1
);
2052 // int prWiiPlaySpeaker(VMGlobals *g, int numArgsPushed)
2054 // PyrSlot* args = g->sp - 4;
2060 // PyrObject* obj = SC_WII::getObject(args+0);
2061 // if (!obj) return errWrongType;
2063 // SC_WII* dev = SC_WII::getDevice(obj);
2064 // if (!dev) return errFailed;
2066 // err = slotIntVal(args+1, &enable1);
2067 // if (err) return err;
2069 // err = slotIntVal(args+2, &freq);
2070 // if (err) return err;
2072 // err = slotIntVal(args+3, &vol);
2073 // if (err) return err;
2075 // // err = slotIntVal(args+4, &sample);
2076 // // if (err) return err;
2078 // if (dev->m_wiiremote == NULL)
2080 // return errFailed;
2084 // // #ifdef SC_DARWIN
2085 // // result = wiiremote_motionsensor( dev->m_wiiremote, enable1 );
2088 // uint8_t sample[20] = {
2089 // 0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,
2090 // 0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c,0x3c
2092 // wiimote_speaker_freq( dev->m_wiiremote, (uint8_t) freq);
2093 // wiimote_speaker_volume( dev->m_wiiremote, (uint8_t) vol );
2095 // wiimote_speaker_play( dev->m_wiiremote, sample, 20);
2097 // // post( "WII: speaker %i %i", freq, vol );
2104 // int prWiiEnableSpeaker(VMGlobals *g, int numArgsPushed)
2106 // PyrSlot* args = g->sp - 1;
2111 // PyrObject* obj = SC_WII::getObject(args+0);
2112 // if (!obj) return errWrongType;
2114 // SC_WII* dev = SC_WII::getDevice(obj);
2115 // if (!dev) return errFailed;
2117 // err = slotIntVal(args+1, &enable1);
2118 // if (err) return err;
2120 // if (dev->m_wiiremote == NULL)
2122 // return errFailed;
2126 // // #ifdef SC_DARWIN
2127 // // result = wiiremote_motionsensor( dev->m_wiiremote, enable1 );
2131 // wiimote_speaker_enable(dev->m_wiiremote);
2133 // wiimote_speaker_disable(dev->m_wiiremote);
2135 // // post( "WII: speaker enable %i", enable1 );
2143 // int prWiiInitSpeaker(VMGlobals *g, int numArgsPushed)
2145 // PyrSlot* args = g->sp - 1;
2150 // PyrObject* obj = SC_WII::getObject(args+0);
2151 // if (!obj) return errWrongType;
2153 // SC_WII* dev = SC_WII::getDevice(obj);
2154 // if (!dev) return errFailed;
2156 // err = slotIntVal(args+1, &enable1);
2157 // if (err) return err;
2159 // if (dev->m_wiiremote == NULL)
2161 // return errFailed;
2165 // // #ifdef SC_DARWIN
2166 // // result = wiiremote_motionsensor( dev->m_wiiremote, enable1 );
2170 // dev->speaker_init( 4 );
2172 // dev->speaker_init( 8 );
2174 // // post( "WII: speaker init %i", enable1 );
2182 // int prWiiMuteSpeaker(VMGlobals *g, int numArgsPushed)
2184 // PyrSlot* args = g->sp - 1;
2189 // PyrObject* obj = SC_WII::getObject(args+0);
2190 // if (!obj) return errWrongType;
2192 // SC_WII* dev = SC_WII::getDevice(obj);
2193 // if (!dev) return errFailed;
2195 // err = slotIntVal(args+1, &enable1);
2196 // if (err) return err;
2198 // if (dev->m_wiiremote == NULL)
2200 // return errFailed;
2204 // // #ifdef SC_DARWIN
2205 // // result = wiiremote_motionsensor( dev->m_wiiremote, enable1 );
2209 // wiimote_speaker_mute(dev->m_wiiremote);
2211 // wiimote_speaker_unmute(dev->m_wiiremote);
2213 // // post( "WII: mute %i", enable1 );
2220 void initWiiPrimitives()
2224 s_wii
= getsym("WiiMote");
2225 s_wiiCalibrationInfoClass
= getsym("WiiCalibrationInfo"); // has calibration date for all axes
2226 // s_wiiLEDStateClass = getsym("WiiLEDState"); // has the four LED states
2228 // s_wiiRemoteClass = getsym("WiiRemote"); // Remote
2229 // s_wiiNunChuckClass = getsym("WiiNunChuck"); // NunChuck
2230 // s_wiiClassicClass = getsym("WiiClassic"); // Classic
2231 // s_wiiAction = getsym("prWiiMoteAction");
2233 s_wiiDisconnected
= getsym("prDisconnectAction");
2234 s_wiiConnected
= getsym("prConnectAction");
2235 s_readError
= getsym("prReadError");
2237 /// general event on MacOSX
2238 s_handleEvent
= getsym("prHandleEvent");
2240 /// separate events on Linux:
2241 s_handleBatteryEvent
= getsym("prHandleBatteryEvent");
2242 s_handleExtensionEvent
= getsym("prHandleExtensionEvent");
2243 s_handleButtonEvent
= getsym("prHandleButtonEvent");
2244 s_handleNunchukEvent
= getsym("prHandleNunchukEvent");
2245 s_handleClassicEvent
= getsym("prHandleClassicEvent");
2246 s_handleIREvent
= getsym("prHandleIREvent");
2247 s_handleAccEvent
= getsym("prHandleAccEvent");
2249 base
= nextPrimitiveIndex();
2251 definePrimitive(base
, index
++, "_Wii_Start", prWii_Start
, 2, 0); // starts the eventloop
2252 definePrimitive(base
, index
++, "_Wii_Discover", prWii_Discover
, 3, 0); // discovers a new device
2253 definePrimitive(base
, index
++, "_Wii_Stop", prWii_Stop
, 1, 0); // stops the eventloop
2255 definePrimitive(base
, index
++, "_Wii_Open", prWii_Open
, 1, 0 );
2256 // definePrimitive(base, index++, "_Wii_Update", prWii_Update, 1, 0 );
2257 // definePrimitive(base, index++, "_Wii_UpdateData", prWii_UpdateData, 9, 0 );
2258 definePrimitive(base
, index
++, "_Wii_Close", prWii_Close
, 1, 0 );
2260 definePrimitive(base
, index
++, "_Wii_Address", prWiiAddress
, 1, 0);
2261 // definePrimitive(base, index++, "_Wii_SetAddress", prWiiSetAddress, 2, 0);
2263 definePrimitive(base
, index
++, "_Wii_Connect", prWiiConnect
, 1, 0);
2264 definePrimitive(base
, index
++, "_Wii_Disconnect", prWiiDisconnect
, 1, 0);
2266 definePrimitive(base
, index
++, "_Wii_Calibration", prWiiCalibration
, 2, 0);
2268 // definePrimitive(base, index++, "_Wii_GetExpansion", prWiiGetExpansion, 1, 0);
2269 // definePrimitive(base, index++, "_Wii_GetBattery", prWiiGetBattery, 1, 0);
2271 // definePrimitive(base, index++, "_Wii_GetButtons", prWiiGetButtons, 2, 0);
2272 // definePrimitive(base, index++, "_Wii_GetMotion", prWiiGetMotion, 2, 0);
2273 // definePrimitive(base, index++, "_Wii_GetIR", prWiiGetIR, 2, 0);
2275 // definePrimitive(base, index++, "_Wii_GetNunchukButtons", prWiiGetNunchukButtons, 2, 0);
2276 // definePrimitive(base, index++, "_Wii_GetNunchukJoy", prWiiGetNunchukJoy, 2, 0);
2277 // definePrimitive(base, index++, "_Wii_GetNunchukMotion", prWiiGetNunchukMotion, 2, 0);
2279 // definePrimitive(base, index++, "_Wii_GetClassicButtons", prWiiGetClassicButtons, 2, 0);
2280 // definePrimitive(base, index++, "_Wii_GetClassicJoy", prWiiGetClassicJoy, 2, 0);
2281 // definePrimitive(base, index++, "_Wii_GetClassicAnalog", prWiiGetClassicAnalog, 2, 0);
2283 // definePrimitive(base, index++, "_Wii_GetLED", prWiiGetLED, 2, 0);
2285 definePrimitive(base
, index
++, "_Wii_SetLED", prWiiSetLED
, 2, 0);
2287 definePrimitive(base
, index
++, "_Wii_SetVibration", prWiiSetVibration
, 2, 0);
2289 // definePrimitive(base, index++, "_Wii_InitSpeaker", prWiiInitSpeaker, 2, 0);
2290 // definePrimitive(base, index++, "_Wii_PlaySpeaker", prWiiPlaySpeaker, 5, 0);
2291 // definePrimitive(base, index++, "_Wii_MuteSpeaker", prWiiMuteSpeaker, 2, 0);
2292 // definePrimitive(base, index++, "_Wii_EnableSpeaker", prWiiEnableSpeaker, 2, 0);
2294 definePrimitive(base
, index
++, "_Wii_Enable", prWiiEnable
, 2, 0);
2295 definePrimitive(base
, index
++, "_Wii_EnableButtons", prWiiSetButtons
, 2, 0);
2296 definePrimitive(base
, index
++, "_Wii_EnableIRSensor", prWiiSetIRSensor
, 2, 0);
2297 definePrimitive(base
, index
++, "_Wii_EnableMotionSensor", prWiiSetMotionSensor
, 2, 0);
2298 definePrimitive(base
, index
++, "_Wii_EnableExpansion", prWiiSetExpansion
, 2, 0);
2301 #else // NOT HAVE_WII
2302 void initWiiPrimitives()