Ejemplo n.º 1
0
/**
 * Simple use case for the text box.
 * This program will show a text box and
 * retrieve the text entered by the user.
 */
extern "C" int MAMain() {
	// Initializations
	const wchar* title = L"My Title";
	const wchar* text = L"My Text";
	const int length = 1024;
	wchar buf[length];

	// Shows the text box
	// Returns when the text box is ready
	// to receive input
	maTextBox(title, text, buf, length, 0);

	// Event loop
	MAEvent event;
	maWait(0);
	while(maGetEvent(&event))
	{
		// Exit when the fire key is pressed
		if(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_FIRE) {
			maExit(0);
		}
		// When the TextBox closes, display the result (OK or CANCEL),
		// the text retrieved, and its length
		if( event.type == EVENT_TYPE_TEXTBOX ) {
			printf("Result (OK = 1 ; CANCEL = 2): %d\n", event.textboxResult);
			wprintf(L"The text box contained: %s\n", buf);
			printf("Length of the text: %d\n", event.textboxLength);
			printf("Press fire to exit...\n");
		}
		maWait(0);
	}
	return 0;
}
Ejemplo n.º 2
0
extern "C" int MAMain() {
	int discoveryState;
	InitConsole();
	gConsoleLogging = 1;

	printf("Hello World!\n");
	discoveryState = maWlanStartDiscovery();
	printf("WLAN: %i\n", discoveryState);
	
	while(1) {
		maWait(0);
		MAEvent event;
		if(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE)
				break;
			if(event.type == EVENT_TYPE_KEY_PRESSED) {
				if(event.key == MAK_0)
					break;
				if(event.key == MAK_FIRE && discoveryState == 1) {
					discoveryState = maWlanStartDiscovery();
					printf("WLAN: %i\n", discoveryState);
				}
			}
			if(event.type == EVENT_TYPE_WLAN) {
				printf("State %i\n", event.state);
				dumpAllAvailableAps();
				printf("Done.\n");
				discoveryState = event.state;
			}
		}
	}
	return 0;
}
Ejemplo n.º 3
0
void testReadOverload(const char* url) {
	Handle conn = maConnect(url);
	if(conn < 0) {
		printf("maConnect error %i\n", conn);
		return;
	}

	int result = 0;
	char buffer[1024];
	while(result >= 0) {
		EVENT event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_CONN) {
				printf("Op %i result %i\n", event.conn.opType, event.conn.result);
				MAASSERT(event.conn.handle == conn);
				result = event.conn.result;
				MAASSERT(result != 0);
			}
		}
		if(result == 0) {
			maWait(0);
		} else {
			maConnRead(conn, buffer, sizeof(buffer));
		}
	}
	printf("Done.\n");
}
Ejemplo n.º 4
0
extern "C" int MAMain() {
	int res;

	InitConsole();

	printf("CreateData\n");
	maCreateData(RES, 386);
	printf("DestroyObject\n");
	maDestroyObject(RES);

	printf("HTTP GET\n");
	//res = myHttpGetToObject(1, "http://dev.mopix.se:8080/testing/mobile.php");
	{
		MAUtil::HttpGetToObject http("http://link.astando.se/astwms/Request.aspx?REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&LAYERS=TO_Vattenytor,TO_Oppen_mark,TO_Byggnadsytor,TO_Vagkonturer,Vagkanter,TO_Geografiska_texter,TO_Allm_byggnadsnamn,Gatunamn&STYLES=&FORMAT=png&BGCOLOR=0xFF0000&TRANSPARENT=TRUE&SRS=EPSG:3152&BBOX=78202.0228224145,99374.2252203757,79546.909389597,100413.827113304&WIDTH=240&HEIGHT=188&reaspect=false", RES);
		res = http.state();
		while(res == 0) {
			EVENT event;
			maWait(0);
			while(maGetEvent(&event)) {
				if(event.type == EVENT_TYPE_CLOSE ||
					(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
				{
					maExit(0);
				} else if(event.type == EVENT_TYPE_CONN) {
					printf("cE %i %i %i\n", event.conn.handle, event.conn.opType, event.conn.result);
					http.notify(event.conn);
					res = http.state();
				}
			}
		}
	}
	printf("Got %i\n", res);
	FREEZE;
}
//de main functie
extern "C" int MAMain()
{
    MAEvent event;

    //nieuw sneeuwlandschap
    SneeuwLandschap* sneeuwLandschap = new SneeuwLandschap();

    //oneindige loop laat onze app in werking
    while (TRUE)
    {
        //run met 1 frame per 100 ms
        maWait(100);

        //kijk of er events hebben plaatsgevonden, sla die info op in MAEvent event.
        maGetEvent(&event);

        //als een event de app wil sluiten...
        if (EVENT_TYPE_CLOSE == event.type)
        {
            // Exit while loop.
            break;
        }

        //handel alle logica van sneeuwlandschap af
        sneeuwLandschap->run( event );

        //teken het sneeuwlandschap
        sneeuwLandschap->draw();

        //vergeet het scherm niet te updaten!
        maUpdateScreen();
    }

    return 0;
}
Ejemplo n.º 6
0
	void runEventLoop()
	{
		MAEvent event;

		bool isRunning = true;
		while (isRunning)
		{
			maWait(0);
			while (maGetEvent(&event) && isRunning)
			{
				switch (event.type)
				{
					case EVENT_TYPE_CLOSE:
						isRunning = false;
						break;

					case EVENT_TYPE_KEY_PRESSED:
						// Exit the app if the back key (on Android) is pressed.
						if (event.key == MAK_BACK)
						{
							isRunning = false;
						}
						break;

					case EVENT_TYPE_WIDGET:
						handleWidgetEvent((MAWidgetEventData*) event.data);
						break;

					case EVENT_TYPE_LOCATION:
						handleGeoLocationEvent((MALocation*) event.data);
						break;
				}
			}
		}
	}
Ejemplo n.º 7
0
/**
 * Entry point of the program.
 */
int MAMain()
{
	MAEvent event;

	printf("Press zero or back to exit");

	while (TRUE)
	{
		maWait(0);
		maGetEvent(&event);

		if (EVENT_TYPE_CLOSE == event.type)
		{
			// Exit while loop.
			break;
		}
		else if (EVENT_TYPE_KEY_PRESSED == event.type)
		{
			if (MAK_BACK == event.key || MAK_0 == event.key)
			{
				// Exit while loop.
				break;
			}

			printf("You typed: %c", event.key);
		}
	}

	return 0;
}
Ejemplo n.º 8
0
void MoSyncStub::sleep(uint32 duration) {
	int startTime = maGetMilliSecondCount();
	do {
		int curTime = maGetMilliSecondCount() - startTime;
		if(curTime>=(int)duration) break;
		maWait(duration-curTime);
	} while(true);
}
Ejemplo n.º 9
0
void MoSyncStub::sleep(uint32 duration) {
	uint32 startTime = getTimeStamp();
	do {
		uint32 curTime = getTimeStamp() - startTime;
		if(curTime>=duration) break;
		maWait(duration-curTime);
	} while(true);
}
Ejemplo n.º 10
0
void testConnectOverload(const char* url, bool acceptSuccess) {
	int connects = 0, events = 0;
	int result = 0;
	int conn;
	bool hasConn = false;
	MAUtil::Vector<Handle> conns;
	do {
		EVENT event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_CONN) {
				printf("Op %i conn %i result %i\n", event.conn.opType, event.conn.handle, event.conn.result);
				MAASSERT(event.conn.opType == CONNOP_CONNECT);
				conn = event.conn.handle;
				if(acceptSuccess) {
					if(event.conn.result < 0) {
						result = event.conn.result;
					}
				} else {
					result = event.conn.result;
				}
				MAASSERT(event.conn.result != 0);
				hasConn = true;
				events++;
				printf("Event %i\n", events);
				break;
			}
		}
		if(result == 0) {
			conn = maConnect(url);
			conns.add(conn);
			if(conn < 0) {
				printf("maConnect error %i\n", conn);
				result = conn;
				hasConn = false;
			} else {
				connects++;
				printf("Connect %i\n", connects);
			}
		} else if(events != connects)
			maWait(0);
	} while(events != connects);// && connects < 3);
	if(hasConn) {
		printf("Result %i on handle %i after %i connects\n", result, conn, connects);
	} else {
		printf("Result %i after %i connects\n", result, connects);
	}
	printf("Closing %i handles\n", conns.size());
	for(int i=0; i<conns.size(); i++) {
		maConnClose(conns[i]);
	}
	printf("Done.\n");
}
Ejemplo n.º 11
0
void MoSyncStub::sleep(uint32 duration) {
	int startTime = maGetMilliSecondCount();
	int dur = (int)duration;
	do {
		int curTime = maGetMilliSecondCount() - startTime;
		if(curTime>=dur) break;
		maWait(dur-curTime);
	} while(true);

	processEvents();
}
Ejemplo n.º 12
0
// swipe handler for pointerReleaseEvent()
void AnsiWidget::doSwipe(int start, bool moveDown, int distance, int maxScroll) {
  MAEvent event;
  int elapsed = 0;
  int vscroll = _front->_scrollY;
  int scrollSize = distance / 3;
  int swipeStep = SWIPE_DELAY_STEP;
  while (elapsed < SWIPE_MAX_TIMER) {
    if (maGetEvent(&event) && event.type == EVENT_TYPE_POINTER_RELEASED) {
      // ignore the next move and release events
      _swipeExit = true;
      break;
    }
    elapsed += (maGetMilliSecondCount() - start);
    if (elapsed > swipeStep && scrollSize > 1) {
      // step down to a lesser scroll amount
      scrollSize -= 1;
      swipeStep += SWIPE_DELAY_STEP;
    }
    if (scrollSize == 1) {
      maWait(20);
    }
    vscroll += moveDown ? scrollSize : -scrollSize;
    if (vscroll < 0) {
      vscroll = 0;
    } else if (vscroll > maxScroll) {
      vscroll = maxScroll;
    }
    if (vscroll != _front->_scrollY) {
      _front->_dirty = true; // forced
      _front->_scrollY = vscroll;
      flush(true, true);
    } else {
      break;
    }
  }

  // pause before removing the scrollbar
  maWait(500);
}
Ejemplo n.º 13
0
void Freeze(int val) {
	maUpdateScreen();
	for(;;) {
		MAEvent event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED &&
				(event.key == MAK_0 || event.key == MAK_BACK)))
			{
				maExit(val);
			}
		}
		maWait(0);
	}
}
Ejemplo n.º 14
0
	//TestCase
	void start() {
		printf("Don't touch anything now...\n");
		MAEvent e;
		while(maGetEvent(&e)) {	//clear event buffer
			if(e.type == EVENT_TYPE_CLOSE)
				maExit(0);
		}
		int startTime = maGetMilliSecondCount();
		maWait(TEST_TIMEOUT);
		int delta = maGetMilliSecondCount() - startTime;
		bool success = delta > TEST_TIMEOUT - TEST_TIME_EPSILON;
		printf("%s (%i ms)\n", success ? "Success" : "Failure", delta);
		assert(name, success);
		suite->runNextCase();
	}
Ejemplo n.º 15
0
void sleep(int s) {
	lprintfln("sleep(%i)", s);
	const int start = maGetMilliSecondCount();
	const int end = start + s * 1000;
	do {
		int left = end - maGetMilliSecondCount();
		int res;
		MAEvent e;
		if(left <= 0)
			break;
		while(maGetEvent(&e)) {
			if(e.type = EVENT_TYPE_CLOSE) {
				lprintfln("EVENT_TYPE_CLOSE");
				exit(42);
			}
		}
		maWait(left);
	} while(1);
}
Ejemplo n.º 16
0
int MAMain() {
	maSetColor(0xFFFFFF);
	maDrawText(0,0, "Hello World!");
	maUpdateScreen();

	//Freeze
	while(1) {
		maWait(0);
		EVENT event;
		if(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE)
				break;
			if(event.type == EVENT_TYPE_KEY_PRESSED) {
				if(event.key == MAK_0)
					break;
			}
		}
	}
	return 0;

}
Ejemplo n.º 17
0
unsigned sleep(unsigned s) {
	lprintfln("sleep(%i)", s);
	const int start = maGetMilliSecondCount();
	const int end = start + s * 1000;
	do {
		int left = end - maGetMilliSecondCount();
		MAEvent e;
		if(left <= 0)
			break;
		while(maGetEvent(&e)) {
			if(e.type == EVENT_TYPE_CLOSE) {
				lprintfln("EVENT_TYPE_CLOSE");
				exit(42);
			}
		}
		maWait(left);
	} while(1);
	int passed = maGetMilliSecondCount() - start;
	MAASSERT(passed >= (int)s*1000);
	return 0;
}
Ejemplo n.º 18
0
/**
 * Wait for a pointer released event.
 */
void waitForClick()
{
    printf("\nTap the screen to continue......\n");
    printf(sFieldSeparator);
    MAEvent event;

    while (true)
    {
        // Wait for a event.
        maWait(-1);

        // Get the event.
        maGetEvent(&event);

        // Check if the event is pointer released.
        if (EVENT_TYPE_POINTER_RELEASED == event.type)
        {
            break;
        }
    }
}
Ejemplo n.º 19
0
int MAMain()
{
	//MAExtent e = maGetScrSize();

	/// play R_MOSO sound
	maSoundPlay(SOUND_RESOURCE, 0, maGetDataSize(SOUND_RESOURCE));

	printf("Press 0/RSK to exit.");

	while(1) {
		maWait(0);
		MAEvent event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && 
				(event.key == MAK_0 || event.key == MAK_SOFTRIGHT || event.key == MAK_BACK)))
			{
				maExit(0);
			}
		}
	}
}
Ejemplo n.º 20
0
int waitConn(Handle conn) {
    while(1) {
        EVENT event;
        if(maGetEvent(&event)) {
            if(event.type == EVENT_TYPE_CLOSE ||
                    (event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
            {
                maConnClose(conn);
                maExit(0);
            } else if(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_1) {
                maConnClose(conn);
            } else if(event.type == EVENT_TYPE_CONN) {
                printf("Result: %i\n", event.conn.result);
                /*if(event.conn.result <= 0) {
                	Freeze(0);
                }*/
                return event.conn.result;
            }
        }
        maWait(0);
    }
}
Ejemplo n.º 21
0
Archivo: main.c Proyecto: Felard/MoSync
int AnimatedConnWait() {
	int startTime = maGetMilliSecondCount();
	int res;
#ifdef ANIMATED
	int lPos = gPos;
	int i=0;
	int screenWidth = EXTENT_X(maGetScrSize());

	maSetColor(0);
	maFillRect(0, lPos, screenWidth - 1, gTextHeight);
	printlnf("a%i",i++);
#endif	//ANIMATED
	while(1) {
		EVENT event;

#ifdef ANIMATED
		gPos = lPos;
		maSetColor(0);
		maFillRect(0, lPos, screenWidth - 1, gTextHeight);
		printlnf("b%i",i++);
#else
		maWait(0);
#endif	//ANIMATED

		if(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_CONN) {
				res = event.conn.result;
				break;
			}
		}
	}
	printlnf("w%i", maGetMilliSecondCount() - startTime);
	return res;
}
Ejemplo n.º 22
0
/**
 * Waits for an event and returns the event object.
 *
 * @param millisecondTimeout Maximum number of milliseconds to wait.
 * @param eventType Event type to wait for.
 * @param returnedEvent Event object [out].
 *
 * @return True if event was caught with the given time limit.
 */
bool EventBase::waitForEvent(int millisecondTimeout, int eventType, MAEvent &returnedEvent)
{
	MAEvent event;
	long startTime = maGetMilliSecondCount();

	while (maGetMilliSecondCount() - startTime < millisecondTimeout)
	{
		maWait(100);
		while(maGetEvent(&event) != 0)
		{
			if (event.type == eventType)
			{
				returnedEvent = event;
				return true;
			}
			else if (event.type == EVENT_TYPE_CLOSE)
			{
				maExit(0);
			}
		}
	}

	return false;
}
Ejemplo n.º 23
0
/**
 * Entry point of the program. The MAMain function
 * needs to be declared as extern "C".
 */
extern "C" int MAMain()
{
	MAEvent event;

	int imgSize = maGetImageSize(RES_BARCODE_IMAGE);

	int imgW = EXTENT_X(imgSize);
	int imgH = EXTENT_Y(imgSize);

	int imgDataSize = imgW * imgH;
	int* imgData = (int*) malloc(imgDataSize * 4);

	MARect imgRect;
	imgRect.left = 0;
	imgRect.top = 0;
	imgRect.width = imgW;
	imgRect.height = imgH;

	maGetImageData(RES_BARCODE_IMAGE, imgData, &imgRect, imgW);

	unsigned char* fixedImg = (unsigned char*) malloc(imgDataSize);

	printf("Converting image\n");

	createLuminosity(imgData, fixedImg, imgDataSize);

	printf("Scanning for barcodes\n");

	// create a reader
	zbar::ImageScanner scanner = zbar::zbar_image_scanner_create();

	// configure the reader
	zbar::zbar_image_scanner_set_config(scanner, zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);

	// wrap image data
	zbar::zbar_image_t *image = zbar::zbar_image_create();
	zbar::zbar_image_set_format(image, 0x30303859);// "Y800" = 0x30303859

	zbar::zbar_image_set_size(image, imgW, imgH);

	zbar::zbar_image_set_data(image, fixedImg, imgW * imgH, NULL);//zbar_image_free_data);

	// scan the image for barcodes
	zbar_scan_image(scanner, image);

	// extract results
	bool result = false;
	const zbar::zbar_symbol_t *symbol = zbar_image_first_symbol(image);
	for(; symbol; symbol = zbar_symbol_next(symbol)) {
		// do something useful with results
		zbar::zbar_symbol_type_t typ = zbar_symbol_get_type(symbol);
		const char *data = zbar_symbol_get_data(symbol);
		printf("decoded %s symbol \"%s\"\n",
			   zbar_get_symbol_name(typ), data);
		result = true;
	}

	// clean up
	zbar_image_destroy(image);

	if(!result)
		printf("No symbols found.\n");

	printf("Press zero, back or touch screen to exit\n");

	while (TRUE)
	{
		maWait(0);
		maGetEvent(&event);

		if (EVENT_TYPE_CLOSE == event.type)
		{
			// Exit while loop.
			break;
		}
		else if (EVENT_TYPE_KEY_PRESSED == event.type)
		{
			if (MAK_BACK == event.key || MAK_0 == event.key)
			{
				// Exit while loop.
				break;
			}
		}
		else if (EVENT_TYPE_POINTER_PRESSED == event.type)
		{
			break;
		}
	}

	return 0;
}
Ejemplo n.º 24
0
void scan() {
	int nserv=0;
	MAEvent event;
#ifdef SCAN_DEVICES
scan_devices:
	int ndev=0;
	MABtDevice d;
	char namebuf[256];
	int res;

	printf("DevDisc...\n");
	int startTime = maGetMilliSecondCount();
	maBtStartDeviceDiscovery(1);
	//printf("Started\n");

	while(true) {
		d.name = namebuf;
		d.nameBufSize = sizeof(namebuf);

		do {
			strcpy(namebuf, "Hello Debugger!");
			res = maBtGetNewDevice(&d);
			if(res) {
				printf("d%i: %i %s\n", ndev++, res, d.name);
				if(res < 0) {
					break;
				}
				printf("%s\n", btaddr2string(d.address));
			} else {
				printf("res %i\n", res);
			}
		} while(res > 0);

		maWait(0);
		maGetEvent(&event);	//this oughta work, cause maWait(0) guarantees that there's at least one event.
		if(event.type == EVENT_TYPE_BT && event.state != 0)
			break;
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_0 || event.key == MAK_KP0)))
		{
			maExit(0);
		}
	}
	printf("Done %i, %i ms\n", event.state, maGetMilliSecondCount() - startTime);

	printf("Press 1 or 3\n");
	while(true) {
		maWait(0);
		maGetEvent(&event);
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_0 || event.key == MAK_KP0)))
		{
			maExit(0);
		}
		if(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_1 || event.key == MAK_KP1)) {
			goto scan_devices;
		}
		if(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_3 || event.key == MAK_KP3)) {
			break;
		}
	}


	const MABtAddr& address = d.address;
#else
	//const MABtAddr address = { { 0x00, 0x0f, 0xde, 0xa1, 0x4b, 0x70 } };	//K700i Jacob
	//const MABtAddr address = { { 0x00, 0x0b, 0x0d, 0x14, 0x99, 0x0f } };	//Holux
	//const MABtAddr address = { { 0x00, 0x11, 0x9f, 0xcb, 0x74, 0x10 } };	//6630 v1.0
	//const MABtAddr address = { { 0x00, 0x18, 0xc5, 0x3f, 0x74, 0x7e } };	//N73
	//const MABtAddr address = { { 0x00, 0x80, 0x98, 0x44, 0x74, 0xc8 } };	//MS-FREDRIK
	//const MABtAddr address = { { 0x00, 0x11, 0x67, 0x9c, 0xd9, 0x3c } };	//MS-FREDRIK, new dongle
	const MABtAddr address = { { 0x00, 0x23, 0x3a, 0xb3, 0xc7, 0x82 } };	//Samsung SGH-i900
#endif	//SCAN_DEVICES

	printf("ServDisc %s\n", btaddr2string(address));
	int servStartTime = maGetMilliSecondCount();
	maBtStartServiceDiscovery(&address, &L2CAP_PROTOCOL_MAUUID);

	while(true) {
		MABtService s;
		char sNameBuf[256];
		static const int MAX_UUIDS = 32;
		MAUUID uuidBuf[MAX_UUIDS];
		int res;
		s.name = sNameBuf;
		s.nameBufSize = sizeof(sNameBuf);
		s.uuids = uuidBuf;

		//printfln("state: %i\n", maBtDiscoveryState2());
		do {
			strcpy(sNameBuf, "Hello Sebugger!");
			MABtServiceSize ss;
			res = maBtGetNextServiceSize(&ss);
			if(res) {
				MAASSERT(ss.nUuids <= MAX_UUIDS);
				if(ss.nameBufSize < 0) {
					printf("%i\n", ss.nameBufSize);
				}
				res = maBtGetNewService(&s);
				if(res) {
					if(ss.nameBufSize < 0) {
						printf("s%i: %i %i No name\n", nserv++, res, s.port);
					} else {
						printf("s%i: %i %i %i \"%s\"\n", nserv++, res, s.port, ss.nameBufSize, s.name);
					}
					/*for(int j=0; j<ss.nUuids; j++) {
						int* u = s.uuids[j].i;
						printf("%08X-%08X-%08X-%08X\n", u[0], u[1], u[2], u[3]);
					}*/
					if(res < 0) {
						//printf("res1 %i\n", res);
						break;
					}
				} else {
					//printf("res2 %i\n", res);
				}
			} else {
				//printf("res3 %i\n", res);
			}
		} while(res > 0);

		maWait(0);
		maGetEvent(&event);
		if(event.type == EVENT_TYPE_BT) {
			//printf("event %i\n", event.state);
			if(event.state != 0)
				break;
		}
		if(event.type == EVENT_TYPE_CLOSE ||
			(event.type == EVENT_TYPE_KEY_PRESSED && (event.key == MAK_0 || event.key == MAK_KP0)))
		{
			maExit(0);
		}
	}
	printf("Done %i, %i ms\n", event.state, maGetMilliSecondCount() - servStartTime);
#ifdef SCAN_DEVICES
	printf("Done, total %i ms\n", maGetMilliSecondCount() - startTime);
#endif	//SCAN_DEVICES
}
Ejemplo n.º 25
0
int RenderMain ( void )
{
	int 			tmrLast = 0;
	int 			currFps = 0,
					lastFps = 0;
	int 			frameIndex = 0;
	float 			frameInterp = 0;
	float			rotRadY = 0.0f,
					rotRadX = 0.0f;
	char			textBuffer[128];
	bool 			keyTable[4] = { false };
	bool focus = true;

	Matrix4fi		transMatrix( false );
	MAExtent		size = maGetScrSize( );
	MDLFixed 		model( RES_MODEL_OGRE );
	TransformPipe	pipe( EXTENT_X( size ), EXTENT_Y( size ) );


	// Center model
	model.centerModel( );

	tmrLast = maGetMilliSecondCount( );

	//
	// Rendering loop
	//
	while ( true )
	{
		//
		// Handle input
		//
		MAEvent e;
		while ( maGetEvent( &e ) )
		{
			if ( e.type == EVENT_TYPE_CLOSE ||
				 e.type == EVENT_TYPE_KEY_PRESSED ||
				 e.type == EVENT_TYPE_POINTER_PRESSED )
				maExit(0);
			else if(e.type == EVENT_TYPE_FOCUS_LOST)
				focus = false;
			else if(e.type == EVENT_TYPE_FOCUS_GAINED)
				focus = true;

			else if ( e.type == EVENT_TYPE_KEY_PRESSED )
			{
				if ( e.key == MAK_LEFT )
					keyTable[MAK_LEFT-MAK_UP] = true;
				else if ( e.key == MAK_RIGHT )
					keyTable[MAK_RIGHT-MAK_UP] = true;
				else if ( e.key == MAK_UP )
					keyTable[MAK_UP-MAK_UP] = true;
				else if ( e.key == MAK_DOWN )
					keyTable[MAK_DOWN-MAK_UP] = true;
			}
			else if ( e.type == EVENT_TYPE_KEY_RELEASED )
			{
				if ( e.key == MAK_LEFT )
					keyTable[MAK_LEFT-MAK_UP] = false;
				else if ( e.key == MAK_RIGHT )
					keyTable[MAK_RIGHT-MAK_UP] = false;
				else if ( e.key == MAK_UP )
					keyTable[MAK_UP-MAK_UP] = false;
				else if ( e.key == MAK_DOWN )
					keyTable[MAK_DOWN-MAK_UP] = false;
			}
		}

		if(focus) {
			if ( keyTable[MAK_LEFT-MAK_UP] )
				rotRadY -= (float)M_PI / 60;
			else if ( keyTable[MAK_RIGHT-MAK_UP] )
				rotRadY += (float)M_PI / 60;
			else if ( keyTable[MAK_UP-MAK_UP] )
				rotRadX -= (float)M_PI / 60;
			else if ( keyTable[MAK_DOWN-MAK_UP] )
				rotRadX += (float)M_PI / 60;

			rotRadX = (rotRadX >= 2*(float)M_PI) ? rotRadX-2*(float)M_PI : rotRadX;
			rotRadY = (rotRadY >= 2*(float)M_PI) ? rotRadY-2*(float)M_PI : rotRadY;

			//
			// Construct transformation pipe
			//
			pipe.resetPipe( );

			transMatrix.rotateX( (float)-M_PI/2 );
			pipe.addTransform( transMatrix );
			transMatrix.rotateY( (float)M_PI/4 );
			pipe.addTransform( transMatrix );

			transMatrix.rotateX( rotRadX );
			pipe.addTransform( transMatrix );
			transMatrix.rotateY( rotRadY );
			pipe.addTransform( transMatrix );
			transMatrix.translate( 0, 0, 130 );
			pipe.addTransform( transMatrix );


			// Clear screen
			maSetColor( 0 );
			maFillRect( 0, 0, EXTENT_X( size ), EXTENT_Y( size ) );

			//
			// Animate and render model
			//
			maSetColor( 0xffffff );
			model.drawFrameLerp( frameIndex, FLT2FIX( frameInterp ), pipe );
			frameInterp += 0.25f;
			if ( frameInterp >= 1.0f )
			{
				frameIndex  = (frameIndex+1) % model.getFrameCount( );
				frameInterp = 0.0f;
			}

			// Draw fps to screen
			sprintf( textBuffer, "fps: %d", lastFps );
			maDrawText( 0, 0, textBuffer );

			// Update screen and keep backlight on
			maUpdateScreen( );
			maResetBacklight( );

			// FPS counter
			currFps++;
			if ( tmrLast+1000 <= maGetMilliSecondCount( ) )
			{
				lastFps = currFps;
				currFps = 0;
				tmrLast = maGetMilliSecondCount( );
				lprintfln( "fps: %d", lastFps );
			}
		} else {	// no focus
			maWait(0);
		}
	}
}
Ejemplo n.º 26
0
Archivo: t8.c Proyecto: Felard/MoSync
int MAMain() {
	const MAExtent scrSize = maGetScrSize();
	const int scrHeight = EXTENT_Y(scrSize);
	const int scrWidth = EXTENT_X(scrSize);
start:	maSetColor(0x808080);
	maFillRect(0, 0, scrWidth, scrHeight);

	maSetColor(0xffffff);
#ifdef STDTEST
	maLine(50, 50, 100, 100);
	maUpdateScreen();
	maLine(50, -50, 100, -100);
	maUpdateScreen();
	maLine(-50, 50, -100, 100);
	maUpdateScreen();
	maLine(-50, -50, -100, -100);
	maUpdateScreen();
	maLine(-10, 20, 20, -10);	//5
	maUpdateScreen();
	maLine(-1, 1, 1, -1);	//6-7
	maUpdateScreen();
	maLine(-20, 10, 10, -20);	//8
	maUpdateScreen();
	maLine(-40, 40, 50, -100);	//9
	maUpdateScreen();
	maLine(172, 226, 176, 205);	//crash test dummy
	maUpdateScreen();
	maLine(-5, 1, 2, -1);
	maUpdateScreen();
#else	//Line pixel test
	maLine(1, 1, 1, 5);
	maUpdateScreen();
	maSetColor(0x00ffff);
	maLine(1, 2, 3, 2);
	maUpdateScreen();
	maSetColor(0xff00ff);
	maLine(2, 3, 0, 3);
	maUpdateScreen();
	maSetColor(0xff80ff);
	maLine(0, 4, 2, 4);
	maUpdateScreen();
	maSetColor(0xffffff);
	maLine(4, 5, 4, 1);
	maUpdateScreen();
#endif

	//Freeze
	while(1) {
		maWait(0);
		MAEvent event;
		if(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE)
				break;
			if(event.type == EVENT_TYPE_KEY_PRESSED) {
				if(event.key == MAK_0)
					break;
			}
		}
		goto start;
	}
	return 0;
}
Ejemplo n.º 27
0
// process events on the system event queue
MAEvent Controller::processEvents(int ms, int untilType) {
  MAEvent event;
  MAExtent screenSize;
  int loadPathSize = _loadPath.length();

  if (ms < 0 && untilType != -1) {
    // flush the display before pausing for target event
    if (isRunning()) {
      _output->flush(true);
    }
    maWait(ms);
    ms = EVENT_WAIT_NONE;
  }

  while (!isBreak() && maGetEvent(&event)) {
    switch (event.type) {
    case EVENT_TYPE_OPTIONS_BOX_BUTTON_CLICKED:
      if (_systemMenu) {
        handleMenu(event.optionsBoxButtonIndex);
        ms = EVENT_WAIT_NONE;
      } else if (isRunning()) {
        if (!_output->optionSelected(event.optionsBoxButtonIndex)) {
          dev_pushkey(event.optionsBoxButtonIndex);
        }
      }
      break;
    case EVENT_TYPE_SCREEN_CHANGED:
      screenSize = maGetScrSize();
      _output->resize(EXTENT_X(screenSize), EXTENT_Y(screenSize));
      os_graf_mx = _output->getWidth();
      os_graf_my = _output->getHeight();
      handleKey(SB_PKEY_SIZE_CHG);
      break;
    case EVENT_TYPE_POINTER_PRESSED:
      _touchX = _touchCurX = event.point.x;
      _touchY = _touchCurY = event.point.y;
      handleKey(SB_KEY_MK_PUSH);
      _output->pointerTouchEvent(event);
      break;
    case EVENT_TYPE_POINTER_DRAGGED:
      _touchCurX = event.point.x;
      _touchCurY = event.point.y;
      _output->pointerMoveEvent(event);
      break;
    case EVENT_TYPE_POINTER_RELEASED:
      _touchX = _touchY = _touchCurX = _touchCurY = -1;
      handleKey(SB_KEY_MK_RELEASE);
      _output->pointerReleaseEvent(event);
      break;
    case EVENT_TYPE_CLOSE:
      setExit(true);
      break;
    case EVENT_TYPE_KEY_PRESSED:
      handleKey(event.key);
      break;
    }
    if (untilType == EVENT_TYPE_EXIT_ANY ||
        untilType == event.type ||
        loadPathSize != _loadPath.length()) {
      // skip next maWait() - found target event or loadPath changed
      ms = EVENT_WAIT_NONE;
      break;
    }
  }

  if (ms != EVENT_WAIT_NONE) {
    maWait(ms);
  }
  return event;
}
Ejemplo n.º 28
0
void dev_delay(uint32_t ms) {
  g_system->getOutput()->flush(true);
  maWait(ms);
}
Ejemplo n.º 29
0
VALUE method_maWait(VALUE self, VALUE milliSecs) {
	int x = NUM2INT(milliSecs);
	maWait(x);
	return Qnil;
}
Ejemplo n.º 30
0
Archivo: main.c Proyecto: Felard/MoSync
int MAMain() {
	Handle conn;
	char ping[] = "ping\n";
	char buffer[1024];
	int res;

#ifdef CONPRINT
	InitConsole();
	gConsoleLogging = 1;
#endif

	//println("Socket test");
retry:
	printlnf("Connecting...");
	conn = maConnect("socket://130.237.3.104:6666");	//test DNS resolution
	res = AnimatedConnWait();
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}
	/*conn = maConnect("socket://217.25.35.146:81");	//test IP address reading
	res = AnimatedConnWait();
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}*/

	println("Writing...");
	maConnWrite(conn, ping, sizeof(ping));
	res = AnimatedConnWait();
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}

	println("Reading...");

	res = ConnReadAtLeast(conn, 4, sizeof(buffer), buffer);
	if(res <= 0) {
		printlnf("err %i", res);
		goto exit;
	}
	maConnClose(conn);

	printlnf("Got %i bytes", res);

	buffer[res] = 0;
	println(buffer);
	maUpdateScreen();

exit:
	println("Press a key");
	for(;;) {
		EVENT event;
		while(maGetEvent(&event)) {
			if(event.type == EVENT_TYPE_CLOSE ||
				(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
			{
				maExit(0);
			} else if(event.type == EVENT_TYPE_KEY_PRESSED) {
				goto retry;
			}
		}
		maWait(0);
	}
}