Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*
 * Routine:  Serial_GenericHalfDuplex_Write
 *---------------------------------------------------------------------------*
 * Description:
 *      Write data out the serial port or timeout trying.  If a timeout,
 *      the number of bytes written is reported.
 * Inputs:
 *      void *aWorkspace          -- This serial GenericHalfDuplex workspace
 *      TUInt8 *aData             -- Data to send
 *      TUInt32 aNumBytes         -- Number of bytes to read.
 *      TUInt32 *aNumBytesWritten -- Number of bytes actually written.  If
 *                                   timeout occurs, this value is less than
 *                                   aNumBytes.
 * Outputs:
 *      T_uezError                 -- Error code.  UEZ_ERROR_TIMEOUT is returned
 *                                   if timeout occurs trying to write
 *                                   the full amount and not enough room was
 *                                   available.  UEZ_ERROR_NONE is reported if
 *                                   all data is written.
 *---------------------------------------------------------------------------*/
T_uezError Serial_GenericHalfDuplex_Write(
            void *aWorkspace, 
            TUInt8 *aData, 
            TUInt32 aNumBytes, 
            TUInt32 *aNumBytesWritten,
            TUInt32 aTimeout)
{
    // Decrement use count.  Are we done?
    T_Serial_GenericHalfDuplex_Workspace *p = (T_Serial_GenericHalfDuplex_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
    TUInt32 i;

    for (i=0; i<aNumBytes; i++)  {
        // Send bytes one at a time
        UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

        // Don't let interrupts occur while we do this one
        (*p->iSerial)->Deactivate((T_halWorkspace *)p->iSerial);

        // Are we currently busy sending data?
        if (p->iTxBusy) {
            // Yes, busy, stuff another byte into the end of the queue
            error = UEZQueueSend(p->iQueueSend, aData, aTimeout);
        } else {
            // Transmit is not busy yet.  But we're about to be

            // Start driving again
            if (p->iDriveEnablePort) {
                if (p->iDriveEnablePolarity) {
                    (*p->iDriveEnablePort)->Set(p->iDriveEnablePort, p->iDriveEnablePin);
                } else {
                    (*p->iDriveEnablePort)->Clear(p->iDriveEnablePort, p->iDriveEnablePin);
                }
            }

            // Declare transmit busy
            p->iTxBusy = ETrue;
            UEZSemaphoreGrab(p->iSemEmpty, 0);
            p->iDidOutput = ETrue;
            error = (*p->iSerial)->OutputByte((T_halWorkspace *)p->iSerial, *aData);
        }
        (*p->iSerial)->Activate((T_halWorkspace *)p->iSerial);

        UEZSemaphoreRelease(p->iSem);

        // Report any errors up to this point
        if (error)
            break;

        // Next byte
        aData++;
    }

    // Report how many bytes we did get
    if (aNumBytesWritten)
        *aNumBytesWritten = i;
    
    // Report final error
    return error;
}
Ejemplo n.º 2
0
 /*---------------------------------------------------------------------------*/
static TBool IHandleForward(WM_MESSAGE * pMsg, int aNCode, int aID)
{
    T_ImageMessage message;
    TUInt32 *tempPointer;

    if (aNCode == WM_NOTIFICATION_RELEASED) {
        UEZSemaphoreGrab(G_LoadingSemaphore, UEZ_TIMEOUT_INFINITE);
        tempPointer = G_PreviousImage;
        G_PreviousImage = G_CurrentImage;
        G_CurrentImage = G_NextImage;
        G_NextImage = tempPointer;
        if (G_CurrentImage_Number < G_NumImagesOnCard){
            G_CurrentImage_Number++;
        } else {
            G_CurrentImage_Number = 1;
        }
        UEZSemaphoreRelease(G_LoadingSemaphore);

        message = IMAGE_ADVANCED;
        UEZQueueSend(G_ImageLoadQueue,
                (void*)&message,
                50);
        WM_InvalidateWindow(pMsg->hWin);
        IHideButtonsAndText(pMsg);
    }
    return EFalse;
}
Ejemplo n.º 3
0
/*-------------------------------------------------------------------------*
 * Function:  GenericBulkBulkOut
 *-------------------------------------------------------------------------*
 * Description:
 *      Bulk virtual comm data has come out of the PC.  This data
 *      is put into the fifo.
 * Inputs:
 *      TUInt8 aEndpoint         -- Endpoint with interrupt
 *      T_USBEndpointStatus aStatus -- Current status of this endpoint
 *-------------------------------------------------------------------------*/
void GenericBulkBulkOut(
        void *aWorkspace,
        TUInt8 aEndpoint,
        T_USBEndpointStatus aStatus)
{
    TInt16 i, length;
    PARAM_NOT_USED(aWorkspace);
    PARAM_NOT_USED(aStatus);

    // Read data from endpoint
    length = (*G_ghDevice)->Read(
                G_ghDevice,
                aEndpoint,
                G_GenBulkBuffer,
                sizeof(G_GenBulkBuffer));

    if (length) {
        // Store all data until we are full.
        // TBD:  If the PC keeps sending us data and our
        //          buffer is full, we currently have no handshaking
        //          to handle overflow.
        for (i=1; i<=G_GenBulkBuffer[0]; i++)  {
            // Put in the queue one character at time quickly, until full.
            if (UEZQueueSend(G_GenBulkFifoIn, &G_GenBulkBuffer[i], 0) != UEZ_ERROR_NONE)
                break;
        }
    }

    // Setup a response
    GenericBulkBulkIn(aWorkspace, USB_ENDPOINT_ADDRESS(1, USB_ENDPOINT_ADDRESS_DIR_IN), aStatus);
}
Ejemplo n.º 4
0
/*-------------------------------------------------------------------------*
 * Function:  GenericBulkPut
 *-------------------------------------------------------------------------*
 * Description:
 *      Send a character out the virtual comm driver.
 *      If no room is available in buffer, returns EFalse.  Otherwise, it
 *      returns ETrue
 * Inputs:
 *      TUInt8 c                 -- Character sent
 *      TUInt32 aTimeout         -- Time to wait for character to go out
 * Outputs:
 *      TBool                    -- ETrue if sent, else EFalse
 *-------------------------------------------------------------------------*/
TBool GenericBulkPut(TUInt8 c, TUInt32 aTimeout)
{
    // Try to stuff in the data, but don't block
    T_uezError error = UEZQueueSend(G_GenBulkFifoOut, &c, aTimeout);

    if (error == UEZ_ERROR_NONE) {
        return ETrue;
    }

    return EFalse;
}
Ejemplo n.º 5
0
TBool TestModeSendCmd(TUInt32 aCmd)
{
    // Go into test mode (if not already running)
    G_mmTestMode = ETrue;
    while (!G_mmTestModeRunning) {
        UEZTaskDelay(10);
    }

    // Check if we are running and send command
    if (G_mmTestModeRunning) {
        if (UEZQueueSend(G_mmTestModeQueue, &aCmd, UEZ_TIMEOUT_INFINITE) != UEZ_ERROR_NONE)
            return EFalse;
        return ETrue;
    }
    return EFalse;
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void IUEZTSMonitorTouchscreensTask(T_uezTask aMyTask, void *aParams)
{
    T_tsDevice *p;
    T_tsQueue *pq;
    T_uezTSReading reading;
    T_uezInputEvent inputEvent;

    for (;;) {
        IUEZTSGrab();
        p = G_tsDevices;
        while (p) {
            if (UEZTSGetReading(p->iDevice, &reading) == UEZ_ERROR_NONE)  {
            
                if(reading.iFlags & TSFLAG_PEN_DOWN) {
                    UEZLCDScreensaverWake();
                    
                    if(UEZLCDScreensaverIsActive())
                        G_WaitForRelease = ETrue;
                }
                
                if(G_WaitForRelease) {
                    if(!(reading.iFlags & TSFLAG_PEN_DOWN)) {
                        // if the pen is released, stop waiting
                        G_WaitForRelease = EFalse;
                    }
                } else {
                    // Apply the reading to all the queues (as last reported)
                    for (pq = p->iQueueList; pq; pq=pq->iNext) {
                        // Send it on the queue.
                        inputEvent = IConvertTSReadingToInputEvent(&reading);
                        UEZQueueSend(pq->iQueue, &inputEvent, 0);
                    }
                }
            }
            p = p->iNext;
        }
        IUEZTSRelease();
        UEZTaskDelay(10);
    }
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*
 * Routine: _PFMainDialog
 *---------------------------------------------------------------------------*
 * Description:
 *      Callback function used by emWin to process events.
 * Inputs:
 *      WM_MESSAGE *pMsg -- message structure for current dialog.
 *---------------------------------------------------------------------------*/
static void _PFMainDialog(WM_MESSAGE *pMsg)
{
    int Id, NCode;
    WM_HWIN hItem;
    GUI_PID_STATE *p_touchState;
    T_ImageMessage message;

    switch (pMsg->MsgId){
    case WM_INIT_DIALOG:
        Id    = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        LAFSetup(pMsg->hWin, ID_WINDOW, PFMainLayout);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_REVERSE_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_UNPRESSED, &REVERSE_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_PRESSED, &REVERSE_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_DISABLED, &REVERSE_BUTTON);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_PLAY_PAUSE_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_UNPRESSED, &PLAY_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_PRESSED, &PLAY_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_DISABLED, &PLAY_BUTTON);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_FORWARD_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_UNPRESSED, &FORWARD_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_PRESSED, &FORWARD_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_DISABLED, &FORWARD_BUTTON);

        hItem = WM_GetDialogItem(pMsg->hWin, ID_SETTINGS_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_UNPRESSED, &SETTINGS_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_PRESSED, &SETTINGS_BUTTON);
        BUTTON_SetBitmap(hItem, BUTTON_BI_DISABLED, &SETTINGS_BUTTON);

        G_OverlayTimer = WM_CreateTimer(pMsg->hWin, ID_OVERLAY_TIMER, OVERLAY_TIMEOUT_MS, 0);
        G_UpdateTimer = WM_CreateTimer(pMsg->hWin, ID_UPDATE_TIMER, UPDATE_TIME_MS, 0);
        G_PictureChangeTimer = WM_CreateTimer(pMsg->hWin, ID_PICTURECHANGE_TIMER, 0, 0);

        if (!G_Current) {
            G_Current = GUI_MEMDEV_Create(0, 0,
                    UEZ_LCD_DISPLAY_WIDTH, UEZ_LCD_DISPLAY_HEIGHT);
            GUI_MEMDEV_Select(G_Current);
            GUI_BMP_Draw(G_CurrentImage, 0, 0);
            GUI_MEMDEV_Select(0);
        }

        WM_SetHasTrans(pMsg->hWin);

        message = IMAGE_INITILIZE;
        UEZQueueSend(G_ImageLoadQueue,
                (void*)&message,
                50);
        break;
    case WM_NOTIFY_PARENT:
        Id = WM_GetId(pMsg->hWinSrc);
        NCode = pMsg->Data.v;
        if( !LAFHandleEvent(PFMainLayout, pMsg, NCode, Id)){
            //Handle special cases here
        }
        break;
    case WM_TIMER:
        NCode = pMsg->Data.v;
        if (G_Active) {
            if (NCode == G_OverlayTimer) {
                IHideButtonsAndText(pMsg);
                //Grab all the touches
                WM_SetCapture(pMsg->hWin, 0);
            } else if (NCode == G_PictureChangeTimer) {
                //put up new picture
                if(G_AutoPlayOn) {
                    IHandleForward(pMsg, WM_NOTIFICATION_RELEASED, ID_FORWARD_BUTTON);
                    WM_RestartTimer(G_PictureChangeTimer, 5000);
                }
            } else if (NCode == G_UpdateTimer) {
                IUpdateFields(pMsg);
                WM_RestartTimer(G_UpdateTimer, UPDATE_TIME_MS);
            }
        }
        break;
    case WM_TOUCH:
        p_touchState = (GUI_PID_STATE *)(pMsg->Data.p);
        if (!p_touchState->Pressed) {
            WM_RestartTimer(G_OverlayTimer, OVERLAY_TIMEOUT_MS);
            //Show all the hidden text on buttons
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TITLE_TEXT);
            WM_ShowWindow(hItem);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_SETTINGS_BUTTON);
            WM_ShowWindow(hItem);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_REVERSE_BUTTON);
            WM_ShowWindow(hItem);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_PLAY_PAUSE_BUTTON);
            WM_ShowWindow(hItem);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_FORWARD_BUTTON);
            WM_ShowWindow(hItem);
            hItem = WM_GetDialogItem(pMsg->hWin, ID_TIMEDATE_TEXT);
            WM_ShowWindow(hItem);
            WM_ReleaseCapture();
            IUpdateFields(pMsg);
        }
        break;
    case WM_POST_PAINT:
        GUI_BMP_Draw(G_CurrentImage, 0, 0);
        break;
    case WM_APP_GAINED_FOCUS:
        G_Active = ETrue;
        WM_SetCapture(pMsg->hWin, 0);
        IHideButtonsAndText(pMsg);
        IUpdateFields(pMsg);
        break;
    case WM_APP_LOST_FOCUS:
        G_Active = EFalse;
        IHideButtonsAndText(pMsg);
        WM_ReleaseCapture();
        G_AutoPlayOn = EFalse;
        break;
    default:
      WM_DefaultProc(pMsg);
    break;
  }
}
/*---------------------------------------------------------------------------*
 * Routine:  Keypad_NXP_I2C_PCA9555_Monitor
 *---------------------------------------------------------------------------*
 * Description:
 *      Setup a task to run and monitor the keypad for presses.
 * Inputs:
 *      T_uezTask aMyTask           -- This task
 *      void *aParameters           -- Passed in workspace
 *---------------------------------------------------------------------------*/
static void Keypad_NXP_I2C_PCA9555_Monitor(
        T_uezTask aMyTask, 
        void *aParameters)
{
    T_Keypad_NXP_I2C_PCA9555_Workspace *p = 
        (T_Keypad_NXP_I2C_PCA9555_Workspace *)aParameters;
    TUInt32 key;
    TUInt32 key2;
    T_uezInputEvent event;
    T_keypadRegistered *p_reg;

    PARAM_NOT_USED(aMyTask);

    // Sit here and wait for an event
    while (1) {
        // At this point, the keypad is fully grabbed, so we'll
        // wait for a release to occur.
#if KEYPAD_USES_EXTERNAL_IRQ
        UEZSemaphoreGrab(p->iReady, UEZ_TIMEOUT_INFINITE);
#else
        UEZTaskDelay(50);
#endif
        // Process the keypad interrupt
        IKeypad_PCA9555_Scan(p, &key);
        if (key != KEY_NONE) {
            // Don't let others access the keypad while we process
            IGrab(p);

            // Send it out a press event to everyone
            event.iType = INPUT_EVENT_TYPE_BUTTON;
            event.iEvent.iButton.iKey = key;
            event.iEvent.iButton.iAction = BUTTON_ACTION_PRESS;
            for (p_reg = p->iRegisteredQueues; p_reg; p_reg = p_reg->iNext) {
                // Send the event, but don't block.
                UEZQueueSend(p_reg->iQueue, (void *)&event, 0);
            }

            // Done, return to our control
            IRelease(p);

            // Watch the scan waiting for no press every at 10 ms intervals
            while (1) {
                if (IKeypad_PCA9555_Scan(p, &key2) != UEZ_ERROR_NONE)
                    break;
                if (key2 == KEY_NONE)
                    break;
                UEZTaskDelay(10);
            }

            // Don't let others access the keypad while we process
            IGrab(p);

            // Finally, no button is pressed
            // Send out a press release to everyone
            event.iType = INPUT_EVENT_TYPE_BUTTON;
            event.iEvent.iButton.iKey = key;
            event.iEvent.iButton.iAction = BUTTON_ACTION_RELEASE;
            for (p_reg = p->iRegisteredQueues; p_reg; p_reg = p_reg->iNext) {
                // Send the event, but don't block.
                UEZQueueSend(p_reg->iQueue, (void *)&event, 0);
            }

#if KEYPAD_USES_EXTERNAL_IRQ
            // Turn back on the external interrupts
            (*p->iEINT)->Clear(p->iEINT, KEYPAD_EINT2_CHANNEL);
#endif

            // Done, return to our control
            IRelease(p);
        }
    }
}