Пример #1
0
static void UpdateInput(void) {
	int pad;
	if (!g.cfg.Threaded) CheckJoy();
	for(pad = 0; pad < 2; pad++) {
		if(g.PadState[pad].PadModeSwitch) {
			g.PadState[pad].PadModeSwitch = 0;
			PADsetMode(pad, 1 - g.PadState[pad].PadMode);
		}
	}
	CheckKeyboard();
}
Пример #2
0
int findUSBkeyboard()
	{
	int found=0;
	DIR * dir_;
	dir_ = opendir("/dev/input");
	int i;
	for (i=0;i<128;i++)
		{
		keyboardmap[i]=0;
		}
	if(dir_==NULL)
		{
		return (-1);	// Error can't open /dev/input directory to find devices
		}
	rewinddir(dir_);
	struct dirent * entry = readdir(dir_);
	for (;entry!=0; entry=readdir(dir_))
		{
		if (strncmp(entry->d_name,"event",5)==0)	// Find all /dev/input/event* devices
			{
			char devstr[25];			// Should be enough
			sprintf(devstr,"/dev/input/%s",entry->d_name);
			int fd = open(devstr, O_RDONLY);
			if (fd !=-1)
				{
				struct input_id device_info;
				memset(&device_info, 0, sizeof(struct input_id));
				if(!ioctl(fd,EVIOCGID, &device_info))
					{
					int value;
					int ioctloutput;
					value=CheckKeyboard(devstr);	// Check if device is a keyboard
					if(value==0)
						{
						found=1;
						keyboard_fd=fd;		// Keyboard detected and open, keep file descriptor
						}
					}
				if(keyboard_fd!=fd)
					close(fd);	// Close anything that's not a keyboard
				}
			}
		}
	closedir(dir_);
	return found;
	}
void main(void)
{

    IFR = 0x0000;
    IER = 0x0000;

    DisableWatchdog();
    InitSysParameters();                        // Initialization of system parameters
    InitSysTimer();                             // Initialization of system timer

#if (USE_TEST1_PIN)
    TEST_1_INI();
    TEST_1_OFF();
#endif
#if (USE_TEST2_PIN)
    TEST_2_INI();
    TEST_2_OFF();
#endif

    InitWatchdog();                             // Initialization of watchdog
    InitXWatchdog();                            // Initialization of extern watchdog

    InitIndicators();
//    InitSwitches();
    InitKeyboard();

    SetTimer(T_LED, T_LED_D);                   // Set Timers
    SetTimer(T_SEC, T_SEC_D);
    SetTimer(T_SWT, T_SWT_D);

    PieCtrlRegs.PIEACK.all = 0xFFFF;            // Enables PIE to drive a pulse into the CPU
    EINT;                                       // Enable Interrupts at the CPU level

    //--- Enable interrupts
    //SetDBGIER(IER);                             // Configure the DBGIER for realtime debug
    //asm(" CLRC INTM, DBGM");                    // Enable global interrupts and realtime debug

    TimeDev.second = 0;
    TimeDev.minute = 0;
    TimeDev.hour = 0;
    TimeDev.date = 0;

    EnableWatchdog();
//--------------------------------------------------------------------------------------------------
    for(;;)                                     // Main loop
    {
        ServiceWatchdog();                     // Reset Watchdog
//--------------------------------------------------------------------------------------------------
//----------------------------------------------// Time intervals
        if(CheckTimer(T_SEC))
        {
            SetTimer(T_SEC, T_SEC_D);
            if (++TimeDev.second > 59)
            {
                TimeDev.second = 0;
                if (++TimeDev.minute > 59)
                {
                    TimeDev.minute = 0;
                    if (++TimeDev.hour > 23)
                    {
                        TimeDev.hour = 0;
                        TimeDev.date++;
                    }
                }
            }
        }
//--------------------------------------------------------------------------------------------------
//----------------------------------------------// Indication
        if(CheckTimer(T_LED))
        {
            Debug[0]++;
            SetTimer(T_LED, T_LED_D);
//----------------------------------------------// Signaling the state of the system

//            ControlLedWork(TOGGLE);            // LED indicates normal work of the system
            //ControlIndicatorPower(TOGGLE);     // Indication of connection to the power line
//----------------------------------------------// Signaling presence of errors
            /*if (FlagDev.bit.ERR)
            {
                ControlLedError(TOGGLE);
                //ControlIndicatorError(TOGGLE);
            }
            else
            {
                ControlLedError(OFF);
                //ControlIndicatorError(OFF);
            }*/

#if (USE_INDICATOR1)
//----------------------------------------------// Indication of the device working
                                                // in the converter mode
            /*if (FlagDev.bit.WORK)
            {
                ControlIndicatorWork(ON);
            }
            else
            {
                ControlIndicatorWork(OFF);
            }*/
#endif

#if (USE_INDICATOR2)
//----------------------------------------------// Indication of the presence of communication
                                                // with the control device
            /*if (!ErrorDev.bit.CTR)
            {
                ControlIndicatorLink(ON);
            }
            else
            {
                ControlIndicatorLink(OFF);
            }*/
#endif
        }

        if(CheckTimer(T_SWT))
        {

#if (USE_SWT1)
            if (CheckButtonStop() && !CheckButtonStart())
            {
                FlagDev.bit.STOP = 1;
            }
#endif

#if (USE_SWT2)
            if (CheckButtonStart() && !CheckButtonStop())
            {
                FlagDev.bit.PUSK = 1;
            }
#endif

#if (USE_SWT3)
            if (CheckButtonReset())
            {
                FlagDev.bit.RESET = 1;
            }
#endif

#if (USE_ONB_BUT1)
            if (CheckButtonOnboard1())
            {
                ControlLedOnboard3(ON);
            }
            else
            {
                ControlLedOnboard3(OFF);
            }
#endif

#if (USE_KBRD)
            CheckKeyboard();
            if(KeyboardStat.bit.BUT1)
            {
                ControlLedWork(ON);
                Debug[1] = 1;
            }
            else
            {
                ControlLedWork(OFF);
                Debug[1] = 0;
            }
            if(KeyboardStat.bit.BUT2)
            {
                ControlLedError(ON);
                Debug[2] = 1;
            }
            else
            {
                ControlLedError(OFF);
                Debug[2] = 0;
            }
            if(KeyboardStat.bit.BUT4)
            {
                ControlLedOnboard3(ON);
                Debug[3] = 1;
            }
            else
            {
                ControlLedOnboard3(OFF);
                Debug[3] = 0;
            }
            if(KeyboardStat.bit.BUT5)
            {
                ControlLedOnboard4(ON);
                Debug[4] = 1;
            }
            else
            {
                ControlLedOnboard4(OFF);
                Debug[4] = 0;
            }
#endif
        }
//--------------------------------------------------------------------------------------------------
    }
}