Exemplo n.º 1
0
wxIAReturnCode wxIASaneProvider::SelectSource(const wxString &name,
    wxIAUIMode uiMode, wxWindow *parent)
{
    wxCHECK_MSG(Ok(), wxIA_RC_NOTINITIALIZED, _T("wxIASane not valid!"));

    wxString selName = name;
    m_selDevice = -1;

    if (!m_deviceList)
        GetSourceCount();

    if (m_numDevices <= 0) {
        wxMessageBox(_("No devices available"), wxTheApp->GetAppName(),
            wxOK | wxICON_EXCLAMATION | wxCENTRE);
            return wxIA_RC_NOSOURCE;
    }

    wxArrayString sources;
    sources.Alloc(m_numDevices);

    unsigned int sel = 0;
    for (unsigned int i = 0; i < m_numDevices; i++)
    {
        sources.Add(wxString::Format("%s %s", m_deviceList[i]->vendor, m_deviceList[i]->model));
        if (name == wxString(m_deviceList[i]->name).Strip())
            sel = i;
    }

    if (uiMode == wxIA_UIMODE_NORMAL)
    {
        wxSingleChoiceDialog d(parent, _("Available Devices:"),
            _("Select Source"), sources);
        d.SetSelection(sel);

        if(d.ShowModal() != wxID_OK)
            return wxIA_RC_CANCELLED;
        sel = d.GetSelection();
        selName = wxString(m_deviceList[sel]->name).Strip();
   }
    else if(!(sel <= m_numDevices))
        return wxIA_RC_NOSOURCE;

    SANE_Status rc = m_sane->SaneOpen(selName);

    if(rc == SANE_STATUS_GOOD)
        m_selDevice = sel;

    return MapStatus(rc);
}
Exemplo n.º 2
0
/**
 * Function:  alarmHandle()
 *
 * Description: This function is called at a periodic rate to perform all
 * required API operations.  It implements the functional requirements of the
 * application mentioned in the header.
 */
void alarmHandle(int val)
{
    VpStatusType status;
    VpEventType event;
    static bool deviceInitialized = FALSE;
    static uint8 cmpCounter = 0;

    /*
     * This loop will query the FXS device for events, and when an event is
     * found, it will parse the event and perform further operations.
     */

    while(VpGetEvent(&devCtx, &event)) {
        /* Print the incoming event */
        UtilPrintEvent(&event); /* See "../common/utils.c" */

        /*
         * A channel under test should process all line events without
         * passing the events over to the main event handling loop
         */
        if ((plineCtxUnderTest != NULL) && (plineCtxUnderTest == event.pLineCtx)) {
            ProcessLineTestEvent(&event);
            continue;
        }

        /* Parse the RESPONSE category */
        if (event.eventCategory == VP_EVCAT_RESPONSE) {
            if(event.eventId == VP_DEV_EVID_DEV_INIT_CMP) {
                uint8 lineNum = 0;
                InitSetMasks();
                QS_DEBUG("Device Initialization completed\n");

                for (; lineNum < NB_LINE; lineNum++) {
                    status = VpSetLineState(&lineCtx[lineNum], VP_LINE_STANDBY);
                    if (status != VP_STATUS_SUCCESS) {
                                QS_DEBUG("Error setting lineNum %i to VP_LINE_STANDBY: %s\n", lineNum, MapStatus(status));
                        exit(-1);
                    }
                    status = VpCalLine(&lineCtx[lineNum]);
                    QS_DEBUG("Starting Calibration on lineNum %i\n", lineNum);
                    if (status != VP_STATUS_SUCCESS) {
                        QS_DEBUG("Error calling VpCalLine on lineNum %i:: %s\n", lineNum, MapStatus(status));
                        exit(-1);
                    }
                }

            } else if (event.eventId == VP_EVID_CAL_CMP) {
                if (++cmpCounter == NB_LINE) {
                    deviceInitialized = TRUE;
                    QS_DEBUG("Calibration completed on both lines ... starting Line Test\n\n");
                    StartLineTest(0, LT_TID_LINE_V);
                }
            }
        }

    } /* end while(VpGetEvent(&devCtx, &event)) */

    return;
}
Exemplo n.º 3
0
/**
 * Function:  main()
 *
 * Description: This function initializes the API and Devices/Lines.
 * It also starts the "alarmHandle" function to be called at a periodic rate.
 */
int main(void)
{
    VpStatusType status;
    struct itimerval timeStruct, timeOldVal;
    uint8 lineNum = 0;

    /* ZTAP board initialization (platform specific) */
    BoardInit(); /* See "../common/board.c" */
    VpSysInit();

    /*
     * The following structure is specific to Linux.  It sets up a timed call
     * to a user specified function.  For the purpose of this demo, the timing
     * is 20mS and the function that will be called is "alarmHandle".  The timer
     * and function call does not start until "setitimer()" and "signal()" are
     * called (below).
     */
    timeStruct.it_interval.tv_sec = 0L;
    timeStruct.it_interval.tv_usec = 19990L;
    timeStruct.it_value.tv_sec = 0L;
    timeStruct.it_value.tv_usec = 19990L;

    timeOldVal.it_interval.tv_sec = 0L;
    timeOldVal.it_interval.tv_usec = 0L;
    timeOldVal.it_value.tv_sec = 0L;
    timeOldVal.it_value.tv_usec = 0L;

    /* Make the objects (1 device, 2 lines) */
#if (SUPPLY_CONFIGURATION == ABS_SUPPLY)
    status = VpMakeDeviceObject(VP_DEV_886_SERIES, deviceId, &devCtx, &devObj);
#else
    status = VpMakeDeviceObject(VP_DEV_887_SERIES, deviceId, &devCtx, &devObj);
#endif
    if (status != VP_STATUS_SUCCESS) {
        QS_DEBUG("Error making the device object: %s\n", MapStatus(status));
        exit(-1);
    }

    for (; lineNum < NB_LINE; lineNum++) {
        status = VpMakeLineObject(VP_TERM_FXS_LOW_PWR, lineNum, &lineCtx[lineNum], &lineObj[lineNum], &devCtx);
        if (status != VP_STATUS_SUCCESS) {
            QS_DEBUG("Error calling VpMakeLineObject on lineNum %i: %s\n", lineNum, MapStatus(status));
            exit(-1);
        }
        QS_DEBUG("--- Created lineNum %i---\n", lineNum);
    }

    /* Start VpInitDevice and wait for the event VP_DEV_EVID_DEV_INIT_CMP */
#if (SUPPLY_CONFIGURATION == FLY_BACK_SUPPLY)
    status = VpInitDevice(&devCtx, FB_DEV_PROFILE, FB_AC_600_FXS, FB_DC_25MA_CC, FB_RING_25HZ_SINE, VP_PTABLE_NULL, VP_PTABLE_NULL);
#elif (SUPPLY_CONFIGURATION == INVERTING_BOOST_SUPPLY)
    status = VpInitDevice(&devCtx, IB_DEV_PROFILE, IB_AC_600_FXS, IB_DC_25MA_CC, IB_RING_25HZ_SINE, VP_PTABLE_NULL, VP_PTABLE_NULL);
#elif (SUPPLY_CONFIGURATION == ABS_SUPPLY)
    status = VpInitDevice(&devCtx, ABS_DEV_PROFILE, ABS_AC_600_FXS, ABS_DC_23MA_CC, ABS_RING_25HZ_SINE, VP_PTABLE_NULL, VP_PTABLE_NULL);
#else
    #error "SUPPLY_CONFIGURATION is incorrectly set"
#endif

    if (status != VP_STATUS_SUCCESS) {
        QS_DEBUG("Device not properly initialized: %s\n", MapStatus(status));
        exit(-1);
    } else {
        QS_DEBUG("\nDevice Initialization started\n");
    }

    /*
     * The following two function calls were described above as Linux specific.
     * They are used to call a user defined function at set increments.  The
     * user may have several other methods to perform the same.
     */
    signal(SIGVTALRM, alarmHandle);
    setitimer(ITIMER_VIRTUAL, &timeStruct, &timeOldVal);

    /*
     * Once the "tick" is setup, the main program can enter a "while(1)" loop
     * and the user specified function will take over the application (with the
     * help of the Linux OS)
     */


    while(1);

    return 0;
}