void KeypadController::start()
{
    enum KeypadButton pincode[4] = { KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE };

    int lastCol = -1;
    bool pressed = false;
    enum segChar writeChar;

    if (setup() != 0)
    {
        emit keypadFinished();
        return;
    }

    // flash 7 segs a few times to show its ready
    selectCol(0xF);
    for (int i=0; i < 3; i++)
    {
        write7seg(SEG_EIGHT);
        usleep(500000);
        write7seg(SEG_BLANK);
        usleep(200000);
    }

    // main loop
    for (col = 0; col < 4; col++, col %= 4)
    {
        QCoreApplication::processEvents();

        write7seg(SEG_BLANK);
        selectCol(col);

        enum KeypadButton button = buttonPressed(col);

        if (button == KEY_NONE)
        {
            if (lastCol == col)
            {
                pressed = false;
            }

            // qDebug() << "nothing";
        }
        else
        {
            if (pressed)
            {
                // ignore button held down
                // qDebug() << "held\n";
            }
            else if (buttonIsNumeric(button))
            {
                // a new button was pressed
                if (needPincode)
                {
                    // add it to pincode
                    pincode[count] = button;
                    count++;
                    qDebug() << "Button is" << getRealNumber(button) << "count is " << count;
                }
                else
                {
                    // forward to main thread
                    qDebug() << "Button is" << getRealNumber(button);
                    emit forwardButton(button);
                }
                pressed = true;
                lastCol = col;
            }
        }

        if (count == 4)
        {
            QString pin = QString("%1%2%3%4").arg(getRealNumber(pincode[0]))
                                  .arg(getRealNumber(pincode[1]))
                                  .arg(getRealNumber(pincode[2]))
                                  .arg(getRealNumber(pincode[3]));
            if (needPincode)
            {
                emit forwardPincode(pin);
            }
            needPincode = false;
        }

        writeChar = getHexRepresentation(pincode[col]);
        write7seg(writeChar);

        usleep(1000);
    }

}
Exemplo n.º 2
0
	int distinctCol(const char *choose)
	{
	  dau.srm.hint="DISTINCT";
	  return selectCol(choose);
	}