Advertisement
Guest User

Untitled

a guest
May 19th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <gccore.h>
  4. #include <wiiuse/wpad.h>
  5. #include <ogc/system.h>
  6.  
  7. #define VERSION       "INFO"
  8. #define RELEASE_DATE  "08-09-2009"
  9.  
  10. int numberOfAttachedControllers();
  11. void waitForWiimote();
  12.  
  13. static u32 *xfb;
  14. static GXRModeObj *rmode;
  15.  
  16. int totalWiiMotes;
  17. int rumbleOn = 0;
  18.  
  19. // Wiimote IR
  20. ir_t ir;
  21.  
  22. // Orientation vars
  23. orient_t orient;
  24. int xRotation;
  25. int yRotation;
  26. int zRotation;
  27.  
  28. //Gforce vars
  29. gforce_t gforce;
  30.  
  31. //---------------------------------------------------------------------------------------------------
  32. //Initialize the video and wii remotes
  33. //---------------------------------------------------------------------------------------------------
  34. void Initialize() {
  35.  
  36.     //initialize video
  37.     VIDEO_Init();
  38.     //initialize wii remotes
  39.     WPAD_Init();
  40.     //set IR resolution to 640 width and 480 height
  41.     WPAD_SetVRes(0, 640, 480);
  42.     //return data for wii remotes should contain Button Data, Accelerometer, and IR
  43.     WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
  44.  
  45.     //find the video mode of the wii
  46.     rmode = VIDEO_GetPreferredMode(NULL);
  47.  
  48.     //create buffer for console terminal output
  49.     xfb = (u32*)MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  50.     //initialize the console
  51.     console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  52.  
  53.     //set video to wii's video mode
  54.     VIDEO_Configure(rmode);
  55.     //set buffer to write to
  56.     VIDEO_SetNextFramebuffer(xfb);
  57.     //whether to set background black, I have chosen no
  58.     VIDEO_SetBlack(FALSE);
  59.     //send VIDEO_ commands for setup
  60.     VIDEO_Flush();
  61.     //wait for vertical sync to ensure it's at the bottom
  62.     VIDEO_WaitVSync();
  63.     //if video is progressive then wait for another vertical sync
  64.     if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  65.  
  66.     //find out how many wii remotes are attached at the start
  67.     waitForWiimote();
  68.     totalWiiMotes = numberOfAttachedControllers();
  69. }
  70.  
  71. //---------------------------------------------------------------------------------------------------
  72. //Exit back to the HBC - can be used for cleanup or other non-sense
  73. //---------------------------------------------------------------------------------------------------
  74. void exitToHomebrewChannel(void) {
  75.     exit(0);
  76. }
  77.  
  78. //---------------------------------------------------------------------------------------------------
  79. //Test for values of wii remote accelerometer and IR
  80. //---------------------------------------------------------------------------------------------------
  81. void showWiiMoteAccelerometer(void) {
  82.  
  83.     printf("\x1b[2J");
  84.     while(1) {
  85.  
  86.         u32 ext;//Extension type
  87.         u32 ret = 0;//remote scan and probe return
  88.         ret = WPAD_ScanPads();
  89.         ret = WPAD_Probe(WPAD_CHAN_0, &ext);//probe remote 1 with extension
  90.  
  91.         WPADData *Data = WPAD_Data(WPAD_CHAN_0);//store data from remote 1
  92.         WPADData data = *Data;
  93.  
  94.         WPAD_IR(WPAD_CHAN_0, &(data.ir));//get IR data
  95.         WPAD_Orientation(WPAD_CHAN_0, &(data.orient));//get rotation data
  96.         WPAD_GForce(WPAD_CHAN_0, &(data.gforce));//get "speed" data
  97.         WPAD_Accel(WPAD_CHAN_0, &(data.accel));//get accelerometer data
  98.         WPAD_Expansion(WPAD_CHAN_0, &(data.exp));//get expansion data
  99.  
  100.         printf("\x1b[1;0HWii Remote Info  \n");
  101.  
  102.         //print gforce data for x, y, and z
  103.         printf("\x1b[2;0HGForce x: %1.3f  \n", data.gforce.x);
  104.         printf("\x1b[3;0HGForce y: %1.3f  \n", data.gforce.y);
  105.         printf("\x1b[4;0HGForce z: %1.3f  \n", data.gforce.z);
  106.  
  107.  
  108.         //get and print the rotation orientation
  109.         xRotation = (int)data.orient.roll;
  110.         yRotation = (int)data.orient.pitch;
  111.         zRotation = (int)data.orient.yaw;
  112.  
  113.         if(xRotation<0){
  114.             xRotation=360+xRotation;
  115.         }
  116.         if(yRotation<0){
  117.             yRotation=360+yRotation;
  118.         }
  119.         if(zRotation<0){
  120.             zRotation=360+zRotation;
  121.         }
  122.  
  123.         printf("\x1b[5;0HxRotation: %d  \n", xRotation);
  124.         printf("\x1b[6;0HyRotation: %d  \n", yRotation);
  125.         printf("\x1b[7;0HzRotation: %d  \n", zRotation);
  126.  
  127.         //print different IR data
  128.         printf("\x1b[9;0HIR x: %1.3f  \n", data.ir.x);
  129.         printf("\x1b[10;0HIR y: %1.3f  \n", data.ir.y);
  130.  
  131.         printf("\x1b[11;0HIR RAW X %1.3f  ", data.ir.ax);
  132.         printf("\x1b[12;0HIR RAW Y %1.3f  ", data.ir.ay);
  133.  
  134.         printf("\x1b[13;0HIR SMOOTH X %1.3f  ", data.ir.sx);
  135.         printf("\x1b[14;0HIR SMOOTH Y %1.3f  ", data.ir.sy);
  136.  
  137.         printf("\x1b[15;0HIR ANGLE %1.3f  ", data.ir.angle);
  138.  
  139.         //print accelerometer data
  140.         printf("\x1b[1;25HACCEL X %d  \n", (int)data.accel.x);
  141.         printf("\x1b[2;25HACCEL Y %d  \n", (int)data.accel.y);
  142.         printf("\x1b[3;25HACCEL Z %d  \n", (int)data.accel.z);
  143.  
  144.  
  145.         if((ret == WPAD_ERR_NONE) && (ext == WPAD_EXP_NUNCHUK))
  146.         {
  147.             printf("\x1b[4;25HNCUHCK MIN X %d Y %d  ", (int)data.exp.nunchuk.js.min.x, (int)data.exp.nunchuk.js.min.y);
  148.             printf("\x1b[5;25HNCUHCK MAX X %d Y %d  ", (int)data.exp.nunchuk.js.max.x, (int)data.exp.nunchuk.js.max.y);
  149.             printf("\x1b[6;25HNCUHCK CENTER X %d Y %d  ", (int)data.exp.nunchuk.js.center.x, (int)data.exp.nunchuk.js.center.y);
  150.             printf("\x1b[7;25HNCUHCK POS X %d Y %d  ", (int)data.exp.nunchuk.js.pos.x, (int)data.exp.nunchuk.js.pos.y);
  151.             printf("\x1b[8;25HNCUHCK ANG %1.3f MAG %1.3f  ", (float)data.exp.nunchuk.js.ang, (float)data.exp.nunchuk.js.mag);
  152.  
  153.             printf("\x1b[9;25HGFORCE X %1.3f  \n", (float)data.exp.nunchuk.gforce.x);
  154.             printf("\x1b[10;25HGFORCE Y %1.3f  \n", (float)data.exp.nunchuk.gforce.y);
  155.             printf("\x1b[11;25HGFORCE Z %1.3f  \n", (float)data.exp.nunchuk.gforce.z);
  156.  
  157.             printf("\x1b[12;25HROTATE X %1.3f  \n", (float)data.exp.nunchuk.orient.roll);
  158.             printf("\x1b[13;25HROTATE Y %1.3f  \n", (float)data.exp.nunchuk.orient.pitch);
  159.             printf("\x1b[14;25HROTATE Z %1.3f  \n", (float)data.exp.nunchuk.orient.yaw);
  160.  
  161.             printf("\x1b[15;25HACCEL X %1.3f  \n", (float)data.exp.nunchuk.accel.x);
  162.             printf("\x1b[16;25HACCEL Y %1.3f  \n", (float)data.exp.nunchuk.accel.y);
  163.             printf("\x1b[17;25HACCEL Z %1.3f  \n", (float)data.exp.nunchuk.accel.z);
  164.         }
  165.        
  166.         if((ret == WPAD_ERR_NONE) && (ext == WPAD_EXP_CLASSIC))
  167.         {
  168.             printf("\x1b[4;25HLJOYST MIN X %d Y %d  ", (int)data.exp.classic.ljs.min.x, (int)data.exp.classic.ljs.min.y);
  169.             printf("\x1b[5;25HLJOYST MAX X %d Y %d  ", (int)data.exp.classic.ljs.max.x, (int)data.exp.classic.ljs.max.y);
  170.             printf("\x1b[6;25HLJOYST CENTER X %d Y %d  ", (int)data.exp.classic.ljs.center.x, (int)data.exp.classic.ljs.center.y);
  171.             printf("\x1b[7;25HLJOYST POS X %d Y %d  ", (int)data.exp.classic.ljs.pos.x, (int)data.exp.classic.ljs.pos.y);
  172.             printf("\x1b[8;25HLJOYST ANG %1.3f MAG %1.3f  ", (float)data.exp.classic.ljs.ang, (float)data.exp.classic.ljs.mag);
  173.            
  174.             printf("\x1b[9;25HRJOYST MIN X %d Y %d  ", (int)data.exp.classic.rjs.min.x, (int)data.exp.classic.rjs.min.y);
  175.             printf("\x1b[10;25HRJOYST MAX X %d Y %d  ", (int)data.exp.classic.rjs.max.x, (int)data.exp.classic.rjs.max.y);
  176.             printf("\x1b[11;25HRJOYST CENTER X %d Y %d  ", (int)data.exp.classic.rjs.center.x, (int)data.exp.classic.rjs.center.y);
  177.             printf("\x1b[12;25HRJOYST POS X %d Y %d  ", (int)data.exp.classic.rjs.pos.x, (int)data.exp.classic.rjs.pos.y);
  178.             printf("\x1b[13;25HRJOYST ANG %1.3f MAG %1.3f  ", (float)data.exp.classic.rjs.ang, (float)data.exp.classic.rjs.mag);
  179.            
  180.             printf("\x1b[14;25HL TRIGGER %1.3f  \n", (float)data.exp.classic.l_shoulder);  
  181.             printf("\x1b[15;25HR TRIGGER %1.3f  \n", (float)data.exp.classic.r_shoulder);          
  182.         }
  183.  
  184.         u32 pressed = WPAD_ButtonsHeld(WPAD_CHAN_0);
  185.         u32 buttonDown = WPAD_ButtonsDown(WPAD_CHAN_0);
  186.  
  187.         if (pressed & WPAD_NUNCHUK_BUTTON_Z) printf("\x1b[18;0HButton Z pressed on Nunchuk");
  188.         if (pressed & WPAD_NUNCHUK_BUTTON_C) printf("\x1b[19;0HButton C pressed on Nunchuk");
  189.         if (pressed & WPAD_CLASSIC_BUTTON_A) printf("\x1b[20;0HButton A pressed on Classic Controller");
  190.         if (pressed & WPAD_CLASSIC_BUTTON_B) printf("\x1b[21;0HButton B pressed on Classic Controller");
  191.         if (pressed & WPAD_CLASSIC_BUTTON_X) printf("\x1b[20;0HButton X pressed on Classic Controller");
  192.         if (pressed & WPAD_CLASSIC_BUTTON_Y) printf("\x1b[21;0HButton Y pressed on Classic Controller");
  193.         if (pressed & WPAD_CLASSIC_BUTTON_FULL_L) printf("\x1b[22;0HButton L pressed on Classic Controller");
  194.         if (pressed & WPAD_CLASSIC_BUTTON_FULL_R) printf("\x1b[23;0HButton R pressed on Classic Controller");
  195.         if (pressed & WPAD_CLASSIC_BUTTON_ZL) printf("\x1b[22;0HButton ZL pressed on Classic Controller");
  196.         if (pressed & WPAD_CLASSIC_BUTTON_ZR) printf("\x1b[23;0HButton ZR pressed on Classic Controller");
  197.         if (pressed & WPAD_CLASSIC_BUTTON_PLUS) printf("\x1b[18;25HButton PLUS pressed on Classic Controller");
  198.         if (pressed & WPAD_CLASSIC_BUTTON_MINUS) printf("\x1b[19;25HButton MINUS pressed on Classic Controller");
  199.         if (pressed & WPAD_CLASSIC_BUTTON_UP) printf("\x1b[20;25HButton UP pressed on Classic Controller");
  200.         if (pressed & WPAD_CLASSIC_BUTTON_DOWN) printf("\x1b[21;25HButton DOWN pressed on Classic Controller");
  201.         if (pressed & WPAD_CLASSIC_BUTTON_LEFT) printf("\x1b[22;25HButton LEFT pressed on Classic Controller");
  202.         if (pressed & WPAD_CLASSIC_BUTTON_RIGHT) printf("\x1b[23;25HButton RIGHT pressed on Classic Controller");
  203.         if (pressed & WPAD_BUTTON_A) printf("\x1b[20;0HButton A pressed");
  204.         if (pressed & WPAD_BUTTON_B) printf("\x1b[21;0HButton B pressed");
  205.         if (pressed & WPAD_BUTTON_1) printf("\x1b[22;0HButton 1 pressed");
  206.         if (pressed & WPAD_BUTTON_2) printf("\x1b[23;0HButton 2 pressed");
  207.         if (pressed & WPAD_BUTTON_PLUS) printf("\x1b[18;25HButton PLUS pressed");
  208.         if (pressed & WPAD_BUTTON_MINUS) printf("\x1b[19;25HButton MINUS pressed");
  209.         if (pressed & WPAD_BUTTON_UP) printf("\x1b[20;25HButton UP pressed");
  210.         if (pressed & WPAD_BUTTON_DOWN) printf("\x1b[21;25HButton DOWN pressed");
  211.         if (pressed & WPAD_BUTTON_LEFT) printf("\x1b[22;25HButton LEFT pressed");
  212.         if (pressed & WPAD_BUTTON_RIGHT) printf("\x1b[23;25HButton RIGHT pressed");
  213.  
  214.         printf("\x1b[24;25HNumber of wiimotes: %d", totalWiiMotes);
  215.         printf("\x1b[24;1Hret: %d", ret);
  216.  
  217.         if (buttonDown & (WPAD_BUTTON_1 | WPAD_BUTTON_2)) {
  218.             if ( rumbleOn == 0 ) {
  219.                 rumbleOn = 1;
  220.                 WPAD_Rumble(WPAD_CHAN_0, 1);
  221.             }
  222.             else {
  223.                 rumbleOn = 0;
  224.                 WPAD_Rumble(WPAD_CHAN_0, 0);
  225.             }
  226.         }
  227.         if (buttonDown & (WPAD_BUTTON_A | WPAD_BUTTON_B)) {
  228.             WPAD_Rumble(WPAD_CHAN_0, 0);
  229.             break;
  230.         }
  231.         if (pressed & (WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME)) {
  232.             WPAD_Rumble(WPAD_CHAN_0, 0);
  233.             exitToHomebrewChannel();
  234.         }
  235.         if(SYS_ResetButtonDown()) exitToHomebrewChannel();
  236.         VIDEO_WaitVSync();
  237.         printf("\x1b[2J");
  238.     }
  239. }
  240.  
  241. //---------------------------------------------------------------------------------------------------
  242. //Find out how many controllers are attached
  243. //---------------------------------------------------------------------------------------------------
  244. int numberOfAttachedControllers() {
  245.     // used to check how many controllers are attached
  246.     int i, numAttached = 0;
  247.     u32 type;  //find the type of the expansion
  248.  
  249.     for(i=0; i<WPAD_MAX_WIIMOTES; i++) {
  250.         if (WPAD_Probe(i, &type) == WPAD_ERR_NONE) {
  251.             numAttached++;
  252.         }
  253.     }
  254.     return numAttached;
  255. }
  256.  
  257. void waitForWiimote()
  258. {
  259.     while(1)
  260.     {
  261.         printf("\x1b[20;20HWaiting for wiimote");
  262.         totalWiiMotes = numberOfAttachedControllers();
  263.         if (totalWiiMotes > 0) break;
  264.     }
  265.     return;
  266. }
  267.  
  268.  
  269. //---------------------------------------------------------------------------------------------------
  270. //Main function
  271. //---------------------------------------------------------------------------------------------------
  272. int main() {
  273.  
  274.     Initialize();
  275.  
  276.     showWiiMoteAccelerometer();
  277.  
  278.     exitToHomebrewChannel();
  279.  
  280.     return 0;
  281. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement