コード例 #1
0
ファイル: pmod_enc.c プロジェクト: mihnagy/zybo-radio
/******************************************************************************
 * This function simulatenously reads ROT-A and ROT-B contacts of the rotary
 * encoder and returns the relationship between their phase.
 *
 * @param   psDev is a pointer to the PmodEnc structure.
 *
 * @return  Phase value.
 *****************************************************************************/
unsigned char encPhase(const PmodEnc_t* psDev)
{
    unsigned char a = readGpio(psDev->RotA);
    unsigned char b = readGpio(psDev->RotB);

    a = (a == 0) ? 1 : 0;
    b = (b == 0) ? 1 : 0;

    return (b << 1) | a;
}
コード例 #2
0
ファイル: main.c プロジェクト: anonspacecowboy/DummyRep
/*
 * Read GPIO serial value
 */
float getSerialData(int num_registers, char* result_string, float rule_height) {
	unsigned short int idx = 0, value_read = 0, pins_out_water = 0;
	float pins_mid_level = 0;
	clockUp();
	loadRegisters();
	//FIXME: Essa não é a forma correta de dar delay, muito ineficiente
	__delay_cycles( SLEEP_TIME);
	clockDown();
	unloadRegisters();

	for (idx = 0; idx < num_registers; idx++) {
		//FIXME: Essa não é a forma correta de dar delay, muito ineficiente
		__delay_cycles( SLEEP_TIME);
		value_read = readGpio();
		pins_out_water += value_read;

		if (value_read)
			strcat(result_string, "1");
		else
			strcat(result_string, "0");

		clockUp();
		//FIXME: Essa não é a forma correta de dar delay, muito ineficiente
		__delay_cycles( SLEEP_TIME);
		clockDown();
	}

	pins_mid_level = (MID_LEVEL / RULE_SPACE_PIN);
	rule_height = ((num_registers - pins_out_water - pins_mid_level)
			* RULE_SPACE_PIN);

	return pins_mid_level;
}
JNIEXPORT jint JNICALL asusec_DockEmbeddedController_nativeReadECWakeUp
(JNIEnv *env, jclass cls) {

    const int SIZE = 16;
    char buf[SIZE];

    int count = readGpio(ASUSEC_SYSFS_EC_WAKEUP, buf, SIZE);
    int ret = -1;
    if (count > 0) {
        ret = atoi(buf);
    }

    return (jint)ret;
}
コード例 #4
0
ファイル: pmod_enc.c プロジェクト: mihnagy/zybo-radio
/******************************************************************************
 * This function implements the state machine that reads the rotary encoder and
 * returns its value;
 *
 * @param   psDev is a pointer to the PmodEnc structure.
 * @param   psStatus is a pointer to the status structure of the encoder.
 *
 * @return  Rotary encoder direction value.
 *****************************************************************************/
void encMonitor(const PmodEnc_t* psDev, PmodEncStatus_t* psStatus)
{
    static int state = DETENT;
    static int last = -1;
    unsigned int value = encPhase(psDev);
    unsigned char centerLast = 0;
    unsigned char centerNow = readGpio(psDev->Center);

    // Detect a possible rising edge of the center button press
    if (centerNow != centerLast)
    {
        if (centerNow)
        {
            psStatus->CenterValueChanged = 1;
        }
        centerLast = centerNow;
    }

    if (value != last)
    {
        switch (state)
        {
        case DETENT:
            if(value == 2)
            {
                state = CW_1;
            }
            else if(value == 1)
            {
                state = CCW_1;
            }
            break;
        case CW_1:
            if(value == 0)
            {
                state = DETENT;
            }
            else if(value == 3)
            {
                state = CW_2;
            }
            break;
        case CW_2:
            if(value == 2)
            {
                state = CW_1;
            }
            else if(value == 1)
            {
                state = CW_3;
            }
            break;
        case CW_3:
            if(value == 1)
            {
                state = CW_2;
            }
            else if(value == 0)
            {
                state = DETENT;
                psStatus->CntValue++;
                psStatus->RotValueChanged = 1;
                //printf("+");
            }
            break;
        case CCW_1:
            if(value == 0)
            {
                state = DETENT;
            }
            else if(value == 3)
            {
                state = CCW_2;
            }
            break;
        case CCW_2:
            if(value == 1)
            {
                state = CCW_1;
            }
            else if(value == 2)
            {
                state = CCW_3;
            }
            break;
        case CCW_3:
            if(value == 3)
            {
                state = CCW_2;
            }
            else if(value == 0)
            {
                state = DETENT;
                psStatus->CntValue--;
                psStatus->RotValueChanged = 1;
                //printf("-");
            }
        }
        last = value;
    }
}