Example #1
0
void GraphPropertiesWidget::on__graphDelete_clicked()
{
    bool createNewGraph = false;
    bool isActive = false;

    if( _graph == _mainWindow->graph() )
    {
        isActive = true;
    }

    GraphDocument* gd = qobject_cast<GraphDocument*>( _graph->parent() );

    if( gd->size() == 1 )
    {
        createNewGraph = true;
    }


    if( isActive ) emit updateNeeded();
    radio()->group()->removeButton( radio() );


    /*! remove this graph from the document. */
    emit removeGraph();

    if( createNewGraph )
    {
        emit addGraph( i18n( "Untitled0" ) );
    }

    deleteLater();
}
Example #2
0
void createUI(NVGcontext *vg, float w, float h)
{
    int col;

    uiClear();

    {
        int root = uiItem(); 
        // position root element
        uiSetLayout(root,UI_LEFT|UI_TOP);
        uiSetMargins(root,50,50,0,0);
        uiSetSize(root,250,400);
    }

    col = column(0);
    uiSetLayout(col, UI_TOP|UI_HFILL);

    button(col, __LINE__, BND_ICONID(6,3), "Item 1", demohandler);
    button(col, __LINE__, BND_ICONID(6,3), "Item 2", demohandler);

    {
        int h = hgroup(col);
        radio(h, __LINE__, BND_ICONID(6,3), "Item 3.0", &enum1);
        radio(h, __LINE__, BND_ICONID(0,10), NULL, &enum1);
        radio(h, __LINE__, BND_ICONID(1,10), NULL, &enum1);
        radio(h, __LINE__, BND_ICONID(6,3), "Item 3.3", &enum1);
    }

    {
        int colr;
        int rows = row(col);
        int coll = vgroup(rows);
        label(coll, -1, "Items 4.0:");
        coll = vgroup(coll);
        button(coll, __LINE__, BND_ICONID(6,3), "Item 4.0.0", demohandler);
        button(coll, __LINE__, BND_ICONID(6,3), "Item 4.0.1", demohandler);
        colr = vgroup(rows);
        uiSetFrozen(colr, option1);
        label(colr, -1, "Items 4.1:");
        colr = vgroup(colr);
        slider(colr, __LINE__, "Item 4.1.0", &progress1);
        slider(colr,__LINE__, "Item 4.1.1", &progress2);
    }

    button(col, __LINE__, BND_ICONID(6,3), "Item 5", NULL);

    check(col, __LINE__, "Frozen", &option1);
    check(col, __LINE__, "Item 7", &option2);
    check(col, __LINE__, "Item 8", &option3);

    textbox(col, (UIhandle)textbuffer, textbuffer, 32);

    uiLayout();
}
Example #3
0
void build_democontent(int parent) {
    // some persistent variables for demonstration
    static float progress1 = 0.25f;
    static float progress2 = 0.75f;
    static int option1 = 1;
    static int option2 = 0;
    static int option3 = 0;

    int col = column();
    uiInsert(parent, col);
    uiSetMargins(col, 10, 10, 10, 10);
    uiSetLayout(col, UI_TOP|UI_HFILL);
    
    column_append(col, button(BND_ICON_GHOST, "Item 1", demohandler));
    if (option3)
        column_append(col, button(BND_ICON_GHOST, "Item 2", demohandler));

    {
        int h = column_append(col, hbox());
        hgroup_append(h, radio(BND_ICON_GHOST, "Item 3.0", &enum1));
        if (option2)
            uiSetMargins(hgroup_append_fixed(h, radio(BND_ICON_REC, NULL, &enum1)), -1,0,0,0);
        uiSetMargins(hgroup_append_fixed(h, radio(BND_ICON_PLAY, NULL, &enum1)), -1,0,0,0);
        uiSetMargins(hgroup_append(h, radio(BND_ICON_GHOST, "Item 3.3", &enum1)), -1,0,0,0);
    }
    
    {
        int rows = column_append(col, row());
        int coll = row_append(rows, vgroup());
        vgroup_append(coll, label(-1, "Items 4.0:"));
        coll = vgroup_append(coll, vbox());
        vgroup_append(coll, button(BND_ICON_GHOST, "Item 4.0.0", demohandler));
        uiSetMargins(vgroup_append(coll, button(BND_ICON_GHOST, "Item 4.0.1", demohandler)),0,-2,0,0);
        int colr = row_append(rows, vgroup());
        uiSetMargins(colr, 8, 0, 0, 0);
        uiSetFrozen(colr, option1);
        vgroup_append(colr, label(-1, "Items 4.1:"));
        colr = vgroup_append(colr, vbox());
        vgroup_append(colr, slider("Item 4.1.0", &progress1));
        uiSetMargins(vgroup_append(colr, slider("Item 4.1.1", &progress2)),0,-2,0,0);
    }
    
    column_append(col, button(BND_ICON_GHOST, "Item 5", NULL));

    static char textbuffer[1024] = "The quick brown fox.";
    column_append(col, textbox(textbuffer, 1024));

    column_append(col, check("Frozen", &option1));
    column_append(col, check("Item 7", &option2));
    column_append(col, check("Item 8", &option3));
}
int ano(int X, int Y){
	int num=1;
	double dist=sqrt((X*X)+(Y*Y));
	while(radio(num*50)<dist) 
			num++;
	return num;
}
Example #5
0
// QRadioTuner's errorsignal
void tst_QRadioTuner::errorSignal()
{
    qRegisterMetaType<QRadioTuner::Error>("QRadioTuner::Error");
    QObject obj;
    MockRadioTunerControl dctrl(&obj);
    MockMediaService service(&obj, &dctrl);
    MockMediaServiceProvider provider(&service);
    QRadioTuner radio(0,&provider);
    QSignalSpy spy(&radio, SIGNAL(error(QRadioTuner::Error)));
    QVERIFY(radio.service() != 0);
    QVERIFY(radio.isAvailable());
    radio.start();
    radio.setBand(QRadioTuner::FM);
    QVERIFY(spy.count() == 1);
    QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(0).at(0)) == QRadioTuner::NoError);
    QVERIFY(radio.error() == QRadioTuner::NoError);
    QVERIFY(radio.error() != QRadioTuner::OpenError);
    QVERIFY(radio.errorString().isEmpty());
    spy.clear();

    /* emits QRadioTuner::OutOfRangeError if band is set to FM2 or LW
           and frequency set to >= 148500000 */

    radio.setBand(QRadioTuner::LW);
    radio.setBand(QRadioTuner::FM2);
    radio.setFrequency(148500000);
    QVERIFY(spy.count() == 3);
    QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(0).at(0)) == QRadioTuner::OutOfRangeError);
    QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(1).at(0)) == QRadioTuner::OutOfRangeError);
    QVERIFY(qvariant_cast<QRadioTuner::Error>(spy.at(2).at(0)) == QRadioTuner::OutOfRangeError);
    QVERIFY(radio.error() == QRadioTuner::OutOfRangeError);
    QVERIFY2(!radio.errorString().isEmpty(), "band and range not supported");
    spy.clear();
    radio.stop();
}
Example #6
0
void tst_QRadioTuner::testNullService()
{
    const QPair<int, int> nullRange(0, 0);

    MockMediaServiceProvider provider(0);
    QRadioTuner radio(0, &provider);
    QVERIFY(!radio.isAvailable());
    radio.start();
    QCOMPARE(radio.error(), QRadioTuner::ResourceError);
    QCOMPARE(radio.errorString(), QString());
    QCOMPARE(radio.band(), QRadioTuner::FM);
    QCOMPARE(radio.isBandSupported(QRadioTuner::AM), false);
    QCOMPARE(radio.isBandSupported(QRadioTuner::FM), false);
    QCOMPARE(radio.frequency(), 0);
    QCOMPARE(radio.frequencyStep(QRadioTuner::AM), 0);
    QCOMPARE(radio.frequencyStep(QRadioTuner::FM), 0);
    QCOMPARE(radio.frequencyRange(QRadioTuner::AM), nullRange);
    QCOMPARE(radio.frequencyRange(QRadioTuner::FM), nullRange);
    QCOMPARE(radio.isStereo(), false);
    QCOMPARE(radio.stereoMode(), QRadioTuner::Auto);
    QCOMPARE(radio.signalStrength(), 0);
    QCOMPARE(radio.volume(), 0);
    QCOMPARE(radio.isMuted(), false);
    QCOMPARE(radio.isSearching(), false);
    radio.stop();
}
Example #7
0
int add_menu_option(int parent, const char *name, int *choice) {
    int opt = radio(-1, name, choice);
    uiInsert(parent, opt);
    uiSetLayout(opt, UI_HFILL|UI_TOP);
    uiSetMargins(opt, 1, 1, 1, 1);
    return opt;
}
void
nsHTMLRadioButtonAccessible::GetPositionAndSizeInternal(PRInt32 *aPosInSet,
                                                        PRInt32 *aSetSize)
{
  nsAutoString nsURI;
  mContent->NodeInfo()->GetNamespaceURI(nsURI);
  nsAutoString tagName;
  mContent->NodeInfo()->GetName(tagName);

  nsAutoString type;
  mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::type, type);
  nsAutoString name;
  mContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::name, name);

  nsCOMPtr<nsIDOMNodeList> inputs;

  nsCOMPtr<nsIDOMHTMLInputElement> radio(do_QueryInterface(mContent));
  nsCOMPtr<nsIDOMHTMLFormElement> form;
  radio->GetForm(getter_AddRefs(form));
  if (form) {
    form->GetElementsByTagNameNS(nsURI, tagName, getter_AddRefs(inputs));
  } else {
    nsIDocument* doc = mContent->GetOwnerDoc();
    nsCOMPtr<nsIDOMDocument> document(do_QueryInterface(doc));
    if (document)
      document->GetElementsByTagNameNS(nsURI, tagName, getter_AddRefs(inputs));
  }

  NS_ENSURE_TRUE(inputs, );

  PRUint32 inputsCount = 0;
  inputs->GetLength(&inputsCount);

  // Compute posinset and setsize.
  PRInt32 indexOf = 0;
  PRInt32 count = 0;

  for (PRUint32 index = 0; index < inputsCount; index++) {
    nsCOMPtr<nsIDOMNode> itemNode;
    inputs->Item(index, getter_AddRefs(itemNode));

    nsCOMPtr<nsIContent> item(do_QueryInterface(itemNode));
    if (item &&
        item->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::type,
                          type, eCaseMatters) &&
        item->AttrValueIs(kNameSpaceID_None, nsAccessibilityAtoms::name,
                          name, eCaseMatters)) {

      count++;

      if (item == mContent)
        indexOf = count;
    }
  }

  *aPosInSet = indexOf;
  *aSetSize = count;
}
Example #9
0
Nanotubo::Nanotubo (int I, int J)
{
    i1 = I;
    i2 = J;
    ordenmin = 1;  // orden --> order
    _d = 1;
    A = 2.46;

    int nn = i1, mm = i2;
    altura = new double[100];
    phi = new double[100];

    // find common factors between nn and mm, move them to d
    for (int i = 1; i <= 25; i++) {
	for (int j = 1; ((nn % primos[i]) == 0)
		 && ((mm % primos[i]) == 0); j++) {
	    nn = nn / primos[i];
	    mm = mm / primos[i];
	    _d = _d * primos[i];
	}}

    deltaz1 = A * sin (M_PI / 3 - quiral ());
    deltaz2 = A * sin (quiral ());	//esto, al estar bajo Q, es positivo cuando deberia ser negativo! OJO a esto!
    // this, when being under Q, is positive when it would have to be negative! WATCH this!
    deltaphi1 = A / radio () * cos (M_PI / 3 - quiral ());
    deltaphi2 = A / radio () * cos (quiral ());

    altura[1] = deltaz1;
    phi[1] = deltaphi1;

    for (int i = 2; i <= (i1 + i2) / _d; i++) {
	if (altura[i - 1] < 0) {
	    altura[i] = altura[i - 1] + deltaz1;
	    phi[i] = phi[i - 1] + deltaphi1;
	} else {
	    altura[i] = altura[i - 1] - deltaz2;
	    phi[i] = phi[i - 1] + deltaphi2;
	}

	if ((altura[i] < altura[ordenmin]) == (altura[i] > 0.0001))
	    ordenmin = i;
    }
}
Example #10
0
Nanotubo::Nanotubo (int I, int J, double aalt)
{

    A = aalt;
    i1 = I;
    i2 = J;
    ordenmin = 1;
    _d = 1;
    A = 2.46;

    int nn = i1, mm = i2;
    altura = new double[100];
    phi = new double[100];

    for (int i = 1; i <= 25; i++) {
	for (int j = 1; ((nn % primos[i]) == 0)
		 && ((mm % primos[i]) == 0); j++) {
	    nn = nn / primos[i];
	    mm = mm / primos[i];
	    _d = _d * primos[i];
	}}

    deltaz1 = A * sin (M_PI / 3 - quiral ());
    deltaz2 = A * sin (quiral ());
    deltaphi1 = A / radio () * cos (M_PI / 3 - quiral ());
    deltaphi2 = A / radio () * cos (quiral ());

    altura[1] = deltaz1;
    phi[1] = deltaphi1;

    for (int i = 2; i <= (i1 + i2) / _d; i++) {
	if (altura[i - 1] < 0) {
	    altura[i] = altura[i - 1] + deltaz1;
	    phi[i] = phi[i - 1] + deltaphi1;
	} else {
	    altura[i] = altura[i - 1] - deltaz2;
	    phi[i] = phi[i - 1] + deltaphi2;
	}

	if ((altura[i] < altura[ordenmin]) == (altura[i] > 0.0001))
	    ordenmin = i;
    }
}
Example #11
0
int main()
{
    float varnum;

    varnum=(radio(ingreso_numero()));
    printf("El area del circulo es: %.2f",(float)varnum);


    return 0;
}
Example #12
0
int main(int argc, char** argv)
{
    // Options parser
    GOptionContext* ctx = g_option_context_new("streamplay");
    const gchar** remaining_args = NULL;
    GOptionEntry entries[] = {
        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
            &remaining_args, NULL, "FILE" },
        { NULL, '\0', 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
    };
    g_option_context_add_main_entries(ctx, entries, NULL);
    g_option_context_add_group(ctx, gst_init_get_option_group() );

    GError* err = NULL;
    if(!g_option_context_parse(ctx, &argc, &argv, &err)) {
        std::cerr << "Argument error:" << err->message << std::endl;
        g_error_free(err);
        return 1;
    }
    if(! remaining_args) { // Missing url argument
        std::cerr << "Usage: [uri]" << std::endl;
        return 1;
    }

    const gchar* uri = remaining_args[0];

    // GStreamer version info
    guint major, minor, micro, nano;
    gst_init(&argc, &argv);
    gst_version(&major, &minor, &micro, &nano);
    const gchar *nano_str = "";
    switch(nano) {
        case 1:
            nano_str = "(CVS)";
            break;
        case 2:
            nano_str = "(Prerelease)";
            break;
    } 
    std::cout << "Using GStreamer " << major << "." << minor << "." << micro << " " << nano_str << std::endl;

    // Start main loop
    {
        loop = g_main_loop_new(NULL, FALSE);
        InternetRadio radio(uri, loop);
        g_main_loop_run(loop);
    }

    g_main_loop_unref(loop);

    return 0;
}
Example #13
0
void main()
{
f=fopen("onform.html","w");

int i,n;

printf("Enter the title for your html file:");
scanf("%s", title);
printf("Enter the css file to be used:");
scanf("%s",css);
printf("Enter the name of script file to be executed:");
scanf("%s",script);
printf("How many fields you want in your table:");
scanf("%d",&n);
clean_stdin();

//fprintf for writing the things in html file

fprintf(f,"<html><head> \n <title>%s</title>",title);
fprintf(f,"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"> \n </head><body>\n",css);
fprintf(f,"<header><h1>%s</h1></header>",title);
fprintf(f,"<table>");
fprintf(f, "<form action=\"%s\" method=\"GET\">",script);

for(i=0; i<n; i++)
{
printf("Enter the type of field:");
scanf("%c",&type);
if(type=='t')
{
  text();
}
else if(type=='r')
{
	radio();
}
else if(type=='c')
{
	checkbox();
}
else if(type=='p')
{	
	password();
}
}
fprintf(f,"</table>");
fprintf(f,"<center><input type=submit value=Submit></center>");
fprintf(f,"</form></body></html>");
}
Example #14
0
int main()
{
        int resetPin = 23; //GPIO_23
        int sdaPin = 0; //GPIO_0 (SDA)

        Si4703_Breakout radio(resetPin, sdaPin);
        radio.powerOn();
        radio.setVolume(5);
        radio.setChannel(1040); //FM4 104.0Mhz (Austria)

        char rdsBuffer[10] = {0};
        radio.readRDS(rdsBuffer, 15000); //timeout 15sec
        printf("Listening to station: %s %.1f\n", rdsBuffer, radio.getChannel()/10.0);

        return 0;
}
Example #15
0
int main(void)
{
	Nordic radio(0,1,2);
	radio.cePin = 3;
	radio.csnPin = 4;
	radio.init();
	radio.setRADDR((uint8_t *)Myaddress);
	radio.setTADDR((uint8_t *)remoteAddress);
	radio.payload = 32;
	radio.channel = CH;
	radio.config();
    
	uint8_t aux;
	while(1)
    {
        radio.send(&aux);
		aux++; 
		_delay_ms(1000);
    }
}
Example #16
0
void main_loop(void* pvParameters)
{
    int loopcount = 0;
#define SHOW_DEBUG() 0 //((my_state == RUNNING) && (loopcount == 0))


#define SPI_SCLK     4
#define SPI_MISO    27
#define SPI_MOSI     2
#define SPI_CS      GPIO_NUM_16
#define SPI_CE      GPIO_NUM_17

    int power_left = 0;
    int power_right = 0;

#if 0
    int left_x_zero = 512;
    int left_y_zero = 512;
#endif
    int right_x_zero = 512;
    int right_y_zero = 512;
    bool first_reading = true;
    
    auto last_packet = xTaskGetTickCount();

    const int NOF_BATTERY_READINGS = 100;
    int32_t battery_readings[NOF_BATTERY_READINGS];
    int battery_reading_index = 0;
    for (int i = 0; i < NOF_BATTERY_READINGS; ++i)
        battery_readings[i] = 0;

    int max_power = 255;
    
    int count = 0;
    bool led_state = false;
    auto last_led_flip = xTaskGetTickCount();
    bool is_halted = false;

    RF24 radio(SPI_CE, SPI_CS);
    assert(radio_init(radio));

	while (1)
	{
        ++loopcount;
        if (loopcount >= 100)
            loopcount = 0;

        // if there is data ready
        if (radio.available())
        {
            last_packet = xTaskGetTickCount();

            ForwardAirFrame frame;
            // Fetch the payload, and see if this was the last one.
            while (radio.available())
                radio.read(&frame, sizeof(frame));

            if (frame.magic != ForwardAirFrame::MAGIC_VALUE)
            {
                printf("Bad magic value; expected %x, got %x\n", ForwardAirFrame::MAGIC_VALUE, frame.magic);
                continue;
            }

            if (!check_crc(frame))
            {
                printf("Bad CRC\n");
                continue;
            }

            // Echo back tick value so we can compute round trip time
            radio.stopListening();

            ReturnAirFrame ret_frame;
            ret_frame.magic = ReturnAirFrame::MAGIC_VALUE;
            ret_frame.ticks = frame.ticks;
#if 0
            battery_readings[battery_reading_index] = motor_get_battery(motor_device);
            ++battery_reading_index;
            if (battery_reading_index >= NOF_BATTERY_READINGS)
                battery_reading_index = 0;
            int n = 0;
            int32_t sum = 0;
            for (int i = 0; i < NOF_BATTERY_READINGS; ++i)
                if (battery_readings[i])
                {
                    sum += battery_readings[i];
                    ++n;
                }
            // Round to nearest 0.1 V to prevent flickering
            ret_frame.battery = n ? 100*((sum/n+50)/100) : 0;
#endif
            set_crc(ret_frame);
            radio.write(&ret_frame, sizeof(ret_frame));

            radio.startListening();

            frame.right_x = 1023 - frame.right_x; // hack!

#define PUSH(bit)   (is_pushed(frame, bit) ? '1' : '0')
#define TOGGLE(bit) (is_toggle_down(frame, bit) ? 'D' : (is_toggle_up(frame, bit) ? 'U' : '-'))
                
            const int rx = frame.right_x - right_x_zero;
            const int ry = frame.right_y - right_y_zero;

            // Map right pot (0-255) to pivot value (20-51)
            const int pivot = frame.right_pot*2;
            // Map left pot (0-255) to max_power (20-255)
            max_power = static_cast<int>(20 + (256-20)/256.0*frame.left_pot);
            compute_power(rx, ry, power_left, power_right, pivot, max_power);
            ++count;
            if (count > 10)
            {
                count = 0;
                printf("max %d\n", max_power);
                printf("L %4d/%4d R %4d/%4d (%d/%d) P %3d/%3d Push %c%c%c%c"
                       " Toggle %c%c%c%c"
                       " Power %d/%d\n",
                       (int) frame.left_x, (int) frame.left_y, (int) frame.right_x, (int) frame.right_y, rx, ry,
                       int(frame.left_pot), int(frame.right_pot),
                       PUSH(0), PUSH(1), PUSH(2), PUSH(3),
                       TOGGLE(0), TOGGLE(1), TOGGLE(2), TOGGLE(3),
                       power_left, power_right);
#if 0
                if (is_toggle_up(frame, 3))
                    signal_control_lights(signal_device, true, true);
                else if (is_toggle_down(frame, 3))
                    signal_control_lights(signal_device, true, false);
                else
                    signal_control_lights(signal_device, false, true);
#endif
            }
            
            //!!set_motors(power_left, power_right);
            is_halted = false;

#if 0
            if (is_pushed(frame, 0))
                signal_play_sound(signal_device, -1);
#endif
        }
        else
        {
            // No data from radio
            const auto cur_time = xTaskGetTickCount();
            if ((cur_time - last_packet > max_radio_idle_time) && !is_halted)
            {
                is_halted = true;
                printf("HALT: Last packet was seen at %d\n", last_packet);
                first_reading = true;
                set_motors(0, 0);
            }
        }

        // Change LED state every 3 seconds
        const auto cur_time = xTaskGetTickCount();
        if (cur_time - last_led_flip > 3000/portTICK_PERIOD_MS)
        {
            last_led_flip = cur_time;
            led_state = !led_state;
            gpio_set_level(GPIO_INTERNAL_LED, led_state);
        }

        vTaskDelay(1/portTICK_PERIOD_MS);

        //xTaskNotifyWait(0, 0, NULL, 1);
    }
}
Example #17
0
void tst_QRadioTuner::testNullControl()
{
    const QPair<int, int> nullRange(0, 0);

    MockMediaService service(0, 0);
    MockMediaServiceProvider provider(&service);
    QRadioTuner radio(0, &provider);
    QVERIFY(!radio.isAvailable());
    radio.start();

    QCOMPARE(radio.error(), QRadioTuner::ResourceError);
    QCOMPARE(radio.errorString(), QString());

    QCOMPARE(radio.band(), QRadioTuner::FM);
    QCOMPARE(radio.isBandSupported(QRadioTuner::AM), false);
    QCOMPARE(radio.isBandSupported(QRadioTuner::FM), false);
    QCOMPARE(radio.frequency(), 0);
    QCOMPARE(radio.frequencyStep(QRadioTuner::AM), 0);
    QCOMPARE(radio.frequencyStep(QRadioTuner::FM), 0);
    QCOMPARE(radio.frequencyRange(QRadioTuner::AM), nullRange);
    QCOMPARE(radio.frequencyRange(QRadioTuner::FM), nullRange);
    {
        QSignalSpy bandSpy(&radio, SIGNAL(bandChanged(QRadioTuner::Band)));
        QSignalSpy frequencySpy(&radio, SIGNAL(frequencyChanged(int)));

        radio.setFrequency(107500);
        QCOMPARE(radio.band(), QRadioTuner::FM);
        QCOMPARE(radio.frequency(), 0);
        QCOMPARE(bandSpy.count(), 0);
        QCOMPARE(frequencySpy.count(), 0);

        radio.setBand(QRadioTuner::AM);
        QCOMPARE(radio.band(), QRadioTuner::FM);
        QCOMPARE(radio.frequency(), 0);
        QCOMPARE(bandSpy.count(), 0);
        QCOMPARE(frequencySpy.count(), 0);
    }
    QCOMPARE(radio.isStereo(), false);
    QCOMPARE(radio.stereoMode(), QRadioTuner::Auto);

    radio.setStereoMode(QRadioTuner::ForceStereo);
    QCOMPARE(radio.stereoMode(), QRadioTuner::Auto);

    QCOMPARE(radio.signalStrength(), 0);

    QCOMPARE(radio.volume(), 0);
    QCOMPARE(radio.isMuted(), false);
    {
        QSignalSpy volumeSpy(&radio, SIGNAL(volumeChanged(int)));
        QSignalSpy muteSpy(&radio, SIGNAL(mutedChanged(bool)));

        radio.setVolume(76);
        QCOMPARE(radio.volume(), 0);
        QCOMPARE(volumeSpy.count(), 0);

        radio.setMuted(true);
        QCOMPARE(radio.isMuted(), false);
        QCOMPARE(muteSpy.count(), 0);
    }
    QCOMPARE(radio.isSearching(), false);
    {
        QSignalSpy spy(&radio, SIGNAL(searchingChanged(bool)));

        radio.searchBackward();
        QCOMPARE(radio.isSearching(), false);
        QCOMPARE(spy.count(), 0);

        radio.searchForward();
        QCOMPARE(radio.isSearching(), false);
        QCOMPARE(spy.count(), 0);

        radio.cancelSearch();
        QCOMPARE(radio.isSearching(), false);
        QCOMPARE(spy.count(), 0);
    }

    radio.stop();
}
Example #18
0
int main(int argc, char **argv)
{

  std::string addressStr;
  std::string defaultAddressStr("0xE7E7E7E7E7");
  bool verbose = false;

  namespace po = boost::program_options;

  po::options_description desc("Allowed options");
  desc.add_options()
    ("help", "produce help message")
    ("address", po::value<std::string>(&addressStr)->default_value(defaultAddressStr), "device address")
    ("verbose,v", "verbose output")
  ;

  try
  {
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);

    if (vm.count("help")) {
      std::cout << desc << "\n";
      return 0;
    }
    verbose = vm.count("verbose");
  }
  catch(po::error& e)
  {
    std::cerr << e.what() << std::endl << std::endl;
    std::cerr << desc << std::endl;
    return 1;
  }

  try
  {
    uint32_t numCrazyradios = Crazyradio::numDevices();
    if (numCrazyradios > 0) {
      uint64_t address;
      std::stringstream sstr;
      sstr << std::hex << addressStr;
      sstr >> address;

      Crazyradio radio(0);
      if (verbose) {
        std::cout << "Found Crazyradio with version " << radio.version() << std::endl;
      }
      radio.setAddress(address);
      size_t numCFsFound = 0;
      for (uint8_t datarate = 0; datarate < 3; ++datarate) {
        radio.setDatarate((Crazyradio::Datarate)datarate);
        for (uint8_t channel = 0; channel <= 125; ++channel) {
          radio.setChannel(channel);

          uint8_t test[] = {0xFF};
          Crazyradio::Ack ack;
          radio.sendPacket(test, sizeof(test), ack);
          if (ack.ack) {
            ++numCFsFound;
            std::cout << "radio://0/" << (uint32_t)channel << "/";
            switch(datarate) {
            case Crazyradio::Datarate_250KPS:
              std::cout << "250K";
              break;
            case Crazyradio::Datarate_1MPS:
              std::cout << "1M";
              break;
            case Crazyradio::Datarate_2MPS:
              std::cout << "2M";
              break;
            }

            if (defaultAddressStr != addressStr) {
              std::cout << "/" << addressStr.substr(2);
            }
            std::cout << std::endl;
          }
        }
      }

      if (   numCFsFound == 0
          && verbose) {
        std::cout << "No Crazyflie found. Did you specify the correct address?" << std::endl;
      }
    } else if (verbose) {
      std::cout << "No Crazyradio found." << std::endl;
    }

    uint32_t numCFoverUSB = CrazyflieUSB::numDevices();
    if (numCFoverUSB > 0) {
      CrazyflieUSB cfusb(0);
      if (verbose) {
        std::cout << "Found Crazyflie connected via USB cable with version " << cfusb.version() << std::endl;
      }

      for (uint32_t i = 0; i < numCFoverUSB; ++i) {
        std::cout << "usb://" << i << std::endl;
      }

    } else if (verbose) {
      std::cout << "No Crazyflie connected via USB cable found." << std::endl;
    }
    return 0;
  }
Example #19
0
int main(int argc, char **argv) {
	try {

		RadioUART radio(57600, Radio::PARITY_EVEN);

		int  done = 0,
			 bytes;
		char *pos;
		std::string buffer;

		while (!done) {
			// Receive
			bytes = radio.read(buffer, 50);
			if (bytes > 0) {
				// Convert CR to LF
				size_t index;
				while ((index = buffer.find('\r')) != std::string::npos)
					buffer[index] = '\n';
				std::cout << "Rx: " << buffer << std::endl;
			}
			bytes = radio.getInputQueueSize();
			std::cout << "(" << bytes << " bytes in queue)" << std::endl;

			if (buffer.find('`') != std::string::npos)
				done = 1;
			else {
				// Transmit
				std::cout << "Tx: ";
				std::getline(std::cin, buffer);

				if (buffer.length() > 0) {
					radio.write(buffer);
					if (buffer.find('`') != std::string::npos)
						done = 1;
				}
			}
		}

		std::cout << "Attempting to read a UBE16..." << std::endl;
		uint16_t number16;
		if (radio.readUBE16(&number16))
			std::cout << "  Received: " << number16 << std::endl;
		else {
			std::cout << "  Not enough data to read" << std::endl
			          << "  (Size of queue: " << radio.getInputQueueSize()
					  << ")" << std::endl;
		}

		std::cout << "Attempting to read a UBE32..." << std::endl;
		uint32_t number32;
		if (radio.readUBE32(&number32))
			std::cout << "  Received: " << number32 << std::endl;
		else {
			std::cout << "  Not enough data to read" << std::endl
			          << "  (Size of queue: " << radio.getInputQueueSize()
					  << ")" << std::endl;
		}

	} catch (Exception &e) {
		std::cout << "EXCEPTION: " << e.getDescription() << std::endl;
		return -1;
	}

	std::cout << "Done!" << std::endl;
	return 0;
}
Example #20
0
int main(int argc, char **argv)
{

    struct mosquitto *mosq;

	mosquitto_lib_init();
	mosq = mosquitto_new("id", true, NULL);
    mosquitto_publish_callback_set(mosq, on_publish);

    mosquitto_connect(mosq, "localhost", 1883, 0);




	RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);	

	const uint8_t rxpipe[5] = {'N','o','d','e','0'};

	uint8_t payload[32];
//	char humidity[4];
//	char temperature[4];

	radio.begin();
	radio.enableDynamicPayloads();
	radio.setRetries(5,15);
	radio.printDetails();

	radio.openReadingPipe(1,rxpipe);
	radio.startListening();

	while (1) {

		if ( radio.available() )
		{
			// Dump the payloads until we've gotten everything
			uint8_t len;


			while (radio.available())
			{
				// Fetch the payload, and see if this was the last one.
				len = radio.getDynamicPayloadSize();
				radio.read( payload, len );

				// Put a zero at the end for easy printing
//				sprintf(humidity, "%d", payload[0]);
//				sprintf(temperature, "%d", payload[1]);

				// Spew it
				printf("Got payload size=%i value=%d,%d\n\r",len,payload[0],payload[1]);
//				mosquitto_publish(mosq, NULL, "nodes/01/humidity", strlen(humidity), humidity, 0, false);
//				mosquitto_publish(mosq, NULL, "nodes/01/temperature", strlen(temperature), temperature, 0, false);
				mosquitto_publish(mosq, NULL, "nodes/01/humidity", 1, &payload[0], 0, false);
				mosquitto_publish(mosq, NULL, "nodes/01/temperature", 1, &payload[1], 0, false);
				mosquitto_loop(mosq, -1, 1);  // this calls mosquitto_loop() in a loop, it will exit once the client disconnects cleanly
			}

		}
		sleep(1);
	}

	return 0;
}
Example #21
0
/*---------------------------------------------------*/
void event_handler()
{
	int dummy,ev_bkstate,ev_bkreturn,ev_bbutton,ev_breturn,ev_bmx,ev_bmy;
	int mbuff[8]/*,xs[4]*/;
	int mwhich,obn;
	int col,ba;

	while(1)
	{
		mwhich=evnt_multi(MU_KEYBD|MU_BUTTON|MU_MESAG,1,1,
			1,0,0,
			0,0,0,
			0,0,0,0,
			0,mbuff,0,
			0,&ev_bmx,&ev_bmy,
			&ev_bbutton,&ev_bkstate,
			&ev_bkreturn,&ev_breturn);
		
		if (mwhich&MU_KEYBD);
		
		
		if (mwhich&MU_BUTTON)
		{
			obn=objc_find(rs_object,0,10,ev_bmx,ev_bmy);
			if ((obn==SAVE)&!(rs_object[SAVE].ob_state&DISABLED))

			{
				rs_object[SAVE].ob_state=SELECTED;
				redraw(SAVE);
				save();
				rs_object[SAVE].ob_state=0;
				redraw(SAVE);
			}
			else
			if ((obn==SAVER)&!(rs_object[SAVER].ob_state&DISABLED))
			{
				saver_flag=!saver_flag;
				rs_object[SAVER].ob_state=SELECTED*saver_flag;
				redraw(SAVER);
				get_modes(saver_flag,-3); /* Saver setzten */
			}
			else
			{
				col=(obn-COL2R1)/5;
				ba=obn-5*col-COL2R1;
				if ((col>=0)&&(col<5)&&(ba>=0)&&(ba<=2)&&
					!(rs_object[COL2R1+5*col+ba].ob_state&DISABLED))
				{
					radio(COL2R1+5*col+ba,COL2R1+5*col,COL2R1+5*col+2);
					if (ba==2)
					{
						get_modes(col,0);
					}
					else  
					{
						get_modes(col,1+ba);
					}
					redraw(COL2BOX+5*col);
				}
			}
			(void)evnt_button(1,1,0,&dummy,&dummy,&dummy,&dummy);	
		}
		
		if (mwhich&MU_MESAG)
		{
			if (mbuff[0]==WM_REDRAW)
			{	
				get_conf();
				redraw(TREE1);
			}
			if (mbuff[0]==WM_MOVED)
			{	
				wind_set(wid,WF_CURRXYWH,
		 			mbuff[4],mbuff[5],mbuff[6],mbuff[7]);
		 		(void)wind_get(wid,WF_WORKXYWH,
					&rs_object[TREE1].ob_x,&rs_object[TREE1].ob_y,
					&dummy,&dummy);
			}
			if ((mbuff[0]==WM_TOPPED)||(mbuff[0]==WM_NEWTOP))
				wind_set(wid,WF_TOP);
			if (mbuff[0]==WM_CLOSED)
				quit_all();
			if ((mbuff[0]==AC_OPEN)&&(!open_f))
			{
				open_w();
			}
			if ((mbuff[0]==AC_CLOSE)&(open_f))
			{
				open_f=0;
			}
			if ((mbuff[0]==WM_ICONIFY)||(mbuff[0]==WM_ALLICONIFY))
			{
				wind_set(wid,WF_ICONIFY,mbuff[4],mbuff[5],82,32+24);
			}
			if ((mbuff[0]==WM_UNICONIFY))
			{
				wind_set(wid,WF_UNICONIFY,mbuff[4],mbuff[5],mbuff[6],mbuff[7]);
			}
		}
	}
}
Example #22
0
int main(int argc, char **argv) {

	// Get current console termios attributes (so we can restore it later)
	struct termios in_oldattr, in_newattr;
	tcgetattr(STDIN_FILENO, &in_oldattr);
	memcpy(&in_newattr, &in_oldattr, sizeof(struct termios));

	// Set console attributes
	in_newattr.c_lflag = 0;
	in_newattr.c_cc[VMIN] = 0;
	in_newattr.c_cc[VTIME] = 0;
	in_newattr.c_cc[VINTR] = 3;

	tcsetattr(STDIN_FILENO, TCSANOW, &in_newattr);

	usleep(3000000);

	tcsetattr(STDIN_FILENO, TCSANOW, &in_oldattr);
	return 0;

	try {
		RadioLinux radio("/dev/ttyUSB0", 57600, Radio::PARITY_EVEN);
		RadioConnection connection(&radio);

		std::cout << "Waiting for connection..." << std::endl;
		connection.connect();
		std::cout << "Connected!" << std::endl;

		std::cout << "Use W and S to move up and down" << std::endl;

		char c;
		bool running = true;
		while (running) {
			c = read(STDIN_FILENO, &c, 1);
			switch (c) {
				case 'q': {
					PacketMotion p(0, 0, 0, 64);
					connection.send(&p);
					std::cout << "Sent \"quit\" signal" << std::endl;
					running = false;
				}	break;
				case 'w': {
					PacketMotion p(0, 0, 32, 0);
					connection.send(&p);
					std::cout << "Sent +z signal" << std::endl;
				}	break;
				case 's': {
					PacketMotion p(0, 0, -32, 0);
					connection.send(&p);
					std::cout << "Sent -z signal" << std::endl;
				}	break;
				default:
					break;
			}

			usleep(100000);
		}

	} catch (Exception &e) {
		std::cout << "EXCEPTION: " << e.getDescription() << std::endl;
		return -1;
	}

	std::cout << "Quitting..." << std::endl;
	tcsetattr(STDIN_FILENO, TCSANOW, &in_oldattr);
	
	usleep(500000);

	return 0;
}
Example #23
0
int main(int argc, char *argv[])
{
        printf("Starting");
	bool verbose = false, sock = true, daemon = true;
	int opt;
	while ((opt = getopt(argc, argv, "vs")) != -1)
		switch(opt) {
		case 'v':
			verbose = true;
			daemon = false;
			break;
		case 's':
			sock = false;
			break;
		default:
			fprintf(stderr, "Usage: %s [-v] [-s]\n", argv[0]);
			exit(1);
		}

	if (daemon) {
		pid_t pid = fork();

		if (pid < 0)
			exit(-1);
		if (pid > 0)
			exit(0);
		if (setsid() < 0)
			exit(-1);

		pid = fork();
		if (pid < 0)
			exit(-1);
		if (pid > 0)
			exit(0);

		umask(0);
		chdir("/tmp");
		close(0);
		close(1);
		close(2);
	}

	signal(SIGINT, signal_handler);

	// set up server socket for clients to connect to, to receive text data
	if (sock) {
		ss = socket(AF_INET, SOCK_STREAM, 0);
		if (ss < 0)
			fatal("socket", strerror(errno));

		struct sockaddr_in serv;
		memset(&serv, 0, sizeof(serv));
		serv.sin_family = AF_INET;
		serv.sin_addr.s_addr = htonl(INADDR_ANY);
		serv.sin_port = htons(5555);
		if (0 > bind(ss, (struct sockaddr *)&serv, sizeof(struct sockaddr)))
			fatal("bind", strerror(errno));

		if (0 > listen(ss, 1))
			fatal("listen", strerror(errno));
	}

	// set up radio details
	RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_CLOCK_DIVIDER_32);	
	radio.begin();
	radio.enableDynamicPayloads();
	radio.setAutoAck(true);
	radio.powerUp();

	const uint16_t this_node = 0;
	RF24Network network(radio);
	network.begin(channel, this_node);

	printf("node_id\t0\t1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\n");

	for (;;) {
		network.update();

		while (network.available()) {
			RF24NetworkHeader header;
			uint8_t buf[1024];
			network.read(header, &buf, sizeof(buf));

			// if client connected to socket, send data
			/*
			if (cs > 0) {
				char buf[1024];
				int n = sprintf(buf, "%d\t%d\t%3.1f\t%3.1f\t%d\t%4.2f\t%u\t%d\t%u\n", 
						header.from_node, payload.light, temperature, humidity, payload.status, 
						battery, header.type, header.id, payload.ms / 1000);
				if (0 > write(cs, buf, n)) {
					perror("write");
					close(cs);
					cs = 0;
				}
			}
			*/
			
			// dump received data
			printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", 
					header.from_node, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12]);
		}

		// if server socket has received connection, set up client socket and send header
		struct timeval timeout;
		timeout.tv_usec = 100000;
		timeout.tv_sec = 0;
		fd_set rd;
		FD_ZERO(&rd);
		if (ss > 0)
			FD_SET(ss, &rd);
		if (select(ss + 1, &rd, 0, 0, &timeout) > 0) {
			struct sockaddr_in client;
			socklen_t addrlen = sizeof(struct sockaddr_in);
			cs = accept(ss, (struct sockaddr *)&client, &addrlen);
			if (cs < 0)
				fatal("accept", strerror(errno));

			const char *header = "node\tlight\tdegC\thum%\tstat\tVbatt\ttype\tmsg-id\ttime\n";
			write(cs, header, strlen(header));
		}
	}
	return 0;
}
Example #24
0
int main(int argc, char **argv)
{

  std::string addressStr;
  std::string defaultAddressStr("0xE7E7E7E7E7");

  namespace po = boost::program_options;

  po::options_description desc("Allowed options");
  desc.add_options()
    ("help", "produce help message")
    ("address", po::value<std::string>(&addressStr)->default_value(defaultAddressStr), "device address")
  ;

  try
  {
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);
    po::notify(vm);

    if (vm.count("help")) {
      std::cout << desc << "\n";
      return 0;
    }
  }
  catch(po::error& e)
  {
    std::cerr << e.what() << std::endl << std::endl;
    std::cerr << desc << std::endl;
    return 1;
  }

  try
  {
    uint64_t address;
    std::stringstream sstr;
    sstr << std::hex << addressStr;
    sstr >> address;

    Crazyradio radio(0);
    radio.setAddress(address);

    for (uint8_t datarate = 0; datarate < 3; ++datarate) {
      radio.setDatarate((Crazyradio::Datarate)datarate);
      for (uint8_t channel = 0; channel <= 125; ++channel) {
        radio.setChannel(channel);

        uint8_t test[] = {0xFF};
        Crazyradio::Ack ack;
        radio.sendPacket(test, sizeof(test), ack);
        if (ack.ack) {
          std::cout << "radio://0/" << (uint32_t)channel << "/";
          switch(datarate) {
          case Crazyradio::Datarate_250KPS:
            std::cout << "250K";
            break;
          case Crazyradio::Datarate_1MPS:
            std::cout << "1M";
            break;
          case Crazyradio::Datarate_2MPS:
            std::cout << "2M";
            break;
          }

          if (defaultAddressStr != addressStr) {
            std::cout << "/" << addressStr.substr(2);
          }
          std::cout << std::endl;
        }
      }
    }
    return 0;
  }
  catch(std::exception& e)
  {
    std::cerr << e.what() << std::endl;
    return 1;
  }
}
Example #25
0
double Nanotubo::deltaphic ()
{
    return A / sqrt (3) / radio () * sin (quiral ());
}
Example #26
0
int main(int argc, char **argv) {
	try {

		RadioUART radio(57600, Radio::PARITY_EVEN);
		RadioConnection connection(&radio);

		std::cout << "Waiting for connection..." << std::endl;
		connection.connect();
		std::cout << "Connected!" << std::endl;

		while (true) {
			// Receive
			Packet *packet = 0;

			int times = 0;
			while (times <= 300 && (packet = connection.receive()) == 0) {
				usleep(10000);
				++times;
			}

			if (times > 300)
				std::cout << "Timeout... Switching to send" << std::endl;
			else {
				switch (packet->getHeader()) {
					case PKT_MOTION: {
						PacketMotion *p = (PacketMotion *)packet;
						std::cout << "Received PKT_MOTION : "
								  << "x = " << (int)p->getX()
								  << ", y = " << (int)p->getY()
								  << ", z = " << (int)p->getZ()
								  << ", rot = " << (int)p->getRot()
								  << std::endl;
					}	break;

					case PKT_DIAGNOSTIC: {
						PacketDiagnostic *p = (PacketDiagnostic *)packet;
						std::cout << "Received PKT_DIAGNOSTIC : "
							<< "battery = " << (unsigned int)p->getBattery()
							<< ", accel_x = " << p->getAccelX()
							<< ", accel_y = " << p->getAccelY()
							<< ", accel_z = " << p->getAccelZ()
							<< std::endl;
					}	break;

					default:
						std::cout << "Unrecognized packet type" << std::endl;
						break;
				}

				delete packet;
			}

			// Send
			struct timeval t;
			gettimeofday(&t, NULL);
			srand(t.tv_sec + t.tv_usec);

			int type = rand() % 2;
			switch (type) {
				// PKT_MOTION
				default:
				case 0: {
					int8_t x = (rand() % 255) - 128,
					       y = (rand() % 255) - 128,
					       z = (rand() % 255) - 128,
					       rot = (rand() % 255) - 128;
					packet = new PacketMotion(x, y, z, rot);
					connection.send(packet);
					std::cout << "Sent PKT_MOTION : " << (int)x << ", "
							<< (int)y << ", " << (int)z << ", " << (int)rot
							<< std::endl;

					delete packet;
					packet = 0;
				}	break;

				// PKT_DIAGNOSTIC
				case 1: {
					int8_t batt = (rand() % 255) - 128;
					float  x = (float)(rand() % 255) / 255.0f,
					       y = (float)(rand() % 255) / 255.0f,
					       z = (float)(rand() % 255) / 255.0f;

					packet = new PacketDiagnostic(batt, x, y, z);
					connection.send(packet);
					std::cout << "Sent PKT_DIAGNOSTIC : " << (int)batt << ", "
							<< x << ", " << y << ", " << z << std::endl;

					delete packet;
					packet = 0;
				}	break;
			}

			usleep(100000);
		}

	} catch (Exception &e) {
		std::cout << "EXCEPTION: " << e.getDescription() << std::endl;
		return -1;
	}

	std::cout << "Done!" << std::endl;
	return 0;
}