gpt4 book ai didi

c - gtk 使用的 Linux 微型计算机上的总线错误

转载 作者:太空宇宙 更新时间:2023-11-04 10:17:09 26 4
gpt4 key购买 nike

我在 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 的库,我通过以下方式执行它:

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);

老实说,我不明白如果不是通过声明一个与 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.

当它发生时,我的 microcomp 崩溃并停止回复任何东西,除了手动关闭电源。许多消息来源(例如 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

最佳答案

您缺少函数参数的类型声明,因此它们默认为 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);
}

关于c - gtk 使用的 Linux 微型计算机上的总线错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45584601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com