Widget::Widget(QWidget *parent) : QWidget(parent) { red_button=new QRadioButton("red"); yellow_button=new QRadioButton("yellow"); green_button=new QRadioButton("green"); start_button=new QPushButton("start"); stop_button=new QPushButton("stop"); QVBoxLayout *layout=new QVBoxLayout; layout->addWidget(red_button); layout->addWidget(yellow_button); layout->addWidget(green_button); layout->addWidget(start_button); layout->addWidget(stop_button); red_button->setStyleSheet("background-color: grey;"); yellow_button->setStyleSheet("background-color: grey;"); green_button->setStyleSheet("background-color: grey;"); timer=new QTimer; disable_lights(); connect(start_button,SIGNAL(clicked(bool)),this,SLOT(set_timer_start())); connect(start_button,SIGNAL(clicked(bool)),this,SLOT(enable_lights())); connect(stop_button,SIGNAL(clicked(bool)),timer,SLOT(stop())); connect(stop_button,SIGNAL(clicked(bool)),this,SLOT(disable_lights())); connect(timer,SIGNAL(timeout()),this,SLOT(change_light())); setLayout(layout); }
void open_close_bl() { if(flag) { light = atoi("0"); change_light("0"); flag = 0; printf("Close LCD BackLight.\n"); } else { light = atoi("100"); change_light("100"); flag = 1; printf("Open LCD BackLight.\n"); } }
int main(void) { char cmd[4]; light = 100; flag = 1; led1_flag = 1; led2_flag = 1; struct input_event t; if ((open_device()) < 0) return 0; while(1) { if (read(key_fd, &t, sizeof(t)) == sizeof(t) && t.type==EV_KEY) { if (t.value == 0) { switch(t.code) { case 107: open_close_bl(); break; case 231: if(!flag) break; if (light > 0) { light -= 10; sprintf(cmd, "%d", light); change_light(cmd); printf("Current backlight lever is %d.\n",light); } else { printf("Current lever is the lowest!\n"); } break; case 158: if(!flag) break; if (light < 150) { light += 10; sprintf(cmd, "%d", light); change_light(cmd); printf("Current backlight lever is %d.\n",light); } else { printf("Current lever is the highest!\n"); } break; case 139: if (led2_flag) { ioctl(led_fd, 0, 1); led2_flag = 0; } else { ioctl(led_fd, 1, 1); led2_flag = 1; } break; case 102: if (led1_flag) { ioctl(led_fd, 0, 0); led1_flag = 0; } else { ioctl(led_fd, 1, 0); led1_flag = 1; } break; default: break; } } } } close_device(); }