PoweroffDialog::PoweroffDialog(QWidget *parent) : QDialog(parent), ui(new Ui::PoweroffDialog), m_timer(new QTimer(this)) { ui->setupUi(this); connect(ui->btnExecute, SIGNAL(clicked()) , this, SLOT(btnExecute_click())); connect(ui->btnCancel, SIGNAL(clicked()) , this, SLOT(btnCancel_click())); connect(this, SIGNAL(accepted()) , this, SLOT(dialog_accepted())); connect(this, SIGNAL(rejected()) , this, SLOT(dialog_rejected())); connect(m_timer, SIGNAL(timeout()) , this, SLOT(timer_event())); // setup timer m_timer->setInterval(1000); // 1 second m_timer->setSingleShot(false); // always execute the timer m_timer->stop(); // topmost frameless window setWindowFlags(Qt::Window | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::ToolTip); }
void MessagePumpLibevent::Run(Delegate* delegate) { //DCHECK(keep_running_) << "Quit must have been called outside of Run!"; assert(keep_running_); // event_base_loopexit() + EVLOOP_ONCE is leaky, see http://crbug.com/25641. // Instead, make our own timer and reuse it on each call to event_base_loop(). std::unique_ptr<event> timer_event(new event); for (;;) { bool did_work = delegate->DoWork(); if (!keep_running_) break; event_base_loop(event_base_, EVLOOP_NONBLOCK); did_work |= processed_io_events_; processed_io_events_ = false; if (!keep_running_) break; did_work |= delegate->DoDelayedWork(&delayed_work_time_); if (!keep_running_) break; if (did_work) continue; did_work = delegate->DoIdleWork(); if (!keep_running_) break; if (did_work) continue; // EVLOOP_ONCE tells libevent to only block once, // but to service all pending events when it wakes up. if (delayed_work_time_.is_null()) { event_base_loop(event_base_, EVLOOP_ONCE); } else { TimeDelta delay = delayed_work_time_ - TimeTicks::Now(); if (delay > TimeDelta()) { struct timeval poll_tv; poll_tv.tv_sec = (long)delay.InSeconds(); poll_tv.tv_usec = delay.InMicroseconds() % Time::kMicrosecondsPerSecond; event_set(timer_event.get(), -1, 0, timer_callback, event_base_); event_base_set(event_base_, timer_event.get()); event_add(timer_event.get(), &poll_tv); event_base_loop(event_base_, EVLOOP_ONCE); event_del(timer_event.get()); } else { delayed_work_time_ = TimeTicks(); } } } keep_running_ = true; }
int start(int argc, char **argv) { GR_EVENT event; nxeyes_state *state; if(GrOpen() < 0) { printf("Couldn't connect to Nano-X server\n"); return 1; } if(!(state = init())) { printf("Couldn't allocate state structure\n"); return 1; } while(!state->quit) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: state->quit = 1; break; case GR_EVENT_TYPE_MOUSE_POSITION: position_event(&event.mouse, state); break; case GR_EVENT_TYPE_BUTTON_UP: case GR_EVENT_TYPE_BUTTON_DOWN: button_event(&event.button, state); break; case GR_EVENT_TYPE_EXPOSURE: draw_eyes(state, 1); break; #if MW_FEATURE_TIMERS case GR_EVENT_TYPE_TIMER: timer_event(&event.timer, state); break; #endif default: break; } if(state->mouse_moved) { draw_eyes(state, 0); state->mouse_moved = 0; } } GrClose(); free(state); return 0; }
static void timer_done(struct s_smc *smc, int restart) { u_long delta ; struct smt_timer *tm ; struct smt_timer *next ; struct smt_timer **last ; int done = 0 ; delta = hwt_read(smc) ; last = &smc->t.st_queue ; tm = smc->t.st_queue ; while (tm && !done) { if (delta >= tm->tm_delta) { tm->tm_active = FALSE ; delta -= tm->tm_delta ; last = &tm->tm_next ; tm = tm->tm_next ; } else { tm->tm_delta -= delta ; delta = 0 ; done = 1 ; } } *last = NULL; next = smc->t.st_queue ; smc->t.st_queue = tm ; for ( tm = next ; tm ; tm = next) { next = tm->tm_next ; timer_event(smc,tm->tm_token) ; } if (restart && smc->t.st_queue) hwt_start(smc,smc->t.st_queue->tm_delta) ; }
int main(int argc, char *argv[]) { char line[PATH_MAX+10]; SDL_Surface *screen; const SDL_VideoInfo* screen_info; struct frame first_frame = blank_frame; struct frame *current_frame = &first_frame; /* Initialize SDL */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } atexit(SDL_Quit); while(fgets(line, PATH_MAX+10, stdin)) { if(line[0] && line[0] != '\n') { load_frame(line, current_frame); current_frame->next = xmalloc(sizeof(*current_frame)); *current_frame->next = blank_frame; current_frame->next->prev = current_frame; current_frame = current_frame->next; } } /* XXX Inefficient */ current_frame->prev->next = NULL; /* Get screen resolution and initialize window */ screen_info = SDL_GetVideoInfo(); if(!screen_info) { fprintf(stderr, "SDL_GetVideoInfo: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } if(!(screen = SDL_SetVideoMode(screen_info->current_w, screen_info->current_h, 0, SDL_HWSURFACE))) { fprintf(stderr, "Unable to init SDL screen: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Fake the first timer event */ timer_event(0, &first_frame); /* Wait for exit events */ while(1) { SDL_Rect rect; SDL_Event event; event.type = 0; if(!SDL_WaitEvent(&event)) { fprintf(stderr, "Unable to get event: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } switch(event.type) { case SDL_USEREVENT: switch(event.user.code) { case TIMER_EVENT: current_frame = event.user.data1; /* This may already be the last slide */ if(!current_frame) { goto mainloopend; } /* Calculate where to draw the image */ rect.x = (screen->w/2)-current_frame->image->w; rect.y = (screen->h/2)-current_frame->image->h; rect.w = current_frame->image->w; rect.h = current_frame->image->h; /* Redraw dirtied background */ if(SDL_FillRect(screen, &rect, 0) != 0) { fprintf(stderr, "Unable to draw rectangle: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Draw image */ if(SDL_BlitSurface(current_frame->image, NULL, screen, &rect) != 0) { fprintf(stderr, "Unable to blit frame: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Update dirty rects */ SDL_UpdateRects(screen, 1, &rect); /* Wait until this slide is done before advancing */ SDL_AddTimer(current_frame->length*1000, &timer_event, current_frame->next); break; } break; case SDL_QUIT: goto mainloopend; } } mainloopend: exit(EXIT_SUCCESS); }
void main(void) { unsigned char n; // // Initialisierung // restart_hw(); TASTER=0; // Prog. LED kurz Ein // Warten bis Bus stabil, nach Busspannungswiederkehr for (n = 0; n < 50; n++) { TR0 = 0; // Timer 0 anhalten TH0 = 0; // Timer 0 setzen mit phys. Adr. damit Geräte unterschiedlich beginnen zu senden TL0 = eeprom[ADDRTAB + 2]; // Nur Low Byte der PA nutzen, sonst sehr kurze Wartezeit bei 15.15.255 TF0 = 0; // Überlauf-Flag zurücksetzen TR0 = 1; // Timer 0 starten while (!TF0) ; } #ifdef DEVICE_ID_CHECK // Only start if correct application has been loaded for(n = 0; n<=3; n++) { if(eeprom[0x03+n] != dev_application_id[n]) { EA = 0; START_WRITECYCLE; WRITE_BYTE(0x01,0x0D,0xFB); // Indicate Stack Overflow, holds app STOP_WRITECYCLE; EA = 1; break; // Flash just once } } #endif restart_app(); do { // // Hauptverarbeitung // if (APPLICATION_RUN) { if (RI) rm_recv_byte(); if (RTCCON >= 0x80) timer_event(); if (!answerWait) process_alarm_stats(); if (!answerWait) process_objs(); } else if (RTCCON>=0x80 && connected) // Realtime clock ueberlauf { // wenn connected den timeout für Unicast connect behandeln RTCCON=0x61;// RTC flag löschen if(connected_timeout <= 110)// 11x 520ms --> ca 6 Sekunden { connected_timeout ++; } else send_obj_value(T_DISCONNECT);// wenn timeout dann disconnect, flag und var wird in build_tel() gelöscht } // // Empfangenes Telegramm bearbeiten, aber nur wenn wir gerade nichts // vom Rauchmelder empfangen. // if (tel_arrived) // && recvCount < 0) process_tel(); // // Watchdog rücksetzen // EA = 0; WFEED1 = 0xA5; WFEED2 = 0x5A; EA = 1; // // Abfrage des Programmier-Tasters // TASTER = 1; if (!TASTER) { for (n = 0; n < 100; n++) // Entprellen ; while (!TASTER) // Warten bis Taster losgelassen ; status60 ^= 0x81;// Prog-Bit und Parity-Bit im system_state toggeln } TASTER = !(status60 & 0x01);// LED entsprechend Prog-Bit schalten (low=LED an) } while (1); }
void main(void) { unsigned char n; // // Initialisierung // restart_hw(); TASTER=0; // Prog. LED kurz Ein // Warten bis Bus stabil, nach Busspannungswiederkehr for (n = 0; n < 50; n++) { TR0 = 0; // Timer 0 anhalten TH0 = eeprom[ADDRTAB + 1]; // Timer 0 setzen mit phys. Adr. damit Geräte unterschiedlich beginnen zu senden TL0 = eeprom[ADDRTAB + 2]; TF0 = 0; // Überlauf-Flag zurücksetzen TR0 = 1; // Timer 0 starten while (!TF0) ; } restart_app(); do { // // Hauptverarbeitung // if (APPLICATION_RUN) { if (RI) rm_recv_byte(); if (RTCCON >= 0x80) timer_event(); if (!answerWait) process_alarm_stats(); if (!answerWait) process_objs(); } else if (RTCCON>=0x80 && connected) // Realtime clock ueberlauf { // wenn connected den timeout für Unicast connect behandeln RTCCON=0x61;// RTC flag löschen if(connected_timeout <= 110)// 11x 520ms --> ca 6 Sekunden { connected_timeout ++; } else send_obj_value(T_DISCONNECT);// wenn timeout dann disconnect, flag und var wird in build_tel() gelöscht } // // Empfangenes Telegramm bearbeiten, aber nur wenn wir gerade nichts // vom Rauchmelder empfangen. // if (tel_arrived) // && recvCount < 0) process_tel(); // // Watchdog rücksetzen // EA = 0; WFEED1 = 0xA5; WFEED2 = 0x5A; EA = 1; // // Abfrage des Programmier-Tasters // TASTER = 1; if (!TASTER) { for (n = 0; n < 100; n++) // Entprellen ; while (!TASTER) // Warten bis Taster losgelassen ; status60 ^= 0x81;// Prog-Bit und Parity-Bit im system_state toggeln } TASTER = !(status60 & 0x01);// LED entsprechend Prog-Bit schalten (low=LED an) } while (1); }
void main(void) { unsigned char n; // // Initialisierung // restart_hw(); DEBUG_SETUP; // Warten bis Bus stabil, nach Busspannungswiederkehr for (n = 0; n < 50; n++) { TR0 = 0; // Timer 0 anhalten TH0 = eeprom[ADDRTAB + 1]; // Timer 0 setzen mit phys. Adr. damit Geräte unterschiedlich beginnen zu senden TL0 = eeprom[ADDRTAB + 2]; TF0 = 0; // Überlauf-Flag zurücksetzen TR0 = 1; // Timer 0 starten while (!TF0) ; } restart_app(); do { // // Hauptverarbeitung // if (APPLICATION_RUN) { process_inputs(); if (RTCCON >= 0x80) timer_event(); } DEBUG_POINT; // // Empfangenes Telegramm bearbeiten // if (tel_arrived) process_tel(); // // Watchdog rücksetzen // EA = 0; WFEED1 = 0xA5; WFEED2 = 0x5A; EA = 1; // // Abfrage des Programmier-Tasters // TASTER = 1; if (!TASTER) { for (n = 0; n < 100; n++) // Entprellen ; while (!TASTER) // Warten bis Taster losgelassen ; status60 ^= 0x81;// Prog-Bit und Parity-Bit im system_state toggeln } TASTER = !(status60 & 0x01);// LED entsprechend Prog-Bit schalten (low=LED an) } while (1); }