System Time

Post Reply
kiwimaddog
Posts: 6
Joined: Mon Aug 25, 2008 4:00 pm

System Time

Post by kiwimaddog » Sun Aug 31, 2008 11:50 am

Does anyone know how to get the system time from the Wii/GC?

Thanks
David

Jeireff
Posts: 7
Joined: Tue Sep 02, 2008 12:36 am

Re: System Time

Post by Jeireff » Wed Sep 03, 2008 9:57 pm

Hi.
It's no Problem to get the system time.
Just o this:

Code: Select all

/* localtime example */
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "Current local time and date: %s", asctime (timeinfo) );
  
  return 0;
}
If you need more information, you can look here:
http://www.cplusplus.com/reference/clibrary/ctime/





A litte demo to use it on your wii. A modified WinterMute Demo.
If you press A, you can see the aktually time in the
"Button Down Field"

Code: Select all

//code by WinterMute
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <stdarg.h>
#include <ctype.h>
#include <math.h>
#include <wiiuse/wpad.h>

#include <stdio.h>
#include <time.h>
 
static GXRModeObj *rmode = NULL;
 
//-----------------------------------------------------------------------------------
 
int doreload=0, dooff=0;
 
void reload(void) {
	doreload=1;
}
 
void shutdown(void) {
	dooff=1;
}
 
void drawdot(void *xfb, GXRModeObj *rmode, float w, float h, float fx, float fy, u32 color) {
	u32 *fb;
	int px,py;
	int x,y;
	fb = (u32*)xfb;
 
	y = fy * rmode->xfbHeight / h;
	x = fx * rmode->fbWidth / w / 2;
 
	for(py=y-4; py<=(y+4); py++) {
		if(py < 0 || py >= rmode->xfbHeight)
				continue;
		for(px=x-2; px<=(x+2); px++) {
			if(px < 0 || px >= rmode->fbWidth/2)
				continue;
			fb[rmode->fbWidth/VI_DISPLAY_PIX_SZ*py + px] = color;
		}
	}
 
}
 
int evctr = 0;
 
void countevs(int chan, const WPADData *data) {
	evctr++;
}
 
int main(int argc, char **argv) {
	int res;
 
	void *xfb[2];
	u32 type;
	int i;
	int fbi = 0;
	float theta;
	WPADData *wd;
 
	VIDEO_Init();
	PAD_Init();
	WPAD_Init();
 
	rmode = VIDEO_GetPreferredMode(NULL);
 
	xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
 
	VIDEO_Configure(rmode);
	VIDEO_SetNextFramebuffer(xfb);
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
 
	SYS_SetResetCallback(reload);
	SYS_SetPowerCallback(shutdown);
 
	WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
	WPAD_SetVRes(0, rmode->fbWidth, rmode->xfbHeight);
 
	while(!doreload && !dooff) {
		CON_Init(xfb[fbi],0,0,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
		//VIDEO_ClearFrameBuffer(rmode,xfb[fbi],COLOR_BLACK);
		printf("\n\n\n");
		WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
		res = WPAD_Probe(0, &type);
		switch(res) {
			case WPAD_ERR_NO_CONTROLLER:
				printf("  Wiimote not connected\n");
				break;
			case WPAD_ERR_NOT_READY:
				printf("  Wiimote not ready\n");
				break;
			case WPAD_ERR_NONE:
				printf("  Wiimote ready\n");
				break;
			default:
				printf("  Unknown Wimote state %d\n",res);
 
		}
		printf("  Event count: %d\n",evctr);
		if(res == WPAD_ERR_NONE) {
			wd = WPAD_Data(0);
			printf("  Data->Err: %d\n",wd->err);
			printf("  IR Dots:\n");
			for(i=0; i<4; i++) {
				if(wd->ir.dot[i].visible) {
					printf("   %4d, %3d\n", wd->ir.dot[i].rx, wd->ir.dot[i].ry);
				} else {
					printf("   None\n");
				}
			}
			if(wd->ir.valid) {
				printf("  Cursor: %.02f,%.02f\n",wd->ir.x, wd->ir.y);
				printf("    @ %.02f deg\n",wd->ir.angle);
			} else {
				printf("  No Cursor\n\n");
			}
			if(wd->ir.raw_valid) {
				printf("  Distance: %.02fm\n", wd->ir.z);
				printf("  Yaw: %.02f deg\n", wd->orient.yaw);
			} else {
				printf("\n\n");
			}
			printf("  Accel:\n");
			printf("   XYZ: %3d,%3d,%3d\n",wd->accel.x,wd->accel.y,wd->accel.z);
			printf("   Pitch: %.02f\n",wd->orient.pitch);
			printf("   Roll:  %.02f\n",wd->orient.roll);
			printf("  Buttons down:\n   ");
			if(wd->btns_h & WPAD_BUTTON_A){
			  time_t rawtime;
			  struct tm * timeinfo;

			  time ( &rawtime );
			  timeinfo = localtime ( &rawtime );
			  printf ( "Current local time and date: %s", asctime (timeinfo) );
    		}
			if(wd->btns_h & WPAD_BUTTON_B) printf("B ");
			if(wd->btns_h & WPAD_BUTTON_1) printf("1 ");
			if(wd->btns_h & WPAD_BUTTON_2) printf("2 ");
			if(wd->btns_h & WPAD_BUTTON_MINUS) printf("MINUS ");
			if(wd->btns_h & WPAD_BUTTON_HOME) printf("HOME ");
			if(wd->btns_h & WPAD_BUTTON_PLUS) printf("PLUS ");
			printf("\n   ");
			if(wd->btns_h & WPAD_BUTTON_LEFT) printf("LEFT ");
			if(wd->btns_h & WPAD_BUTTON_RIGHT) printf("RIGHT ");
			if(wd->btns_h & WPAD_BUTTON_UP) printf("UP ");
			if(wd->btns_h & WPAD_BUTTON_DOWN) printf("DOWN ");
			printf("\n");
			for(i=0; i<4; i++) {
				if(wd->ir.dot[i].visible) {
					drawdot(xfb[fbi], rmode, 1024, 768, wd->ir.dot[i].rx, wd->ir.dot[i].ry, COLOR_YELLOW);
				}
			}
			if(wd->ir.raw_valid) {
				for(i=0; i<2; i++) {
					drawdot(xfb[fbi], rmode, 4, 4, wd->ir.sensorbar.rot_dots[i].x+2, wd->ir.sensorbar.rot_dots[i].y+2, COLOR_GREEN);
				}
			}
			if(wd->ir.valid) {
				theta = wd->ir.angle / 180.0 * 3.1415;
				drawdot(xfb[fbi], rmode, rmode->fbWidth, rmode->xfbHeight, wd->ir.x, wd->ir.y, COLOR_RED);
				drawdot(xfb[fbi], rmode, rmode->fbWidth, rmode->xfbHeight, wd->ir.x + 10*sinf(theta), wd->ir.y - 10*cosf(theta), COLOR_BLUE);
			}
			if(wd->btns_h & WPAD_BUTTON_1) doreload=1;
		}
		VIDEO_SetNextFramebuffer(xfb[fbi]);
		VIDEO_Flush();
		VIDEO_WaitVSync();
		fbi ^= 1;
	}
	if(doreload) return 0;
	if(dooff) SYS_ResetSystem(SYS_SHUTDOWN,0,0);
 
	return 0;
}
I hope it will help you :-D

kiwimaddog
Posts: 6
Joined: Mon Aug 25, 2008 4:00 pm

Re: System Time

Post by kiwimaddog » Thu Sep 04, 2008 6:15 pm

Thanks for your reply. Do you know how I could get milliseconds. The reason why I ask is that normaly I would use something like GetTickCount to set when to update world lets say every 25fps. However, I'm unable to use that and was hoping this would do the trick.
Thanks
David

Jeireff
Posts: 7
Joined: Tue Sep 02, 2008 12:36 am

Re: System Time

Post by Jeireff » Thu Sep 04, 2008 11:09 pm

I think it's no problem to handle with milliseconds.

here is a part of a sourecode from a Homwbrewapp called "Shut"
you can get the completed code with grafix and so on here:
http://wiibrew.org/wiki/List_of_homebre ... ns_(demos)

By the way, I've think you have to include this before:
#include <ogc/lwp_watchdog.h>

Here the example:

Code: Select all

		if(selected>0 && selected!=current){
			over.SetPosition((*selectedsprite).GetX(),(*selectedsprite).GetY()); 
			over.SetVisible(true);
			if(!rumbeling){
                             
                                // Is this what you'r searching for?
				time2rumble = ticks_to_millisecs(gettime());
				WPAD_Rumble(0,1);
				rumbeling = true;


			}
			current = selected;
		}
		
                // Here he used it again ^^
		//stop rumble after 50ms
		if(ticks_to_millisecs(gettime())>time2rumble+50 && rumbeling){ WPAD_Rumble(0,0); }
		//let it rumble again after 250ms
		if(ticks_to_millisecs(gettime())>time2rumble+250 && rumbeling){ rumbeling = false; }
EDIT: Ähm, there is something you have to know, too. time2rumble is a u64

I hope it can help you ;-D

Greetz,
Jeireff

kiwimaddog
Posts: 6
Joined: Mon Aug 25, 2008 4:00 pm

Re: System Time

Post by kiwimaddog » Fri Sep 05, 2008 7:49 pm

Perfect! That's exactly what I needed!
Thanks once again for your help!

David

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest