Esempio n. 1
0
void display_cmd(const char *cmd, int cl, int cursor_pos)
{
	cmd_len = cl;
	if (cursor_pos == -1 || cursor_pos > cmd_len)
		cursor_pos = cmd_len;
	cmd_cursor_pos = cursor_pos;
	cmd_cmd = cmd;

	display_lock();
	werase(win_cmd);
	if (cursor_pos < cmd_len) {
		waddnstr(win_cmd, cmd, cursor_pos);
		wbkgdset(win_cmd, COLOR_PAIR(YELLOW_ON_BLACK));
		waddnstr(win_cmd, cmd + cursor_pos, 1);
		wbkgdset(win_cmd, COLOR_PAIR(BLACK_ON_YELLOW));
		waddnstr(win_cmd, cmd + cursor_pos + 1, cmd_len - (cursor_pos + 1));
	}
	else {
		waddnstr(win_cmd, cmd, cmd_len);
		wmove(win_cmd, cursor_pos, 0);
		wbkgdset(win_cmd, COLOR_PAIR(YELLOW_ON_BLACK));
		waddstr(win_cmd, " ");
		wbkgdset(win_cmd, COLOR_PAIR(BLACK_ON_YELLOW));
	}

	wattroff(win_stat, A_UNDERLINE);
	wrefresh(win_cmd);
	display_unlock();
}
Esempio n. 2
0
void display_print_page(void)
{
	int n_lines = 0;
	int cur_idx_prev = cur_idx;

	if (cur_idx >= (int)pages_len) {
		return;
	}

	display_lock();
	for (size_t i = cur_idx; i < pages_len; ++i) {
		if (pages[i] == '\n') {
			n_lines++;
			if (n_lines == win_txt_height - 2) {
				pages[i] = 0;
				cur_idx = i + 1;
				break;
			}
		}
	}

	waddstr(win_txt, pages + cur_idx_prev);
	if (cur_idx != cur_idx_prev && cur_idx < (int)pages_len)
		waddstr(win_txt, "\nPRESS ENTER FOR MORE...\n");
	else {
		pages_len = 0;
	}
	wrefresh(win_txt);
	display_unlock();
}
Esempio n. 3
0
void display_stats(void)
{
	display_lock();
	current_screen->draw_stats(&screen_state);
	display_stats_general();
	wrefresh(win_stat);
	display_unlock();
}
Esempio n. 4
0
int display_getch(void)
{
	int ret;

	display_lock();
	ret = wgetch(scr);
	display_unlock();

	return ret;
}
Esempio n. 5
0
static void stats_display_layout(uint8_t in_place)
{
	uint8_t cur_stats_height;

	cur_stats_height = current_screen->get_height();
	cur_stats_height = cur_stats_height > max_n_lines? max_n_lines: cur_stats_height;

	display_lock();
	if (!in_place) {
		// moving existing windows does not work
		delwin(win_txt);
		delwin(win_general);
		delwin(win_title);
		delwin(win_tabs);
		delwin(win_cmd);
		delwin(win_txt);
		delwin(win_help);

		clear();
	}

	if (!in_place) {
		win_stat = create_subwindow(cur_stats_height + 2, 0, 4, 0);
		win_tabs = create_subwindow(1, 0, 1, 0);
		win_general = create_subwindow(2, 0, 2, 0);
		win_title = create_subwindow(1, 0, 0, 0);
		win_cmd = create_subwindow(1, 0, cur_stats_height + 2 + 4,  0);
		win_txt_height = LINES - cur_stats_height - 2 - 3 - 3;
		win_txt = create_subwindow(win_txt_height, 0, cur_stats_height + 4 + 3, 0);
		win_help = create_subwindow(1, 0, LINES - 1, 0);
	}

	draw_title();
	draw_general_frame();
	/* Command line */
	wbkgd(win_cmd, COLOR_PAIR(BLACK_ON_YELLOW));
	idlok(win_cmd, FALSE);
	/* Move cursor at insertion point */
	leaveok(win_cmd, FALSE);

	draw_status_bar();
	draw_log_window();

	/* Draw everything to the screen */
	refresh();
	current_screen->draw_frame(&screen_state);
	display_unlock();

	refresh_cmd_win();
	display_stats();
}
Esempio n. 6
0
void display_print(const char *str)
{
	display_lock();

	if (scr == NULL) {
		fputs(str, stdout);
		fflush(stdout);
		display_unlock();
		return;
	}

	/* Check if the whole string can fit on the screen. */
	pages_len = strlen(str);
	int n_lines = 0;
	memset(pages, 0, sizeof(pages));
	memcpy(pages, str, pages_len);
	cur_idx = 0;
	for (size_t i = 0; i < pages_len; ++i) {
		if (pages[i] == '\n') {
			n_lines++;
			if (n_lines == win_txt_height - 2) {
				pages[i] = 0;
				cur_idx = i + 1;
				break;
			}
		}
	}

	waddstr(win_txt, pages);
	if (cur_idx != 0)
		waddstr(win_txt, "\nPRESS ENTER FOR MORE...\n");
	else
		pages_len = 0;

	wrefresh(win_txt);
	display_unlock();
}
Esempio n. 7
0
int main (int argc, char **argv)
{
	SADisplay *display;
	VisVideo *video;

	VisInput *input;
	VisActor *actor;
	VisEventQueue *localqueue;
	VisVideoAttributeOptions *vidoptions;

	int running = TRUE;
	int fullscreen = FALSE;
	int visible = TRUE;

	int depth;

	//visual_mem_alloc_install_vtable (visual_mem_alloc_vtable_profile ());

	visual_init (&argc, &argv);

	display = display_new (sdl_driver_new ());

	/* Libvisual stuff */
	if (argc > 1)
		actor = visual_actor_new (argv[1]);
	else
		actor = visual_actor_new ("projectM");


	if (argc > 3) {
		depth = visual_video_depth_enum_from_value (atoi (argv[3]));
	} else
		depth = visual_video_depth_get_highest (visual_actor_get_supported_depth (actor));

	vidoptions = visual_actor_get_video_attribute_options (actor);

	display_create (display, depth, vidoptions, 480, 360, TRUE);

	visual_actor_realize (actor);

	video = display_get_video (display);

        visual_actor_set_video (actor, video);
	visual_actor_video_negotiate (actor, 0, FALSE, FALSE);

	if (argc > 2)
		input = visual_input_new (argv[2]);
	else
		input = visual_input_new ("alsa");

	visual_input_realize (input);

	localqueue = visual_event_queue_new ();

	while (running) {
		VisEventQueue *pluginqueue;
		VisEvent *ev;

		/* Handle all events */
		display_drain_events (display, localqueue);

		pluginqueue = visual_plugin_get_eventqueue (visual_actor_get_plugin (actor));
		while (visual_event_queue_poll_by_reference (localqueue, &ev)) {

			if (ev->type != VISUAL_EVENT_RESIZE)
				visual_event_queue_add (pluginqueue, ev);

			switch (ev->type) {
				case VISUAL_EVENT_RESIZE:
					video = display_get_video (display);
					visual_actor_set_video (actor, video);

					visual_actor_video_negotiate (actor, depth, FALSE, FALSE);
					break;

				case VISUAL_EVENT_MOUSEMOTION:
					break;

				case VISUAL_EVENT_MOUSEBUTTONDOWN:

					break;

				case VISUAL_EVENT_MOUSEBUTTONUP:
					break;

				case VISUAL_EVENT_KEYDOWN:
					switch (ev->event.keyboard.keysym.sym) {
						case VKEY_ESCAPE:
							running = FALSE;
							break;

						case VKEY_TAB:
							fullscreen = !fullscreen;

							display_set_fullscreen (display, fullscreen, TRUE);

							/* Resync video */
							video = display_get_video (display);
							visual_actor_set_video (actor, video);

							visual_actor_video_negotiate (actor, depth, FALSE, FALSE);

							break;

						default:
							printf ("key: %c\n", ev->event.keyboard.keysym.sym);
							break;
					}

					break;

				case VISUAL_EVENT_KEYUP:
					break;

				case VISUAL_EVENT_QUIT:
					running = FALSE;
					break;

				case VISUAL_EVENT_VISIBILITY:
					visible = ev->event.visibility.is_visible;
					break;

				default:
					break;
			}
		}

		if (visible == FALSE) {
			visual_input_run (input);

			visual_time_usleep (10000);

			continue;
		}

		/* Do a run cycle */
		visual_input_run (input);

		display_lock (display);
		visual_actor_run (actor, input->audio);
		display_unlock (display);

		display_update_all (display);

		display_fps_limit (display, 30);
	}

	/* Termination procedure */
	display_set_fullscreen (display, FALSE, TRUE);
	display_close (display);

	visual_quit ();

	//visual_mem_alloc_profile ();

	printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display));

	return 0;
}
Esempio n. 8
0
static void
game_update_full (bool wait)
{
  const int max_fps = 16;
  const int32_t frame_duration = 1000 / max_fps;

  static int32_t last_frame_ticks;
  int32_t start_ticks;

  display_unlock ();

  sound_update ();
  display_update ();
  game_handle_sdl_events ();

  start_ticks = SDL_GetTicks ();

  if (wait && last_frame_ticks != 0)
    {
      int32_t last_frame_duration;

      last_frame_duration = (int32_t) (start_ticks - last_frame_ticks + 2);

      if (last_frame_duration < frame_duration)
	{
	  int32_t total_sleep_time = frame_duration - last_frame_duration;
	  const int32_t min_sleep_time = 1000 / 40;
	  const int32_t max_sleep_time = 1000 / 20;

	  total_sleep_time = frame_duration - last_frame_duration;

	  if (total_sleep_time > 0)
	    {
	      float f = (float) total_sleep_time
			* (min_sleep_time + max_sleep_time)
			/ (2 * min_sleep_time * max_sleep_time);
	      int32_t base_sleep_time = (int32_t) (total_sleep_time / f + .5f);

	      while (total_sleep_time > 0)
		{
		  int32_t sleep_time = MIN (base_sleep_time, total_sleep_time);
		  int32_t ticks = SDL_GetTicks ();

		  SDL_Delay (sleep_time);

		  display_lock ();
		  game_handle_sdl_events ();
		  sound_update ();
		  display_unlock ();

		  display_update_mouse_pointer ();

		  total_sleep_time -= SDL_GetTicks () - ticks;
		}
	    }
	}
    }

  last_frame_ticks = SDL_GetTicks ();

  display_lock ();
}
Esempio n. 9
0
File: io.c Progetto: Fornax/RS485
void io_loop() {
	
	//Button decrement
	if ( BTN_DEC == 1u && old_btn_dec == 0u && cnt_dec == 0u ) {
		cnt_dec= 100;
		old_btn_dec= 1u;
		display_on(); //Show current address
	} else 	if ( BTN_DEC == 0u && old_btn_dec == 1u && cnt_dec == 0u ) {
		cnt_dec= 100;
		old_btn_dec= 0u;
		delay_unlock= 0u; //Reset unlocking time
		
		if (old_btn_inc == 0u) {
			if (!btn_ignore) {
				display_dec();
			}
			btn_ignore= 0u;
		} else {
			btn_ignore= 1u;
		}
	}
	//Button increment
	if ( BTN_INC == 1u && old_btn_inc == 0u && cnt_inc == 0u ) {
		cnt_inc= 100;
		old_btn_inc= 1u;
		display_on(); //Show current address
	} else if ( BTN_INC == 0u && old_btn_inc == 1u && cnt_inc == 0u ) {
		cnt_inc= 100;
		old_btn_inc= 0u;
		delay_unlock= 0u; //Reset unlocking time
		
		if (old_btn_dec == 0u) {
			if (!btn_ignore) {
				display_inc();
			}
			btn_ignore= 0u;
		} else {
			btn_ignore= 1u;
		}
	}
	
	//Input buttons
	if ( buttons_input == 0u && (INPUT1 == 0u && INPUT2 == 0u) && cnt_input == 0u ) {
		cnt_input= 100;
		buttons_input= 1u;
	} else if (buttons_input == 1u && (INPUT1 != 0u || INPUT2 != 0u) && cnt_input == 0u ) {
		cnt_input= 100;
		buttons_input= 0u;
		if (INPUT1&0x01) {inputs=9;}
		if (INPUT1&0x02) {inputs=8;}
		if (INPUT1&0x04) {inputs=7;}
		if (INPUT1&0x08) {inputs=6;}
		if (INPUT1&0x10) {inputs=5;}
		if (INPUT1&0x20) {inputs=4;}
		if (INPUT2&0x01) {inputs=3;}
		if (INPUT2&0x02) {inputs=2;}
		if (INPUT2&0x04) {inputs=1;}
	}
	//Input capture
	if ( CAPT1 == 1u && capt1 == 0u && cnt_capt == 0u ) {
		cnt_capt= 100;
		capt1= 1;
	} else if ( CAPT1 == 0u && capt1 == 1u && cnt_capt == 0u ) {
		cnt_capt= 100;
		capt1= 0;
		puls_counter++;
	}
	//both switches pressed
	if ( BTN_INC != 0u && BTN_DEC != 0u ) {
		if (cnt_dec == 0u && cnt_inc == 0u && delay_unlock == 0u) {
			delay_unlock= 2000;
		}
		
		//Unlock up/down counting.
		if (cnt_dec == 0u && cnt_inc == 0u && delay_unlock <= 200u) {
			display_unlock();
		}
	}
	
	//Display on
	if ( BTN_INC != 0u || BTN_DEC != 0u) {
		delay_off= 3000;
	}
	
	//Display off
	if ( delay_off == 0u ) {
		display_lock();
	}
}