gtk

时间:2017-08-09 07:48:14

标签: c linux gtk raspbian

我在Raspbian机器上运行此代码:

#include <gtk/gtk.h>
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
GtkAdjustment *slider_frequency;
GtkAdjustment *slider_duty_cycle;
//GtkWidget *scale1 (GtkOrientation Horizontal, gdouble 0, gdouble 200, gdouble 1);
int main(int argc, char *argv[])
{
//service.gnome3.at-spi2-core.enable = true;    
   //NO_AT_BRIDGE ="1"; 
   int pin;
   /*for(pin=0;pin<8;++pin){
      pinMode(pin, OUTPUT);
      digitalWrite(pin,LOW);
   }*/
   // wiringPiSetup();
    wiringPiSetupGpio();
    pinMode(18,PWM_OUTPUT);
    pwmSetMode(PWM_MODE_MS);
    pwmSetClock(4);
    pwmSetRange (200) ;
  //pwmWrite (18, 30);
    //scale1->gtk_scale_set_value_pos();
    GtkBuilder      *builder; 
    GtkWidget       *window;

    gtk_init(&argc, &argv);

    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "window_main.glade", NULL);

    window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
    gtk_builder_connect_signals(builder, NULL);

    g_object_unref(builder);

    gtk_widget_show(window);                
    gtk_main();

    return 0;
}

// called when window is closed
void on_window_main_destroy()
{
    gtk_main_quit();
}

void on_slider_frequency_value_changed(slider_frequency){
    //gtk_main_quit();
    int value;
    value = gtk_adjustment_get_value(slider_frequency);
    //printf("%d\n",value);
    pwmSetClock(value);
}
void on_slider_duty_cycle_value_changed(slider_duty_cycle){
    //gtk_main_quit();
    int value;
    value = gtk_adjustment_get_value(slider_duty_cycle);
    //printf("%d\n",value);
   // pwm_Write(18, value);
    pwmWrite (18, value);
}

界面是在Glade中设计的。代码使用名为wiringPi的side lib,我执行它:

sudo gcc -o gladewin pw.c -lwiringPi -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic 
sudo chmod 777 gladewin
./gladewin

发生了一些错误。这是输出,表明出现了问题:

pw.c: In function ‘on_slider_frequency_value_changed’:
pw.c:54:38: warning: passing argument 1 of ‘gtk_adjustment_get_value’ makes pointer from integer without a cast
     value = gtk_adjustment_get_value(slider_frequency);
                                      ^
In file included from /usr/include/gtk-3.0/gtk/gtk.h:38:0,
                 from pw.c:1:
/usr/include/gtk-3.0/gtk/gtkadjustment.h:96:12: note: expected ‘struct GtkAdjustment *’ but argument is of type ‘int’
 gdouble    gtk_adjustment_get_value             (GtkAdjustment   *adjustment);
            ^
pw.c: In function ‘on_slider_duty_cycle_value_changed’:
pw.c:61:38: warning: passing argument 1 of ‘gtk_adjustment_get_value’ makes pointer from integer without a cast
     value = gtk_adjustment_get_value(slider_duty_cycle);
                                      ^
In file included from /usr/include/gtk-3.0/gtk/gtk.h:38:0,
                 from pw.c:1:
/usr/include/gtk-3.0/gtk/gtkadjustment.h:96:12: note: expected ‘struct GtkAdjustment *’ but argument is of type ‘int’
 gdouble    gtk_adjustment_get_value             (GtkAdjustment   *adjustment);

我不明白honeslty如果不通过声明一个名称与glade程序完全相同的指针并将它们放入插槽中,我将如何处理信号。

但有时甚至更糟(统计上可能是1到5)我正在

bus error 

warning ** error retrieving accessibility bus address 
org.freedesktop.dbus.error.serviceunknown

WARNING: Couldn't register with accessibility bus: Did not receive a reply.

当它发生时,我的微型电脑会压碎并停止回复任何东西,但手动断电。 许多来源(例如this)告诉我们在这种情况下应该在终端

中运行
export NO_AT_BRIDGE = 1

但没有任何帮助。所以我可能问题在于我的代码..? 如何避免这条消息并且可能是由我的代码引起的?

更新一次

感谢Barmar,现在我知道shell命令应该没有空格 它必须是

export NO_AT_BRIDGE=1

但是在我得到./gladewin后它没有帮助:

(gladewin:1324): Gtk-WARNING **: Failed to parse /home/pi/.config/gtk-3.0/settings.ini: input/output error
Bus error

更新两次

这一切都无法修复总线错误。现在我正在以这种方式编译后执行我的程序:

export NO_AT_BRIDGE=1
./gladewin

有时(不是所有的时间)我得到了这个:

(gladewin:1319): Gtk-WARNING **: Failed to parse /home/pi/.config/gtk-3.0/settings.ini: Input/output error
(gladewin:1319): Gtk-CRITICAL **: _gtk_css_section_to_string: assertion 'section !=NULL' failed 
(gladewin:1319): Gtk-WARNING **: Theme parsing error: (null): Failed to import: Error opening file: Input/output error
line 3: 1319 Bus error

输出/home/pi/.config/gtk-3.0/settings.ini

[Settings]
gtk-primary-button-warps-slider = false

1 个答案:

答案 0 :(得分:1)

您错过了函数参数的类型声明,因此它们默认为int

void on_slider_frequency_value_changed(GtkAdjustment *slider_frequency){
    //gtk_main_quit();
    int value;
    value = gtk_adjustment_get_value(slider_frequency);
    //printf("%d\n",value);
    pwmSetClock(value);
}
void on_slider_duty_cycle_value_changed(GtkAdjustment *slider_duty_cycle){
    //gtk_main_quit();
    int value;
    value = gtk_adjustment_get_value(slider_duty_cycle);
    //printf("%d\n",value);
   // pwm_Write(18, value);
    pwmWrite (18, value);
}