Beispiel #1
0
 // N.B. This may need revisiting when the UI is added
 static QStringList GetDeviceList(void)
 {
     QStringList results;
     cec_device_type_list list;
     list.Clear();
     list.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
     ICECAdapter *adapter = LibCecInit("MythTV", list);
     if (!adapter)
         return results;
     cec_adapter *devices = new cec_adapter[MAX_CEC_DEVICES];
     uint8_t num_devices = adapter->FindAdapters(devices, MAX_CEC_DEVICES, NULL);
     if (num_devices < 1)
         return results;
     for (uint8_t i = 0; i < num_devices; i++)
         results << QString::fromAscii(devices[i].comm);
     UnloadLibCec(adapter);
     return results;
 }
Beispiel #2
0
Datei: main.cpp Projekt: aep/cecd
int main (int argc, char *argv[])
{
    if(argc<2){
        fprintf(stderr,"usage: echo /path/to/echo.method\n");
        exit(1);
    }
    ubus_t * service=ubus_create(argv[1]);
    if(service==0){
        perror("ubus_create");
        exit(0);
    }



    g_config.Clear();
    g_callbacks.Clear();
    snprintf(g_config.strDeviceName, 13, "XBMC");
    g_config.clientVersion       = CEC_CONFIG_VERSION;
    g_config.bActivateSource     = 0;
    //    g_callbacks.CBCecLogMessage  = &CecLogMessage;
    //    g_callbacks.CBCecKeyPress    = &CecKeyPress;
    //    g_callbacks.CBCecCommand     = &CecCommand;
    //    g_callbacks.CBCecAlert       = &CecAlert;
    //    g_config.callbacks           = &g_callbacks;


    g_config.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
    ICECAdapter *parser = LibCecInitialise(&g_config);
    if (!parser)
    {
#ifdef __WINDOWS__
        cout << "Cannot load libcec.dll" << endl;
#else
        cout << "Cannot load libcec.so" << endl;
#endif
        if (parser)
            UnloadLibCec(parser);
        return 1;
    }

    // init video on targets that need this
    parser->InitVideoStandalone();


    if (g_strPort.empty())
    {
        if (!g_bSingleCommand)
            cout << "no serial port given. trying autodetect: ";
        cec_adapter devices[10];
        uint8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL);
        if (iDevicesFound <= 0)
        {
            if (g_bSingleCommand)
                cout << "autodetect ";
            cout << "FAILED" << endl;
            UnloadLibCec(parser);
            return 1;
        }
        else
        {
            if (!g_bSingleCommand)
            {
                cout << endl << " path:     " << devices[0].path << endl <<
                    " com port: " << devices[0].comm << endl << endl;
            }
            g_strPort = devices[0].comm;
        }
    }

    fprintf(stderr,"opening a connection to the CEC adapter...");

    if (!parser->Open(g_strPort.c_str()))
    {
        fprintf(stderr,"unable to open the device on port %s", g_strPort.c_str());
        UnloadLibCec(parser);
        return 1;
    }

    if (!g_bSingleCommand)
        fprintf(stderr,"waiting for input\n");




    signal(SIGPIPE, SIG_IGN);


    fd_set rfds;
    char buff [2000];
    for(;;) {
        FD_ZERO (&rfds);
        int maxfd=ubus_select_all(service,&rfds);
        if (select(maxfd+2, &rfds, NULL, NULL, NULL) < 0){
            perror("select");
            exit(1);
        }
        ubus_activate_all(service,&rfds,0);
        ubus_chan_t * chan=0;
        while((chan=ubus_ready_chan(service))){
            int len = ubus_read(chan,&buff,2000);
            if (len < 1) {
                ubus_disconnect(chan);
            }else {
                if (strncmp(buff, "volup", 5) == 0) {
                    parser->VolumeUp();
                    ubus_write(chan,&buff,len);
                } else if (strncmp(buff, "voldown", 7) == 0) {
                    parser->VolumeDown();
                    ubus_write(chan,&buff,len);
                } else if (strncmp(buff, "mute", 4) == 0) {
                    parser->AudioToggleMute();
                    ubus_write(chan,&buff,len);
                }
            }
        }
    }
    fprintf(stderr,"bye\n");
    ubus_destroy(service);


    parser->Close();
    UnloadLibCec(parser);

    if (g_logOutput.is_open())
        g_logOutput.close();

    return 0;
}