コード例 #1
0
ファイル: display_desktop.c プロジェクト: testfarm/testfarm
void display_desktop_remove_frame(int shmid)
{
  display_desktop_t *desktop;
  GtkTreeIter iter;
  frame_hdr_t *frame;

  if ( display_current == NULL )
    return;
  desktop = &(display_current->desktop);

  debug(DEBUG_FRAME, "FRAME REMOVE shmid=%d\n", shmid);

  frame = display_desktop_find_frame(shmid, &iter);
  if ( frame != NULL ) {
    frame_geometry_t g0 = frame->g0;

    display_pattern_remove_frame(display_current_frame);

    display_desktop_remove_children(desktop, &iter);
    gtk_tree_store_remove(GTK_TREE_STORE(display_desktop_model), &iter);
    display_desktop_free_frame(desktop, frame);

    display_desktop_map_layers(desktop);
    display_refresh(display_current, &g0);
    display_selection_show(display_current);
    display_pattern_set_frame(display_current_frame);
    display_screenshot_set_frame(display_current_frame);
  }
  else {
    error("FRAME REMOVE: frame shmid=%d not found in current desktop %s\n", shmid, display_current->desktop.name);
  }
}
コード例 #2
0
/*
 * layout_cipher() - Draws recover cipher
 *
 * INPUT
 *     - current_word: current word that is being typed in at this point in recovery
 *     - cipher: randomized cipher
 * OUTPUT
 *     none
 */
void layout_cipher(const char *current_word, const char *cipher)
{
    DrawableParams sp;
    const Font *title_font = get_body_font();
    Canvas *canvas = layout_get_canvas();

    call_leaving_handler();
    layout_clear();

    /* Draw prompt */
    sp.y = 11;
    sp.x = 4;
    sp.color = BODY_COLOR;
    draw_string(canvas, title_font, "Recovery Cipher:", &sp, 58, font_height(title_font) + 3);

    /* Draw current word */
    sp.y = 46;
    sp.x = 4;
    sp.color = BODY_COLOR;
    draw_string(canvas, title_font, current_word, &sp, 68, font_height(title_font));
    display_refresh();

    /* Animate cipher */
    layout_add_animation(&layout_animate_cipher, (void *)cipher,
                         CIPHER_ANIMATION_FREQUENCY_MS * 30);
}
コード例 #3
0
ファイル: display.c プロジェクト: kusumi/DragonFlyBSD
void
display_clear_the_screen(void)
{
        clear();
        move(0, 0);
        display_refresh();
}
コード例 #4
0
ファイル: spi-master.c プロジェクト: Kvasshtain/uos-embedded
/*
 * Отправка слова по SPI, получение ответа и отображение на дисплее.
 */
void send_receive (unsigned sent)
{
	unsigned received;

	spi_output (&spi, sent);
	spi_input_wait (&spi, (unsigned short *)&received);
	display_refresh (sent, received);
}
コード例 #5
0
/*
 * exec() - Main loop
 *
 * INPUT
 *     none
 * OUTPUT
 *     none
 */
static void exec(void)
{
    usb_poll();

    /* Attempt to animate should a screensaver be present */
    animate();
    display_refresh();
}
コード例 #6
0
void demo_circles() {
    for (int i = 0; i < 100; i += 2) {
        display_clear();
        for (int j = 0; j < 6; j++) {
            display_circle(64 + (i - 50) / 6 - j * (i - 50) / 10, 32 + j,
                    j * 12 + 5);
        }
        display_refresh();
    }
}
コード例 #7
0
ファイル: app_display.c プロジェクト: yangchengxcy/da14580
void app_display_update_temp_type_screen(const char* type_string)
{
    char string[DISPLAY_LINE_SIZE];

    //String creation
    strcpy(string, "s ");
    strcat(string, type_string);

    display_screen_update(app_display_env.screen_id_ht_type, 1, string);
    display_refresh();
}
コード例 #8
0
ファイル: text.c プロジェクト: BatchDrake/biteye
void 
cputs (textarea_t *area, const char *text)
{
  int i;
  
  for (i = 0; i < strlen (text); i++)
    cputchar (area, text[i]);
    
  if (area->autorefresh)
    display_refresh (area->display);
}
コード例 #9
0
// Checker board made by direct manipulation of display ram
void demo_checker_board() {
    // Checker board
    display_clear();
    for (int i = 0; i < 64; i++) {
        for (int j = 0; j < 16; j++) {
            d_buffer[i * 16 + j] = (i & 4) ? 0xf0 : 0x0f;
        }
    }

    display_refresh();
    _delay_ms(1000);
}
コード例 #10
0
ファイル: actions.c プロジェクト: rdebath/sgt
static void act_exit(void) {
    static char question[] = "File is modified. Save before quitting? [yn] ";
    if (modified) {
	int c;

	display_moveto (display_rows-1, 0);
	display_clear_to_eol ();
	display_set_colour (COL_MINIBUF);
	display_write_str (question);
	display_refresh();
	do {
#if defined(unix) && !defined(GO32)
	    if (update_required) {
		update();
		display_moveto (display_rows-1, 0);
		display_clear_to_eol ();
		display_set_colour (COL_MINIBUF);
		display_write_str (question);
		display_refresh();
	    }
	    safe_update = TRUE;
#endif
	    c = display_getkey();
#if defined(unix) && !defined(GO32)
	    safe_update = FALSE;
#endif
	    if (c >= 'a' && c <= 'z')
		c += 'A'-'a';
	} while (c != 'Y' && c != 'N' && c != '\007');
	if (c == 'Y') {
	    act_save();
	    if (modified)
		return;		       /* couldn't save, so don't quit */
	    draw_scr();		       /* update the ** on status line! */
	} else if (c == '\007') {
	    return;		       /* don't even quit */
	}
    }
    finished = TRUE;
}
コード例 #11
0
ファイル: app_display.c プロジェクト: yangchengxcy/da14580
void app_display_set_adv(bool enable)
{
    app_display_env.advertising = enable;
    if (enable)
    {
        display_screen_update(app_display_env.screen_id_adv, 1, "s ON");
    }
    else
    {
        display_screen_update(app_display_env.screen_id_adv, 1, "s OFF");
    }
    display_refresh();
}
コード例 #12
0
ファイル: test-tcp.c プロジェクト: Kvasshtain/uos-embedded
void console_task (void *data)
{
	int c, display_count = 0;
	tcp_socket_t *s;

	for (;;) {
		if (peekchar (&debug) < 0) {
			timer_delay (&timer, 50);
			if (++display_count == 10) {
				display_refresh ();
				display_count = 0;
			}
			continue;
		}
		c = getchar (&debug);
		switch (c) {
		case '\n': case '\r':
			putchar (&debug, '\n');
			printf (&debug, "Transmit: %ld packets, %ld collisions, %ld errors\n",
					eth.netif.out_packets, eth.netif.out_collisions,
					eth.netif.out_errors);
			printf (&debug, "Receive: %ld packets, %ld errors, %ld lost\n",
					eth.netif.in_packets, eth.netif.in_errors,
					eth.netif.in_discards);
			printf (&debug, "Interrupts: %ln\n", eth.intr);
			printf (&debug, "Free memory: %u bytes\n",
				mem_available (&pool));
			k5600bg1_debug (&eth, &debug);
			puts (&debug, "Local address   Port    Peer address    Port    State\n");
			for (s=ip.tcp_sockets; s; s=s->next)
				print_tcp_socket (&debug, s);
			for (s=ip.tcp_closing_sockets; s; s=s->next)
				print_tcp_socket (&debug, s);
			for (s=ip.tcp_listen_sockets; s; s=s->next)
				print_tcp_socket (&debug, s);
			if (user_socket)
				print_socket_data (&debug, user_socket);
			putchar (&debug, '\n');
			break;
		case 't' & 037:
			task_print (&debug, 0);
			task_print (&debug, (task_t*) stack_console);
//			task_print (&debug, (task_t*) stack_poll);
			task_print (&debug, (task_t*) stack_tcp);
			task_print (&debug, (task_t*) eth.stack);
			task_print (&debug, (task_t*) ip.stack);
			putchar (&debug, '\n');
			break;
		}
	}
}
コード例 #13
0
/*
 *  update_fw() - Firmware update mode
 *
 *  INPUT
 *      none
 *  OUTPUT
 *      none
 *
 */
static void update_fw(void)
{
    led_func(CLR_GREEN_LED);

    if(usb_flash_firmware())
    {
        layout_standard_notification("Firmware Update Complete",
                                     "Please disconnect and reconnect.", NOTIFICATION_UNPLUG);
        display_refresh();
    }
    else
    {
        layout_simple_message("Firmware Update Failure, Try Again");
    }
}
コード例 #14
0
// diagonal line down and up
void demo_pixel_set() {
    // Lines with line algorithm
    // diagonal line down and up
    display_clear();
    for (int x = 0; x < 128; x++) {
        if (x < 64) {
            display_set(x, x);
        } else {
            display_set(x, 127 - x);
        }
    }

    display_refresh();
    _delay_ms(1000);
}
コード例 #15
0
ファイル: app_display.c プロジェクト: yangchengxcy/da14580
void app_display_set_con(bool state)
{
    app_display_env.connected = state;

    if (state)
    {
        display_screen_update(app_display_env.screen_id_con, 1, "  ON");
    }
    else
    {
        display_screen_update(app_display_env.screen_id_con, 1, "  OFF");
    }

    display_refresh();
}
コード例 #16
0
ファイル: spi-master.c プロジェクト: Kvasshtain/uos-embedded
void uos_init (void)
{
	buttons_init ();

	/* Use LCD panel for display. */
	extern gpanel_font_t font_fixed6x8;
	gpanel_init (&display, &font_fixed6x8);

	/* SPI2, 16-bit words, master at 1 Mbit/sec. */
	spi_init (&spi, 0, 16, 1000000 / KBIT_PER_SEC, 0);
	display_refresh (~0, ~0);

	task_create (task_console, 0, "console", 10,
		stack_console, sizeof (stack_console));
}
コード例 #17
0
ファイル: player.c プロジェクト: davel/lartem
void player_see()
{
	shadow_scan(0, 1, 1, 0);
	shadow_scan(1, 1, 1, 0);
	shadow_scan(2, 1, 1, 0);
	shadow_scan(3, 1, 1, 0);
	shadow_scan(4, 1, 1, 0);
	shadow_scan(5, 1, 1, 0);
	shadow_scan(6, 1, 1, 0);
	shadow_scan(7, 1, 1, 0);

	/* Finally, draw the player */
	main_plot(player.x, player.y, COL_WHITE, '@');

	display_refresh();
}
コード例 #18
0
// Demo lines to make a moving Qix thing
void demo_lines() {
    int const num = 8;
    int x0s[num], y0s[num], x1s[num], y1s[num];
    int dx0 = -2, dx1 = 3, dy0 = 3, dy1 = 2;

    // init
    for (int t = 0; t < num; t++) {
        x0s[t] = 33;
        x1s[t] = 58;
        y0s[t] = 0;
        y1s[t] = 1;
    }

    // Move the lines aound
    for (int t = 0; t < 250; t++) {
        display_clear();
        // draw each line
        for (uint8_t j = 0; j < num; j++) {
            display_line(x0s[j], y0s[j], x1s[j], y1s[j]);
        }

        // move them down
        for (uint8_t j = num - 1; j >= 1; j--) {
            x0s[j] = x0s[j - 1];
            x1s[j] = x1s[j - 1];
            y0s[j] = y0s[j - 1];
            y1s[j] = y1s[j - 1];
        }

        // calculate next
        x0s[0] += dx0;
        x1s[0] += dx1;
        y0s[0] += dy0;
        y1s[0] += dy1;
#define limit(v, dv, max_v) {\
        if (v < 0) { v = 0; dv = (rand() & 3) + 2; } \
        if (v >= max_v) { v = max_v - 1; dv = -(rand() & 3) - 2; } \
}
        limit(x0s[0], dx0, 128);
        limit(x1s[0], dx1, 128);
        limit(y0s[0], dy0, 64);
        limit(y1s[0], dy1, 64);
#undef limit
        display_refresh();
    }
}
コード例 #19
0
/*
 * layout_pin() - Draws pin matrix
 *
 * INPUT
 *     - str: string prompt to display next to pin matrix
 *     - pin: randomized pin matric
 * OUTPUT
 *     none
 */
void layout_pin(const char *str, char pin[])
{
    DrawableParams sp;
    Canvas *canvas = layout_get_canvas();

    call_leaving_handler();
    layout_clear();

    /* Draw prompt */
    const Font *font = get_body_font();
    sp.y = 29;
    sp.x = (140 - calc_str_width(font, str)) / 2;
    sp.color = BODY_COLOR;
    draw_string(canvas, font, str, &sp, TITLE_WIDTH, font_height(font));
    display_refresh();

    /* Animate pin scrambling */
    layout_add_animation(&layout_animate_pin, (void *)pin, PIN_MAX_ANIMATION_MS);
}
コード例 #20
0
ファイル: finish.c プロジェクト: olegv142/PhotoFinish
__interrupt void watchdog_timer(void)
{
	// Routine maintenance tasks
	int ir_div = ir_divider();
	int r = wc_update(&g_wc);
	if (r && g_state == st_started) {
		display_set_dp(1);
		display_bin(g_wc.d);
		if (r > WC_DIGITS)
			g_timeout = 1;
	}
	display_refresh();
	if (is_calibrating()) {
		P1OUT |= CALIB_LED;
	} else {
		P1OUT &= ~CALIB_LED;
	}
	if (g_no_ir) {
		g_no_ir = 0;
		++g_no_ir_gen;
		if (is_calibrating())
			beep(ir_div * 2);
	}
	if (g_beep) {
		if (g_beep > 0)
			--g_beep;
		P1OUT |= BEEP_BIT;
	} else {
		P1OUT &= ~BEEP_BIT;
	}
	if (ir_div) {
		if (++g_ir_timer >= ir_div) {
			g_ir_timer -= ir_div;
			g_ir_burst = IR_BURST_PULSES * 2;
		}
	}
	__low_power_mode_off_on_exit();
}
コード例 #21
0
ファイル: player.c プロジェクト: davel/lartem
struct coord player_select_square()
{
	struct coord c, dc;
	int k;

	c.x = player.x;
	c.y = player.y;

	do {
		main_move(c.x, c.y);
		display_refresh();

		k = display_getch();

		dc = key_to_direction(k);

		c.x += dc.x;
		c.y += dc.y;

	} while(k != '.');

	return c;
}
コード例 #22
0
ファイル: app_display.c プロジェクト: yangchengxcy/da14580
void app_display_update_temp_val_screen(float value)
{
    char int_part[4];
    char dec_part[4];
    char string[DISPLAY_LINE_SIZE];
    int int_part_int = (int)(app_ht_env.temp_value)/100;
    int dec_part_int = (int)(app_ht_env.temp_value)%100;

    sprintf(int_part, "%d", int_part_int);
    sprintf(dec_part, "%d", dec_part_int);

    //String creation
    strcpy(string, "s ");
    strcat(string, int_part);
    strcat(string, ".");
    if (dec_part_int < 10)
    {
        strcat(string, "0");
    }
    strcat(string, dec_part);

    display_screen_update(app_display_env.screen_id_ht_value, 1, string);
    display_refresh();
}
コード例 #23
0
ファイル: app_display.c プロジェクト: yangchengxcy/da14580
/**
 ****************************************************************************************
 * @brief Handles the 1 second tick (event handler).
 *****************************************************************************************
 */
static void app_display_sec_tick_evt_hdl(void)
{
    char * ptr;
    char line0[DISPLAY_LINE_SIZE];
    char line1[DISPLAY_LINE_SIZE];
    struct rtc_time time;

    // Clear DISPLAY kernel event
    ke_event_clear(KE_EVENT_RTC_1S_TICK);

    // Read current time from RTC
    rtc_get_time(&time);

    // Format the date
    ptr = &line0[0];
    *ptr++ = '<';
    memcpy(ptr, Months[time.tm_mon-1], strlen(Months[time.tm_mon-1]));
    ptr += strlen(Months[time.tm_mon-1]);
    *ptr++ = ' ';
    if(time.tm_mday > 9)
    {
        *ptr++ = 48 + time.tm_mday / 10;
        time.tm_mday = time.tm_mday - (10 * (time.tm_mday / 10));
    }
    *ptr++ = 48 + time.tm_mday;
    *ptr++ = ' ';
    memcpy(ptr, Days[time.tm_wday-1], strlen(Days[time.tm_wday-1]));
    ptr += strlen(Days[time.tm_wday-1]);
    *ptr++ = ' ';
    *ptr++ = '2';
    *ptr++ = '0';
    time.tm_year -= 2000;
    *ptr++ = 48 + time.tm_year / 10;
    time.tm_year = time.tm_year - (10 * (time.tm_year / 10));
    *ptr++ = 48 + time.tm_year;
    *ptr++ = 0;
//    sprintf(line0, "<%s %d %s %d", Months[time.tm_mon-1], time.tm_mday, Days[time.tm_wday-1], time.tm_year);

    // Format the time
    ptr = &line1[0];
    *ptr++ = 48 + time.tm_hour / 10;
    time.tm_hour = time.tm_hour - (10 * (time.tm_hour / 10));
    *ptr++ = 48 + time.tm_hour;
    *ptr++ = ':';
    *ptr++ = 48 + time.tm_min / 10;
    time.tm_min = time.tm_min - (10 * (time.tm_min / 10));
    *ptr++ = 48 + time.tm_min;
    *ptr++ = ':';
    *ptr++ = 48 + time.tm_sec / 10;
    time.tm_sec = time.tm_sec - (10 * (time.tm_sec / 10));
    *ptr++ = 48 + time.tm_sec;
    *ptr++ = 0;
//    sprintf(line1, "%02d:%02d:%02d", time.tm_hour, time.tm_min, time.tm_sec);


    // Update screen content
    display_screen_update(app_display_env.screen_id_rtc, 0, line0);
    display_screen_update(app_display_env.screen_id_rtc, 1, line1);

    // Program a screen refreshment
    display_refresh();
//    display_goto_screen(app_display_env.screen_id_rtc);
}
コード例 #24
0
ファイル: display_pad.c プロジェクト: testfarm/testfarm
static void display_pad_refresh(frame_geometry_t *g)
{
  display_refresh(display_current, g);
  display_pattern_show_selection();
  display_selection_show(display_current);
}
コード例 #25
0
ファイル: display_desktop.c プロジェクト: testfarm/testfarm
static gboolean display_desktop_select(GtkTreeSelection *selection, GtkTreeModel *model,
				       GtkTreePath *path, gboolean path_currently_selected,
				       void *data)
{
  int path_newly_selected = path_currently_selected ? 0:1;
  display_t *d = NULL;
  frame_hdr_t *frame = NULL;
  GtkTreeIter iter;

  if ( path_newly_selected ) {
    if ( gtk_tree_model_get_iter(model, &iter, path) ) {
      gtk_tree_model_get(model, &iter,
			 DESKTOP_TREE_DISPLAY, &d,
			 DESKTOP_TREE_FRAME, &frame,
			 -1);
    }
  }

  /* Manage desktop switch */
  if ( (d != NULL) && (d != display_current) ) {
    display_t *display_previous;

    /* Select new desktop */
    display_previous = display_current;
    display_current = d;
    display_current_iter = iter;

    /* Disconnect previously selected desktop */
    display_disconnect(display_previous);

    debug(DEBUG_FRAME, "SELECT DESKTOP name='%s'\n", d->desktop.name);

    /* Start connection if display is available */
    if ( d->desktop.available ) {
      if ( display_connect(d) )
	display_desktop_available(d, 0);
    }

    /* Show jammed screen if display not available */
    else {
      display_setup(d);
    }
  }

  if ( (frame != NULL) && (frame != display_current_frame) ) {
    display_current_frame = frame;
    display_current_frame_iter = iter;

    debug(DEBUG_FRAME, "SELECT FRAME id='%s'\n", frame->id);

    display_desktop_map_layers(&(display_current->desktop));
    display_refresh(display_current, &(display_current->desktop.root.g0));
    display_selection_show(display_current);
    display_pattern_set_frame(frame);
    display_screenshot_set_frame(frame);

    display_desktop_highlight_frame(frame);
  }

  return TRUE;
}
コード例 #26
0
ファイル: display.c プロジェクト: testfarm/testfarm
static int display_ctl_process(display_t *d)
{
  frame_ctl_rsp *rsp = (frame_ctl_rsp *) d->rsp_buf;
  frame_ctl_hdr *hdr = (frame_ctl_hdr *) d->rsp_buf;
  int ret = 0;

  debug(DEBUG_CTL, "READ PROCESS ctl=%02X\n", hdr->ctl);

  switch ( hdr->ctl ) {
  case FRAME_CTL_INIT:
    if ( display_connected(d, &(rsp->init)) ) {
      display_desktop_available(d, 0);
      ret = 1;
    }
    break;
  case FRAME_CTL_WINDOW:  /* Display active geometry updated */
    d->rgb_window = rsp->window.g;
    display_update(d, NULL);
    display_redraw_all(d);
    display_pattern_show_selection();
    display_selection_show(d);
    break;
  case FRAME_CTL_REFRESH:  /* Display refresh requested */
    {
      /* Paranoia: Reject unacceptable refresh window geometry */
      if ( (rsp->refresh.g.x < d->desktop.root.g0.width) && (rsp->refresh.g.y < d->desktop.root.g0.height) ) {
	/* Paranoia: Clip refresh window geometry into physical display */
	unsigned int max;

	max = d->desktop.root.g0.width - rsp->refresh.g.x;
	if ( rsp->refresh.g.width > max )
	  rsp->refresh.g.width = max;

	max = d->desktop.root.g0.height - rsp->refresh.g.y;
	if ( rsp->refresh.g.height > max )
	  rsp->refresh.g.height = max;

	display_refresh(d, &(rsp->refresh.g));
	display_pattern_show_selection();
	display_selection_show(d);
      }
      else {
        error("Got a Refresh control message with illegal geometry\n");
      }
    }
    break;
  case FRAME_CTL_PATTERN:  /* Pattern declaration added */
    {
      char *id = rsp->pattern.id_source;
      char *source = id + strlen(id) + 1;
      frame_hdr_t *frame = NULL;

      if ( rsp->pattern.shmid > 0 ) {
	frame = display_desktop_get_frame(rsp->pattern.shmid);
	if ( frame == NULL ) {
	  error("Cannot retrieve frame shmid=%d required by pattern %s\n", rsp->pattern.shmid, id);
	}
      }

      display_pattern_update(id, frame, source, &(rsp->pattern.g), rsp->pattern.mode, rsp->pattern.type,
			     rsp->pattern.fuzz, rsp->pattern.loss);
    }
    break;
  case FRAME_CTL_MATCH:  /* Pattern matched */
    {
      char *id = rsp->match.id;
      display_pattern_match(d, id, rsp->match.state);
    }
    break;
  case FRAME_CTL_PERIOD:  /* Refresh period changed */
    {
      display_refresh_updated(rsp->period.period);
    }
    break;
  case FRAME_CTL_SOURCE:  /* Source playback done */
    {
      display_record_stop();
    }
    break;
  case FRAME_CTL_PAD:  /* Show pad list */
    {
      int i;

      for (i = 0; i < rsp->pad.nmemb; i++) {
	display_pad_add(&d->pad, &rsp->pad.gtab[i], display_pad_color);
      }
    }
    break;
  case FRAME_CTL_FRAME:  /* Add frame */
    {
      if ( rsp->frame.parent_shmid >= 0 )
	display_desktop_add_frame(rsp->frame.id, rsp->frame.shmid, &(rsp->frame.g0), rsp->frame.parent_shmid);
      else
	display_desktop_remove_frame(rsp->frame.shmid);
    }
    break;
  case FRAME_CTL_HISTORY:  /* Command history event */
    {
	    display_command_history(rsp->history.id, rsp->history.cmd);
    }
    break;
  }

  return ret;
}
コード例 #27
0
ファイル: display.c プロジェクト: aguido/400plus
void display_message_set(char *message, int timeout) {
	strncpy(display_message, message, LP_MAX_WORD);
	message_timeout = timestamp() + timeout;

	display_refresh();
}
コード例 #28
0
int main(int argc, char *argv[]) {
  key_t shmkey;
  int shmid, shmsize;
  int i, j, k, t = 0, c = 0;
  int pause = PAUSE, again = 1;
  int setupIndex = -1;
  int minSampleIndex = -1, minMessageIndex = -1;
  int maxSampleIndex = -1, maxMessageIndex = -1;
  int minSampleValue = INT_MAX, minMessageValue = INT_MAX;
  int maxSampleValue = INT_MIN, maxMessageValue = INT_MIN;
  int maxCountCleared = 0, countCleared = 0, countLoop = 0;
  int countInvalid = 0, countData = 0, countSetup = 0, countCancel = 0, countUnknown = 0;

  for (i=0; i<MAXNUMTRIGCHAN; i++)
    lastValue[i] = 0;

  /* make the shared memory key
   * if ((shmkey = ftok(ACQ_MSGQ_SHMPATH, ACQ_MSGQ_SHMPROJID)) == -1) {
   *   perror("ftok");
   *   exit(1);
   * }
   */

  /* use the pre-defined shared memory key */
  shmkey = ACQ_MSGQ_SHMKEY;

  /* determine the size of the shared memory buffer */
  shmsize = sizeof(ACQ_MessagePacketType) * ACQ_MSGQ_SIZE;

  /* connect to (and possibly create) the segment */
  if ((shmid = shmget(shmkey, shmsize, PERMISSION | IPC_CREAT )) == -1) {
    perror("shmget");
    exit(1);
  }

  /* attach to the segment to get a pointer to it */
  packet = shmat(shmid, (void *)0, 0);
  if ((char *)packet == (char *)(-1)) {
    perror("shmat");
    exit(1);
  }

  display_start();
  display_print("initializing\n");
  // clear_all_except_setup();
  // clear_all();

  display_refresh();

  while (again) {
    clear();

    setupIndex = -1;
    minSampleIndex = -1, minMessageIndex = -1;
    maxSampleIndex = -1, maxMessageIndex = -1;
    minSampleValue = INT_MAX, minMessageValue = INT_MAX;
    maxSampleValue = INT_MIN, maxMessageValue = INT_MIN;
    countInvalid = 0, countData = 0, countSetup = 0, countCancel = 0, countUnknown = 0;

    /*******************************************************************************
     * collect information about all packets in the buffer
     *******************************************************************************/

    for (i=0; i<ACQ_MSGQ_SIZE; i++) {
      if (i<SHOWPACKET)
        print_packet(i);

      switch (packet[i].message_type) {
        case ACQ_MSGQ_SETUP_COLLECTION:
          if (countSetup>0) {
            /* multiple packets with a setup are not allowed, only keep the first */
            display_print("clearing superfluous setup packet at %d (setup @ %d)\n", i, setupIndex);
            clear_packet(i);
            countCleared++;
            break;
          }
          countSetup++;
          setupIndex = i;
          /* update the specifications that relate to trigger maintenance */
          numRealChan = packet[i].data[DATASIZE-TRIGSIZE*3-MAXNUMTRIGCHAN-2];  /* update the value */
          numTrigChan = packet[i].data[DATASIZE-TRIGSIZE*3-MAXNUMTRIGCHAN-1];  /* update the value */
          trigChan    = packet[i].data+DATASIZE-TRIGSIZE*3-MAXNUMTRIGCHAN;     /* update the pointer */
          trigPointer = packet[i].data+DATASIZE-TRIGSIZE*3;                    /* update the pointer */
          if (numRealChan<0)
            numRealChan = 0;
          if (numTrigChan<0)
            numTrigChan = 0;
          if (numTrigChan>MAXNUMTRIGCHAN) {
            display_print("cannot maintain more than %d trigger channels in real time\n", MAXNUMTRIGCHAN);
            numTrigChan = MAXNUMTRIGCHAN;
          }
          break;

        case ACQ_MSGQ_DATA:
          countData++;
          if (packet[i].sampleNumber<minSampleValue) {
            minSampleIndex = i;
            minSampleValue = packet[i].sampleNumber;
          }
          if (packet[i].sampleNumber>maxSampleValue) {
            maxSampleIndex = i;
            maxSampleValue = packet[i].sampleNumber;
          }
          if (packet[i].messageId<minMessageValue) {
            minMessageIndex = i;
            minMessageValue = packet[i].messageId;
          }
          if (packet[i].messageId>maxMessageValue) {
            maxMessageIndex = i;
            maxMessageValue = packet[i].messageId;
          }
          if ((packet[i].sampleNumber/ packet[i].numSamples)>lastPacket) {
            /* detect the flanks in the trigger channels */
            lastPacket = packet[i].sampleNumber/ packet[i].numSamples;
            for (j=0; j<numTrigChan; j++) {
              if (trigChan[j]>-1 && trigChan[j]<numRealChan)
                for (k=0; k<packet[i].numSamples; k++) {
                  int sample = k*numRealChan + trigChan[j];
                  /* detect changes in the value of the trigger channel */
                  if (packet[i].data[sample]!=lastValue[j]) {
                    lastValue[j] = packet[i].data[sample];
                    if (lastValue[j]) {
                      display_print("trigger detected\n");
                      /* only store it if it is an upgoing flank */
                      trigPointer[numTrigger+0] = trigChan[j];              /* channel number */
                      trigPointer[numTrigger+1] = packet[i].sampleNumber+k; /* sample number  */
                      trigPointer[numTrigger+2] = lastValue[j];             /* sample value   */
                      numTrigger = wrapnumtrigger(numTrigger+3);
                    }
                  }
                }
            }
          }
          break;

        case ACQ_MSGQ_CLOSE_CONNECTION:
          countCancel++;
          break;

        case ACQ_MSGQ_INVALID:
          countInvalid++;
          break;

        default:
          countUnknown++;
          clear_packet(i);
          countCleared++;
          break;

      } /* end switch */
    } /* end for */

    /*******************************************************************************
     * print information about all packets in the buffer
     *******************************************************************************/

    display_print("\n");
    display_print("buffer size  = %d\n", ACQ_MSGQ_SIZE);
    display_print("shm size     = %d\n", shmsize);
    display_print("shm key      = %#x\n", shmkey);
    display_print("pause        = %d\n", pause);
    if (setupIndex>=0)
      display_print("dataset      = %s @ %d\n", (char *)packet[setupIndex].data, setupIndex);
    else
      display_print("dataset      = <unknown>\n");
    display_print("\n");

    display_print("countSetup   = %d\n", countSetup);
    display_print("countData    = %d\n", countData);
    display_print("countCancel  = %d\n", countCancel);
    display_print("countInvalid = %d\n", countInvalid);
    display_print("countUnknown = %d\n", countUnknown);
    display_print("countCleared = %d\n", countCleared);
    display_print("\n");

    /* this might look like a weird location to reinitialize */
    maxCountCleared = (countCleared>maxCountCleared ? countCleared : maxCountCleared);
    countCleared = 0;

    display_print("min(sampleNumber) = %d @ %d\n", minSampleValue, minSampleIndex);
    display_print("max(sampleNumber) = %d @ %d\n", maxSampleValue, maxSampleIndex);
    // display_print("min(messageId)    = %d @ %d\n", minMessageValue, minMessageIndex);
    // display_print("max(messageId)    = %d @ %d\n", maxMessageValue, maxMessageIndex);
    display_print("max(countCleared) = %d\n", maxCountCleared);
    display_print("\n");

    if (maxSampleIndex>=0)
      display_print("current trial = %d @ %d\n", maxSampleValue/packet[maxSampleIndex].numSamples, maxSampleIndex);
    else
      display_print("current trial = <unknown>\n");
    display_print("\n");

    display_print("numRealChan  = %d\n", numRealChan);
    display_print("numTrigChan  = %d\n", numTrigChan);
    display_print("numTrigger   = %d\n", numTrigger/3);
    display_print("lastPacket   = %d\n", lastPacket);
    display_print("trigChan     = ");
    for (i=0; i<numTrigChan; i++)
      display_print("%d\t", trigChan[i]);
    display_print("\n");
    display_print("lastValue    = ");
    for (i=0; i<numTrigChan; i++)
      display_print("%d\t", lastValue[i]);
    display_print("\n");
    display_print("\n");

    display_refresh();

    /*******************************************************************************
     * do the desired maintenance on the packet buffer (only if a key was pressed)
     *******************************************************************************/

    k = getch();
    switch (k) {
    case 's':
      write_setup(0);
      break;

    case 'p':
      pause = PAUSE;
      break;

    case 'f':
      while (countInvalid && packet[t].message_type!=ACQ_MSGQ_INVALID)
        t = wrapnumpacket(t+1);
      while (packet[t].message_type==ACQ_MSGQ_INVALID) {
        write_data(t, c);
        t = wrapnumpacket(t+1);
        c++;
      }
      break;

    case 'd':
      while (countInvalid && packet[t].message_type!=ACQ_MSGQ_INVALID)
        t = wrapnumpacket(t+1);
      write_data(t, c);
      t = wrapnumpacket(t+1);
      c++;
      break;

    case 'c':
      maxCountCleared = 0;
      clear_all_except_setup();
      break;

    case 'h':
      showDisplay = (!showDisplay);
      break;

    case 'x':
      maxCountCleared = 0;
      clear_all();
      break;

    case 'q':
      again = 0;
      break;
    }
 
    if (k!=ERR) {
      display_print("key pressed = %d\n", k);
      display_refresh();
      continue;
    }

    /*******************************************************************************
     * do the regular maintenance on the packet buffer
     *******************************************************************************/

    if (countCancel) {
      display_print("initializing all packets\n");
      clear_all();
      countInvalid = ACQ_MSGQ_SIZE;
      countData    = 0;
      countSetup   = 0;
      countCancel  = 0;
    }

    // if ((MINFREE-countInvalid)>1 && pause) {
    //   pause/=(MINFREE-countInvalid);
    //   display_print("decreasing pause to %d\n", pause);
    // }

    while (countInvalid<MINFREE && countData)
      /* make more empty packets available */
      if (setupIndex>-1) {
        /* moving the setup one packet at a time may look inefficient, but this only happens at the start of online acquisition */
        display_print("moving setup from %d to %d\n", setupIndex, minSampleIndex);
        memcpy(&packet[minSampleIndex], &packet[setupIndex], sizeof(ACQ_MessagePacketType));
        countCleared++;
        countInvalid++;
        countData--;
        // NOTE: don't clear the packet, since Matlab might be reading from it
        // display_print("clearing packet %d\n", setupIndex);
        // clear_packet(setupIndex);
        packet[setupIndex].message_type = ACQ_MSGQ_INVALID;
        setupIndex     = minSampleIndex;
        minSampleIndex = wrapnumpacket(minSampleIndex+1); /* the next is probably now the oldest */
      }
      else {
        display_print("clearing packet %d\n", minSampleIndex);
        clear_packet(minSampleIndex);
        countCleared++;
        countInvalid++;
        countData--;
        minSampleIndex = wrapnumpacket(minSampleIndex+1); /* the next is probably now the oldest */
      }

    while (setupIndex>-1 && countData && packet[wrapnumpacket(setupIndex+1)].message_type==ACQ_MSGQ_INVALID) {
      /* move the setup to the next empty packet */
      /* moving the setup one packet at a time may look inefficient, but this only happens at the start of online acquisition */
      display_print("moving setup from %d to %d\n", setupIndex, wrapnumpacket(setupIndex+1));
      memcpy(&packet[wrapnumpacket(setupIndex+1)], &packet[setupIndex], sizeof(ACQ_MessagePacketType));
      // NOTE: don't clear the packet, since Matlab might be reading from it
      // clear_packet(setupIndex);
      packet[setupIndex].message_type = ACQ_MSGQ_INVALID;
      countCleared++;
      setupIndex = wrapnumpacket(setupIndex+1);
    }

    display_refresh();
    usleep(pause);

    if (countInvalid>4)
      printf("ok %d\n", countLoop);
    else
      printf("error %d\n", countLoop);
    countLoop++;
  }

  /* detach from the shared memory segment */
  if (shmdt(packet) == -1) {
    perror("shmdt");
    exit(1);
  }

  /* end curses mode */
  display_stop();
  
  /* end of program */
  return 0;
}
コード例 #29
0
ファイル: chopstix.c プロジェクト: WrathOfChris/chopstix
int
main(int argc, char **argv)
{
	int ch;
	const char *conffile;

	conffile = CONFFILE;

	while ((ch = getopt(argc, argv, "f:v")) != -1) {
		switch (ch) {
			case 'f':
				conffile = optarg;
				break;
			case 'v':
				verbose++;
				break;
			default:
				usage();
				/* NOTREACHED */
		}
	}

	bzero(&config, sizeof(config));
	config.print.feedlines = -1;
	config.print.cchide_customer = 1;
	config.print.ccsig_customer = 1;
	bzero(&header, sizeof(header));
	if (parse_config(conffile))
		exit(1);

	/* set database files */
	if (config.database.custdb == NULL)
		if ((config.database.custdb = strdup(config.database.alldb
				? config.database.alldb : CUSTDBFILE)) == NULL)
			err(1, "cannot set customer database file");
	if (config.database.menudb == NULL)
		if ((config.database.menudb = strdup(config.database.alldb
				? config.database.alldb : MENUDBFILE)) == NULL)
			err(1, "cannot set menu database file");
	if (config.database.orderdb == NULL)
		if ((config.database.orderdb = strdup(config.database.alldb
				? config.database.alldb : ORDERDBFILE)) == NULL)
			err(1, "cannot set order database file");
	if (config.print.feedlines < 0)
		config.print.feedlines = PRINT_FEED_LINES;

	if (licence_init() == -1)
		errx(1, "cannot proceed without licence");

	event_init();

	module_init();
	rule_init();

	input_init();
	print_init();
	form_init();
	display_init();
	status_init();
	menu_init();
	customer_init();
	special_init();
	payment_init();
	window_init();
	order_init();

	display_refresh();

	signal(SIGPIPE, SIG_IGN);
	if (event_dispatch() == -1)
		err(1, "terminated abnormally");

	if (exitcode != 0 && exitmsg == NULL)
		exitmsg = strdup(status.status);

	order_exit();
	window_exit();
	payment_exit();
	special_exit();
	customer_exit();
	menu_exit();
	status_exit();
	display_exit();
	form_exit();
	print_exit();
	input_exit();

	rule_exit();
	module_exit();

	if (exitcode && exitmsg != NULL)
		errx(exitcode, "%s", exitmsg);
	else
		fprintf(stdout, "exiting normally\n");

	exit(0);
}