Show
Ignore:
Timestamp:
12/29/08 14:27:47 (4 years ago)
Author:
takeru
Message:

wpad demo

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/wii/ruby_for_wii/channels/rubwii/source/rubwii.c

    r27517 r27547  
    1313#include "gfx/logo.h" 
    1414 
    15 //#include <ruby.h> 
    16 typedef unsigned long VALUE; 
     15#include <ruby.h> 
     16//typedef unsigned long VALUE; 
    1717 
    1818Mtx GXmodelView2D; 
     
    2828//printf(ANSI_FG_BLUE "BLUE" ANSI_FG_RED "RED" ANSI_FG_WHITE "\n"); 
    2929 
     30// class Wii 
     31VALUE rb_cWii; 
     32VALUE rb_wii_s_hello(VALUE klass, VALUE _x, VALUE _y) 
     33{ 
     34  long x; 
     35  long y; 
     36  long ret; 
     37  x = NUM2LONG(_x); 
     38  y = NUM2LONG(_y); 
     39  ret = x + y; 
     40  return LONG2NUM(ret); 
     41} 
     42VALUE rb_wii_s_usleep(VALUE klass, VALUE _us) 
     43{ 
     44  long us; 
     45  us = NUM2LONG(_us); 
     46  usleep(us); 
     47  return Qnil; 
     48} 
     49VALUE rb_wii_s_wpad(VALUE klass, VALUE _chan) 
     50{ 
     51  int chan; 
     52  u32 wpaddown; 
     53  u32 wpadheld; 
     54  struct ir_t ir; 
     55  struct gforce_t gforce; 
     56  VALUE ary; 
     57  chan = NUM2INT(_chan); 
     58 
     59  WPAD_ScanPads(); 
     60 
     61  wpaddown = WPAD_ButtonsDown(chan); 
     62  wpadheld = WPAD_ButtonsHeld(chan); 
     63  WPAD_IR(chan, &ir); 
     64  WPAD_GForce(chan, &gforce); 
     65 
     66  ary = rb_ary_new(); 
     67  rb_ary_push(ary, LONG2NUM(wpaddown)); 
     68  rb_ary_push(ary, LONG2NUM(wpadheld)); 
     69  rb_ary_push(ary, rb_float_new(ir.x)); 
     70  rb_ary_push(ary, rb_float_new(ir.y)); 
     71  rb_ary_push(ary, rb_float_new(ir.z)); 
     72  rb_ary_push(ary, rb_float_new(gforce.x)); 
     73  rb_ary_push(ary, rb_float_new(gforce.y)); 
     74  rb_ary_push(ary, rb_float_new(gforce.z)); 
     75 
     76  return ary; 
     77} 
     78void Init_Wii() 
     79{ 
     80  // define class Wii 
     81  rb_cWii = rb_define_class("Wii", rb_cObject); 
     82  rb_define_singleton_method(rb_cWii, "hello",   rb_wii_s_hello,  2); 
     83  rb_define_singleton_method(rb_cWii, "wpad",    rb_wii_s_wpad,   1); 
     84  rb_define_singleton_method(rb_cWii, "usleep",  rb_wii_s_usleep, 1); 
     85} 
     86 
     87 
     88 
    3089static VALUE __eval0(char* script, int print_script) 
    3190{ 
     
    41100  }else{ 
    42101    obj = rb_eval_string_protect("$!", &state); 
    43     printf("%s", ANSI_FG_RED); 
     102    printf("%s", ANSI_FG_YELLOW); 
    44103    rb_p(obj); 
    45104    printf("%s", ANSI_FG_WHITE); 
     
    49108static VALUE __eval(char* script) 
    50109{ 
    51   __eval0(script, true); 
     110  return __eval0(script, true); 
    52111} 
    53112 
     
    69128 
    70129  // ANSI COLOR 
     130  /* 
    71131  rb_eval_string("RED     = \"\\x1B[31m\""); 
    72132  rb_eval_string("GREEN   = \"\\x1B[32m\""); 
     
    76136  rb_eval_string("CYAN    = \"\\x1B[36m\""); 
    77137  rb_eval_string("WHITE   = \"\\x1B[37m\""); 
    78  
     138  */ 
     139 
     140  Init_Wii(); 
    79141  return 0; 
    80142} 
     
    132194} 
    133195 
    134 int rubwii_WPAD_ScanPads() 
    135 { 
    136   WPAD_ScanPads(); 
    137   u32 wpaddown = WPAD_ButtonsDown(0); 
    138   u32 wpadheld = WPAD_ButtonsHeld(0); 
     196void test_time(void) 
     197{ 
     198  // timesupp.h 
     199  // time_t time(time_t *timer); 
     200  // unsigned int nanosleep(struct timespec *tb); 
     201  // timesupp.c 
     202  int i; 
     203  time_t t; 
     204  int ret; 
     205  struct timespec ts; 
     206  for(i=0; i<20; i++){ 
     207    t = time(NULL); 
     208    ret = clock_gettime(&ts); 
     209    printf("%2d %10ld %10ld %20lu\n", i, t, ts.tv_sec, (unsigned long)ts.tv_nsec); 
     210    usleep(100*1000); 
     211  } 
    139212} 
    140213 
     
    169242  ret = WPAD_Init(); 
    170243  printf("WPAD_Init:ret=%d\n", ret); 
     244  ret = WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR); 
     245  printf("WPAD_SetDataFormat:ret=%d\n", ret); 
    171246 
    172247  ret = initialize_network(); 
     
    178253  ret = rubwii_init(); 
    179254  printf("rubwii_init:ret=%d\n", ret); 
     255 
     256  test_time(); 
    180257 
    181258  count = 50000; 
     
    210287        } 
    211288        if(wpaddown & WPAD_BUTTON_A){ 
    212           count = (count+2000)%1000; 
     289          count = (count+2000)/1000*1000; 
    213290        } 
    214291    if(count%1000==0){