Esempio n. 1
0
/* ----- init_page: initialize postscript page ----- */
void init_page (FILE *fp)
{

  if (vb>=10) printf ("init_page called; in_page=%d\n", in_page);
  if (in_page) return;

  if (!file_initialized) {
    if (vb>=10) printf ("file not yet initialized; do it now\n");
    init_ps (fp,infostr, 0,0.0,0.0,0.0,0.0);
  }
  in_page=1;
  pagenum++;

  if (verbose==0) ;
  else if (verbose==1) printf ("[%d] ", pagenum);
  else if (verbose==2) printf ("[%d] ", pagenum);
  else                 printf ("[%d]\n", pagenum);
  fflush (stdout);
  fprintf (fp, 
           "\n%% --- page %d\n"
           "%%%%Page: %d %d\n"
           "%%%%BeginPageSetup\n",
           pagenum, pagenum, pagenum);

  if (cfmt.landscape) fprintf(fp,"%%%%PageOrientation: Landscape\n");
  fprintf(fp,"gsave ");
  if (cfmt.landscape) fprintf(fp,"90 rotate 0 %.1f translate ", 
                              -cfmt.pageheight);
  fprintf (fp,"%.2f %.2f translate\n", 
           cfmt.leftmargin, cfmt.pageheight-cfmt.topmargin);
  fprintf (fp, "%%%%EndPageSetup\n");


  /* write page number */
  if (pagenumbers) {
    fprintf (fp, "/Times-Roman 12 selectfont ");
    
    /* page numbers always at right */
    fprintf(fp, "%.1f %.1f moveto (%d) /bx false def lshow\n", 
            cfmt.staffwidth, cfmt.topmargin-30.0, pagenum); 

    /* page number right/left for odd/even pages */
/*|      if (pagenum%2==0)   |*/
/*|        fprintf(fp, "%.1f %.1f moveto (%d) show\n",  |*/
/*|                0.0, cfmt.topmargin-30.0, pagenum);  |*/
/*|      else  |*/
/*|        fprintf(fp, "%.1f %.1f moveto (%d) lshow\n",  |*/
/*|                cfmt.staffwidth, cfmt.topmargin-30.0, pagenum);  |*/

  }
  
}
Esempio n. 2
0
int ps_init(char *filename, int color) {
  int i;
  if ((psfile = fopen(filename, "w")) == NULL) {
    err_msg("Cannot open file ");
    return (0);
  }
  init_ps();
  PltFmtFlag = 1;
  PSLines = 0;
  LastPSX = -10000;
  LastPSY = -10000;
  fprintf(psfile, "%%!PS-Adobe-2.0\n");
  fprintf(psfile, "%%Creator: xppaut\n");
  fprintf(psfile, "%%%%BoundingBox: %d %d %d %d\n", PS_XOFF, PS_YOFF,
          (int)(PS_YMAX / PS_SC + .5 + PS_YOFF + 0.1 * PS_VCHAR),
          (int)(PS_XMAX / PS_SC + .5 + PS_XOFF + 0.1 * PS_VCHAR));
  fprintf(psfile, "/xppdict 40 dict def\nxppdict begin\n");
  if (color == 0) {
    fprintf(psfile, "/Color false def \n");
    PSColorFlag = 0;
  } else {
    fprintf(psfile, "/Color true def \n");
    fprintf(psfile, "/RGB {setrgbcolor currentpoint stroke moveto} def\n");
    fprintf(psfile, "/RGb {setrgbcolor } def\n");
    PSColorFlag = 1;
  }
  fprintf(psfile, "/xpplinewidth %.3f def\n", PS_LW);
  fprintf(psfile, "/vshift %d def\n", (int)(PS_VCHAR) / (-3));
  fprintf(psfile, "/dl {%d mul} def\n", PS_SC); /* dash length */
  fprintf(psfile, "/hpt %.1f def\n", PS_HTIC / 2.0);
  fprintf(psfile, "/vpt %.1f def\n", PS_VTIC / 2.0);
  for (i = 0; PS_header[i] != NULL; i++)
    fprintf(psfile, "%s", PS_header[i]);
  fprintf(psfile, "end\n");
  fprintf(psfile, "%%%%EndProlog\n");
  fprintf(psfile, "xppdict begin\n");
  fprintf(psfile, "gsave\n");
  fprintf(psfile, "%d %d translate\n", PS_XOFF, PS_YOFF);
  fprintf(psfile, "%.3f %.3f scale\n", 1. / PS_SC, 1. / PS_SC);
  if (!PS_Port)
    fprintf(psfile, "90 rotate\n0 %d translate\n", -PS_YMAX);
  /* fprintf(psfile,"% 0 setgray\n"); */
  fprintf(psfile, "/%s findfont %d ", PS_FONT, PS_FONTSIZE * PS_SC);
  fprintf(psfile, "scalefont setfont\n");
  fprintf(psfile, "newpath\n");
  return (1);
}
Esempio n. 3
0
int main() {
    cli();

    wdt_disable(); // To make sure nothing weird happens
    init_tlc5940();
    init_spi();
    init_ps();

    init_blank_timer();
    init_effect_timer();

    init_playlist();

    initUSART();
    sei();

    hcsr04_start_continuous_meas();
    adc_start();

    serial_boot_report();

    // Select correct startup mode
    pick_startup_mode();

    while(1) {
        /* Serial processing is implementation specific and defined in
         * serial_common.c */
        process_serial();

        switch (mode) {
        case MODE_SLEEP:
        // Fall through to MODE_IDLE
        case MODE_IDLE:
            // No operation
            sleep_if_no_traffic();
            break;
        case MODE_PLAYLIST:
            ticks = centisecs();
            if (ticks > effect_length) {
                next_effect();
                init_current_effect();
            }

        // no need to break!
        // fall to MODE_EFFECT on purpose
        case MODE_EFFECT:
            // If a buffer is not yet flipped, wait interrupts
            if (flags.may_flip) {
                sleep_if_no_traffic();
                break;
            }

            // Update clock
            ticks = centisecs();

            /* Go back to serial handler if drawing time
             * is reached. By doing this we avoid serial
             * port slowdown when FPS is low */
            if (ticks < next_draw_at ) {
                sleep_if_no_traffic();
                break;
            }

            /* Restart effect if maximum ticks is
             * reached. This may result a glitch but is
             * better than the effect to stop. */
            if (ticks == ~0) {
                init_current_effect();
                ticks = 0;
            }

            // Update sensor values
            sensors.distance1 = hcsr04_get_distance_in_cm();
            sensors.distance2 = hcsr04_get_distance_in_cm(); //TODO: use separate sensor
            sensors.ambient_light = adc_get(0) >> 2;
            sensors.sound_pressure_level = adc_get(1) >> 2;

            // Do the actual drawing
            draw_t draw = (draw_t)pgm_get(effect->draw,word);
            if (draw != NULL) {
                draw();
                allow_flipping(true);
            }

            // Update time when next drawing is allowed
            next_draw_at = ticks + pgm_get(effect->minimum_ticks,byte);

            break;
        }
    }

    return 0;
}
Esempio n. 4
0
int main() {
	cli();

	wdt_disable(); // To make sure nothing weird happens
	init_tlc5940();
	init_spi();
	init_ps();

	init_blank_timer();
	init_effect_timer();
	
	init_playlist();
	
	initUSART();
	sei();

	hcsr04_start_continuous_meas();
	adc_start();

	serial_elo_init();
	
	// Select correct startup mode
	pick_startup_mode();

	while(1) {
		if(serial_available()) {
			uint8_t cmd = serial_read();
#if defined AVR_ZCL
			serial_zcl_process(cmd);
#elif defined AVR_ELO
			serial_elo_process(cmd);
#elif defined SIMU
			// Do nothing
#else
#error Unsupported serial communication type
#endif
		}

		switch (mode) {
		case MODE_SLEEP:
			// Fall through to MODE_IDLE
		case MODE_IDLE:
			// No operation
			sleep_mode();
			break;
		case MODE_PLAYLIST:
			ticks = centisecs();
			if (ticks > effect_length) {
				next_effect();
				init_current_effect();
			}

			// no need to break!
			// fall to MODE_EFFECT on purpose
		case MODE_EFFECT:
			// If a buffer is not yet flipped
			if (flags.may_flip) break;

			// Update clock and sensor values
			ticks = centisecs();
			sensors.distance1 = hcsr04_get_distance_in_cm();
			sensors.distance2 = hcsr04_get_distance_in_cm(); //TODO: use separate sensor
			sensors.ambient_light = adc_get(0) >> 2;
			sensors.sound_pressure_level = adc_get(1) >> 2;

			// Do the actual drawing
			draw_t draw = (draw_t)pgm_get(effect->draw,word);
			if (draw != NULL) {
				draw();
				allow_flipping(true);
			}

			// Slow down drawing if FPS is going to be too high
			uint16_t target_ticks =
				ticks + pgm_get(effect->minimum_ticks,byte);
			while (centisecs() < target_ticks ) {
				sleep_mode();
			}

			break;
		}
	}

	return 0;
}
Esempio n. 5
0
/* -- output a EPS (-E) or SVG (-g) file -- */
void write_eps(void)
{
	unsigned i;
	char *p, title[80];

	if (mbf == outbuf
	 || !info['X' - 'A'])
		return;

	p_fmt = &cfmt;				/* tune format */

	if (epsf != 3) {			/* if not -z */
		strcpy(outfnam, outfn);
		if (outfnam[0] == '\0')
			strcpy(outfnam, OUTPUTFILE);
		cutext(outfnam);
		i = strlen(outfnam) - 1;
		if (i == 0 && outfnam[0] == '-') {
			if (epsf == 1) {
				error(1, NULL, "Cannot use stdout with '-E' - abort");
				exit(EXIT_FAILURE);
			}
			fout = stdout;
		} else {
			if (outfnam[i] == '=') {
				p = &info['T' - 'A']->text[2];
				while (isspace((unsigned char) *p))
					p++;
				strncpy(&outfnam[i], p, sizeof outfnam - i - 4);
				outfnam[sizeof outfnam - 5] = '\0';
				epsf_fn_adj(&outfnam[i]);
			} else {
				if (i >= sizeof outfnam - 4 - 3)
					i = sizeof outfnam - 4 - 3;
				sprintf(&outfnam[i + 1], "%03d", ++nepsf);
			}
			strcat(outfnam, epsf == 1 ? ".eps" : ".svg");
			if ((fout = fopen(outfnam, "w")) == NULL) {
				error(1, NULL, "Cannot open output file %s - abort",
						outfnam);
				exit(EXIT_FAILURE);
			}
		}
	}
	epsf_title(title, sizeof title);
	if (epsf == 1) {
		init_ps(title);
		fprintf(fout, "0.75 dup scale 0 %.1f T\n", -bposy);
		write_buffer();
		fprintf(fout, "showpage\nrestore\n");
	} else {
		if (epsf == 3 && file_initialized == 0)
			fputs("<br/>\n", fout);	/* new image in the same flow */
		init_svg(title);
		write_buffer();
		svg_close();
	}
	if (epsf != 3)
		close_fout();
	else
		file_initialized = 0;
	cur_lmarg = 0;
	cur_scale = 1.0;
}
Esempio n. 6
0
/* the flag 'in_page' is always false and epsf is always null */
static void init_page(void)
{
	float pheight, pwidth;

	p_fmt = !info['X' - 'A'] ? &cfmt : &dfmt;	/* global format */

	nbpages++;
	if (svg) {
		if (file_initialized <= 0) {
			if (!fout)
				open_fout();
			define_svg_symbols(in_fname, nbpages,
				cfmt.landscape ? p_fmt->pageheight : p_fmt->pagewidth,
				cfmt.landscape ? p_fmt->pagewidth : p_fmt->pageheight);
			file_initialized = 1;
			output = svg_output;
		} else {
			define_svg_symbols(in_fname, nbpages,
				cfmt.landscape ? p_fmt->pageheight : p_fmt->pagewidth,
				cfmt.landscape ? p_fmt->pagewidth : p_fmt->pageheight);
		}
		user_ps_write();
	} else if (file_initialized <= 0) {
		init_ps(in_fname);
	}
	in_page = 1;
	outft = -1;

	if (!svg)
		fprintf(fout, "%%%%Page: %d %d\n",
			nbpages, nbpages);
	if (cfmt.landscape) {
		pheight = p_fmt->pagewidth;
		pwidth = cfmt.pageheight;
		if (!svg)
			fprintf(fout, "%%%%PageOrientation: Landscape\n"
				"gsave 0.75 dup scale 90 rotate 0 %.1f T\n",
				-cfmt.topmargin);
	} else {
		pheight = cfmt.pageheight;
		pwidth = p_fmt->pagewidth;
		if (!svg)
			fprintf(fout, "gsave 0.75 dup scale 0 %.1f T\n",
				pheight - cfmt.topmargin);
	}
	if (svg)
		output(fout, "0 %.1f T\n", -cfmt.topmargin);
	else
		output(fout,
			"%% --- width %.1f\n",		/* for index */
			(pwidth - cfmt.leftmargin - cfmt.rightmargin) /
					cfmt.scale);

	remy = maxy = pheight - cfmt.topmargin - cfmt.botmargin;

	/* output the header and footer */
	if (!cfmt.header) {
		char *p = NULL;

		switch (pagenumbers) {
		case 1: p = "$P\t"; break;
		case 2: p = "\t\t$P"; break;
		case 3: p = "$P0\t\t$P1"; break;
		case 4: p = "$P1\t\t$P0"; break;
		}
		if (p)
			cfmt.header = strdup(p);
	}
	if (cfmt.header) {
		float dy;

		dy = headfooter(1, pwidth, pheight);
		if (dy != 0) {
			output(fout, "0 %.1f T\n", -dy);
			remy -= dy;
		}
	}
	if (cfmt.footer)
		remy -= headfooter(0, pwidth, pheight);
	pagenum++;
	outft = -1;
}