Exemplo n.º 1
0
SCROLL_WHEEL_DIRECTION GetScrollDirection()
{
	w1 = mTouchReadButton(1);
	w2 = mTouchReadButton(2);
	scrollBarState = GetScrollState(w1, w2);
			
	if ((scrollBarState != NO_TOUCH) && (g_isTouched == 0))
	{		
		g_isTouched = 1;
		g_touchStartVal = w1-w2;
	}
	
	if (scrollBarState == NO_TOUCH)
	{
		g_isTouched = 0;
		return NO_TOUCH;
	}

	if (g_isTouched && ((signed int)g_touchStartVal - ((signed int)w1-(signed int)w2)) > 100)
	{
		g_touchStartVal = w1-w2;
		return SCROLL_UP;
		
	}
	else if (g_isTouched && ((signed int)g_touchStartVal - ((signed int)w1-(signed int)w2)) < -100)
	{
		g_touchStartVal = w1-w2;
		return SCROLL_DOWN;
	}	
}
Exemplo n.º 2
0
void SelectLevel()
{
	unsigned char i, j;
	SCROLL_WHEEL_DIRECTION scrollDir;
	char buffer[32];
	oledPutROMString((ROM_STRING)"    SELECT  LEVEL    ",0,0);
	
	scrollDir = GetScrollDirection();

	if (scrollDir == SCROLL_UP)
	{
		if (g_menuSelected > 0)
			g_menuSelected --;
	}
	else if (scrollDir == SCROLL_DOWN)
	{
		if (g_menuSelected < (LEVELS-1))
			g_menuSelected ++;
	}	

	if ((g_menuSelected - firstLevel) == 3 && (firstLevel < (LEVELS-4)))
		firstLevel++;

	if ((g_menuSelected - firstLevel) == 0 && (firstLevel > 0))
		firstLevel--;

	j = 0;
	for (i = firstLevel; i < firstLevel+4; i++)
	{
		sprintf((char *)buffer, (const far rom char *)("       Level %d      "), i);

		if (g_menuSelected == i)
		{
			oledPutNegString((unsigned char *)buffer,j+2,0);
		}
		else
			oledPutString((unsigned char *)buffer,j+2,0);

		j++;
	}

	w1 = mTouchReadButton(3);
	if (w1 < 600)
	{
		DemoIntroState = 6;
		g_menuSelected = 1;
	}

	w1 = mTouchReadButton(0);
	if (w1 < 600)
	{
		DemoIntroState = 0xFF;
		g_level=g_menuSelected;
		loadLevel(g_level);
	}
}
Exemplo n.º 3
0
void CalibrateAcc()
{
	unsigned int w1;
	static unsigned int filterPass = 0;
	char buffer[64];

	ReadAccState();
	
	axisX += g_devAccelerationX-g_devAccOffsetX;
	axisY += g_devAccelerationY-g_devAccOffsetY;
	//axisZ += g_devAccelerationZ-g_devAccOffsetZ;
	
	if (filterPass == 200)
	{
		oledPutROMString((ROM_STRING)"   CALIBRATE SENSOR  ",0,0);
		sprintf((char *)buffer, (const far rom char *)("   X:  %d             "), axisX/200);
		oledPutString((unsigned char *)buffer,2,0);
		sprintf((char *)buffer, (const far rom char *)("   Y:  %d             "), axisY/200);
		oledPutString((unsigned char *)buffer,3,0);
	
		axisX = 0;
		axisY = 0;
		//axisZ = 0;
	
		filterPass = 0;
	}

	w1 = mTouchReadButton(0);

	if (w1 < 600)
	{
		g_devAccOffsetX = g_devAccelerationX;
		g_devAccOffsetY = g_devAccelerationY;
		//g_devAccOffsetZ = g_devAccelerationZ;
	}

	w1 = mTouchReadButton(3);
	if (w1 < 600)
	{
		DemoIntroState = 6;
	}

	filterPass ++;
}
Exemplo n.º 4
0
void mTouchCalibrate(void)
{
	unsigned int Vread;
	unsigned char i;

	for (i = 0; i < MTOUCH_CHANNELS; i++)
	{
		g_mTouchCalibrationITRIM[i] = 0;

		Vread =  mTouchReadButton(i);
		if (Vread < 800)
		{
			do
			{
				if (g_mTouchCalibrationITRIM[i] == 0x1F)
				{
					/* Callibration failed */
					g_mTouchCalibrationITRIM[i] = 0;
					break;
				}
				g_mTouchCalibrationITRIM[i] ++;
				Vread = mTouchReadButton(i);
			}while (Vread < 800);	
		}
		else if(Vread > 800)
		{
			do
			{
				if (g_mTouchCalibrationITRIM[i] == 0xE1)
				{
					/* Callibration failed */
					g_mTouchCalibrationITRIM[i] = 0;
					break;
				}
				g_mTouchCalibrationITRIM[i] --;
				Vread = mTouchReadButton(i);
			}while (Vread > 800);	
		}
	}
}
Exemplo n.º 5
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{   
    //BMA150_REG reg_MSB;
    //BMA150_REG reg_LSB;
	unsigned int w1;

	if(DemoIntroState == 0xFF)
    {
	    //BL_CheckLoaderEnabled();
		
		if (g_ballGth == 0 && g_ballGtt == 0)
			Step(0.04f, 1);
		else
			Step(0.04f, 0);
		DrawScene();

		if (g_endGame == 1)
		{
			g_endGame = 0;
			DemoIntroState = 8;
		}
		
		w1 = mTouchReadButton(3);
		if (w1 < 600)
		{
			DemoIntroState = 6;
			g_menuSelected = 0;
			FillDisplay(0x00);
		}
		
    }
	
    // User Application USB tasks
    //if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

	// Soft Start the APP_VDD
    if(AppPowerReady() == FALSE) return;

    DemoIntroduction();
}		//end ProcessIO
Exemplo n.º 6
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{
    if(DemoIntroState == 0xFF)
    {
        BL_CheckLoaderEnabled();
    }

    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    // Soft Start the APP_VDD
    if(AppPowerReady() == FALSE) return;

    DemoIntroduction();

    if(!HIDRxHandleBusy(USBOutHandle))        //Check if data was received from the host.
    {

        switch(ReceivedDataBuffer[0])       //Look at the data the host sent, to see what kind of application specific command it sent.
        {
        case 0x80:  //mTouch callibration command
            mTouchCalibrate();
            break;

        case 0x20:
        {
            WORD potVoltage;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                /* Select ADC channel */
                ADCON0bits.CHS = 4;

                /* Make sure A/D interrupt is not set */
                PIR1bits.ADIF = 0;

                /* Begin A/D conversion */
                ADCON0bits.GO=1;
                //Wait for A/D convert complete
                while(!PIR1bits.ADIF);

                /* Get the value from the A/D */
                potVoltage = ADRES;

                ToSendDataBuffer[0] = 0x20;
                ToSendDataBuffer[1] = (BYTE)(potVoltage);
                ToSendDataBuffer[2] = (BYTE)(potVoltage>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
        break;

        case 0x30:
        {
            WORD w;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                w = mTouchReadButton(0);

                ToSendDataBuffer[0] = 0x30;
                ToSendDataBuffer[1] = (BYTE)w;
                ToSendDataBuffer[2] = (BYTE)(w>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
        break;

        case 0x31:
        {
            WORD w;

            if(!HIDTxHandleBusy(USBInHandle))
            {
                w = mTouchReadButton(1);

                ToSendDataBuffer[0] = 0x31;
                ToSendDataBuffer[1] = (BYTE)w;
                ToSendDataBuffer[2] = (BYTE)(w>>8);

                USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);
            }
        }
Exemplo n.º 7
0
void DemoIntroduction(void)
{
	unsigned char i ;
	unsigned int w1, w2;
	unsigned char touchedNow;
	SCROLL_WHEEL_DIRECTION scrollDir;
	
    switch(DemoIntroState)
    {
        case 0:
            ResetDevice();  
        
            FillDisplay(0x00);
            oledPutROMString((ROM_STRING)" Labyrinth Demo v1.0 ",0,0);
            oledPutROMString((ROM_STRING)"   by Daniel Szot    ",1,0);
			oledPutROMString((ROM_STRING)"                     ",2,0);
			oledPutROMString((ROM_STRING)"  MB Turnkey Design  ",3,0);
			oledPutROMString((ROM_STRING)" mbturnkeydesign.com ",4,0);
            oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0);

            DemoIntroState = 1;
            break;

        case 1:
            if(CheckButtonPressed() == TRUE)
            {
                DemoIntroState=4;
            }
            break;

        case 4:
            oledPutROMString((ROM_STRING)" 1. Use scroll to    ",0,0);
            oledPutROMString((ROM_STRING)" select menu items.  ",1,0);
            oledPutROMString((ROM_STRING)" 2. Tilt the board   ",2,0);
            oledPutROMString((ROM_STRING)" to move the ball.   ",3,0);
            oledPutROMString((ROM_STRING)" 3. Have a good time.",4,0);
            oledPutROMString((ROM_STRING)"                     ",5,0);
            oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0);
            DemoIntroState = 5;
            break;

        case 5:
            if(CheckButtonPressed() == TRUE)
            {
                DemoIntroState++;
            }
            break;

        case 6:
			scrollDir = GetScrollDirection();

			if (scrollDir == SCROLL_UP)
			{
				if (g_menuSelected > 0)
					g_menuSelected --;
			}
			else if (scrollDir == SCROLL_DOWN)
			{
				if (g_menuSelected < 3)
					g_menuSelected ++;
			}		

            oledPutROMString((ROM_STRING)"   LABIRYNTH  MENU   ",0,0);
            oledPutROMString(empty_line,1,0);

			if (g_menuSelected == 0)
				oledPutROMNegString((ROM_STRING)"      NEW  GAME      ",2,0);	
			else
            	oledPutROMString((ROM_STRING)"      NEW  GAME      ",2,0);

            if (g_menuSelected == 1)
				oledPutROMNegString((ROM_STRING)"     SELECT LEVEL    ",3,0);
			else
				oledPutROMString((ROM_STRING)"     SELECT LEVEL    ",3,0);
		    
			if (g_menuSelected == 2)
            	oledPutROMNegString((ROM_STRING)"      CALIBRATE      ",4,0);
			else
				oledPutROMString((ROM_STRING)"      CALIBRATE      ",4,0);
			
			if (g_menuSelected == 3)
            	oledPutROMNegString((ROM_STRING)"      QUIT GAME      ",5,0);
			else
				oledPutROMString((ROM_STRING)"      QUIT GAME      ",5,0);

            oledPutROMString(empty_line,6,0);

			w1 = mTouchReadButton(0);
			if (w1 < 600)
			{
				switch(g_menuSelected)
				{
					case 0: DemoIntroState = 0xFF; g_level=0; loadLevel(g_level); break;
					case 1: DemoIntroState = 9; DelayMs(100); FillDisplay(0x00); g_menuSelected = 0; firstLevel = 0; break;
					case 2: DemoIntroState = 7; DelayMs(100); FillDisplay(0x00);  break;
					case 3: 
						_asm
						RESET
						_endasm
						 break;
				}
			}
            break;

        case 7:
			CalibrateAcc();
            break;

		case 8:
			FillDisplay(0xFF);
			oledPutROMNegString((ROM_STRING)"  CORNGRATULATIONS!  ",0,0);
			oledPutROMNegString((ROM_STRING)"   You won nothing   ",2,0);
			oledPutROMNegString((ROM_STRING)" You just waste your ",3,0);
			oledPutROMNegString((ROM_STRING)"   PRECIOUS time :)  ",4,0);
			DelayMs(2000);
			DemoIntroState = 6;
			FillDisplay(0x00);
			g_level = 0;
			g_ballGtt = 0;
			break;

		case 9:
			SelectLevel();
			break;

        default:
            break;
    }
}