コード例 #1
0
/**
 * Allocate / get first button from the unallocated buttons
 * @retval Button pointer or message and NULL pointer if no button available
 */
TouchButton * TouchButton::allocButton(bool aOnlyAutorepeatButtons) {
    TouchButton * tButtonPointer = sListStart;
    if (!sButtonPoolIsInitialized) {
        // mark pool as free
        for (int i = 0; i < NUMBER_OF_BUTTONS_IN_POOL; ++i) {
            TouchButtonPool[i].mFlags &= ~FLAG_IS_ALLOCATED;
        }
        sButtonPoolIsInitialized = true;
    }
    // walk through list
    while (tButtonPointer != NULL
            && ((tButtonPointer->mFlags & FLAG_IS_ALLOCATED)
                    || (aOnlyAutorepeatButtons && !(tButtonPointer->mFlags & FLAG_IS_AUTOREPEAT_BUTTON))
                    || (!aOnlyAutorepeatButtons && (tButtonPointer->mFlags & FLAG_IS_AUTOREPEAT_BUTTON)))) {
        tButtonPointer = tButtonPointer->mNextObject;
    }
    if (tButtonPointer == NULL) {
        if (aOnlyAutorepeatButtons) {
            failParamMessage(sButtonCombinedPoolSize, "No autorepeat button available");
        } else {
            failParamMessage(sButtonCombinedPoolSize, "No button available");
        }
        // to avoid NULL pointer
        tButtonPointer = sListStart;
        sButtonCombinedPoolSize++;
    } else {
        tButtonPointer->mFlags |= FLAG_IS_ALLOCATED;
    }

    sButtonCombinedPoolSize--;
    if (sButtonCombinedPoolSize < sMinButtonPoolSize) {
        sMinButtonPoolSize = sButtonCombinedPoolSize;
    }
    return tButtonPointer;
}
コード例 #2
0
/**
 * Allocate / get first button from the unallocated buttons
 * @retval Button pointer or message and NULL pointer if no button available
 */
TouchButton * TouchButton::allocButton(bool aOnlyAutorepeatButtons) {
    TouchButton * tButtonPointer;
    if (!sButtonPoolIsInitialized) {
        tButtonPointer = NULL;
        // mark pool as free
        for (int i = NUMBER_OF_BUTTONS_IN_POOL - 1; i >= 0; i--) {
            TouchButtonPool[i].mFlags = 0;
            TouchButtonPool[i].mNextObject = tButtonPointer;
            tButtonPointer = &TouchButtonPool[i];
        }
        sButtonPoolIsInitialized = true;
        sButtonListStart = &TouchButtonPool[0];
    }

// walk through list
    tButtonPointer = sButtonListStart;
    while (tButtonPointer != NULL && (tButtonPointer->mFlags & FLAG_IS_ALLOCATED)) {
        tButtonPointer = tButtonPointer->mNextObject;
    }
    if (tButtonPointer == NULL) {
        failParamMessage(sButtonCombinedPoolSize, "No button available");
        // to avoid NULL pointer
        tButtonPointer = sButtonListStart;
    } else {
        tButtonPointer->mFlags |= FLAG_IS_ALLOCATED;
        sButtonCombinedPoolSize--;
    }

    if (sButtonCombinedPoolSize < sMinButtonPoolSize) {
        sMinButtonPoolSize = sButtonCombinedPoolSize;
    }
    return tButtonPointer;
}
コード例 #3
0
int8_t TouchButton::setPosition(uint16_t aPositionX, uint16_t aPositionY) {
    int8_t tRetValue = 0;
    mPositionX = aPositionX;
    mPositionY = aPositionY;

// check values
    if (aPositionX + mWidthX > LOCAL_DISPLAY_WIDTH) {
        mWidthX = LOCAL_DISPLAY_WIDTH - aPositionX;
        failParamMessage(aPositionX + mWidthX, "XRight wrong");
        tRetValue = TOUCHBUTTON_ERROR_X_RIGHT;
    }
    if (aPositionY + mHeightY > LOCAL_DISPLAY_HEIGHT) {
        mHeightY = LOCAL_DISPLAY_HEIGHT - mPositionY;
        failParamMessage(aPositionY + mHeightY, "YBottom wrong");
        tRetValue = TOUCHBUTTON_ERROR_Y_BOTTOM;
    }
    return tRetValue;
}
コード例 #4
0
int8_t TouchButton::setPosition(const uint16_t aPositionX, const uint16_t aPositionY) {
    int8_t tRetValue = 0;
    mPositionX = aPositionX;
    mPositionY = aPositionY;

    // check values
    if (aPositionX + mWidth > mDisplay->getDisplayWidth()) {
        mWidth = mDisplay->getDisplayWidth() - aPositionX;
        failParamMessage(aPositionX + mWidth, "XRight wrong");
        tRetValue = TOUCHBUTTON_ERROR_X_RIGHT;
    }
    if (aPositionY + mHeight > mDisplay->getDisplayHeight()) {
        mHeight = mDisplay->getDisplayHeight() - mPositionY;
        failParamMessage(aPositionY + mHeight, "YBottom wrong");
        tRetValue = TOUCHBUTTON_ERROR_Y_BOTTOM;
    }
    return tRetValue;
}
コード例 #5
0
/**
 * free / release one button to the unallocated buttons
 */
void TouchButton::freeButton(TouchButton * aTouchButton) {
    TouchButton * tButtonPointer = sButtonListStart;
// walk through list
    while (tButtonPointer != NULL && tButtonPointer != aTouchButton) {
        tButtonPointer = tButtonPointer->mNextObject;
    }
    if (tButtonPointer == NULL) {
        failParamMessage(aTouchButton, "Button not found in list");
    } else {
        sButtonCombinedPoolSize++;
        tButtonPointer->mFlags &= ~FLAG_IS_ALLOCATED;
        tButtonPointer->mFlags &= ~FLAG_IS_ACTIVE;
    }
}