Esempio n. 1
0
static void ps_rect(double x, double y, double wid, double len) {
  float x1, y1, x2, y2;
  ps_convert(x, y, &x1, &y1);
  ps_convert(x + wid, y + len, &x2, &y2);
  fprintf(my_plot_file,
          "%d %d m \n %d %d l \n %d %d l \n %d %d l \n %d %d l \n S \n",
          (int)x1, (int)y1, (int)x2, (int)y1, (int)x2, (int)y2, (int)x1,
          (int)y2, (int)x1, (int)y1);
}
Esempio n. 2
0
static void ps_bar(double x, double y, double wid, double len, double fill,
                   int flag) {
  float x1, y1, x2, y2;
  fprintf(my_plot_file, "%f G\n", fill);
  ps_convert(x, y, &x1, &y1);
  ps_convert(x + wid, y + len, &x2, &y2);
  fprintf(my_plot_file, "%d %d m \n %d %d l \n %d %d l \n %d %d l \n FS\n",
          (int)x1, (int)y1, (int)x2, (int)y1, (int)x2, (int)y2, (int)x1,
          (int)y2);

  if (flag) {
    fprintf(my_plot_file, "0 G\n");
    ps_rect(x, y, wid, len);
  }
}
Esempio n. 3
0
static void ps_text2(char *str, double xr, double yr, int icent) {
  double slant = .0174532 * ps_scale.slant;
  float x, y;
  float sizex = ps_scale.tx, sizey = ps_scale.ty, rot = ps_scale.angle;
  double a = sizex * cos(slant), b = sizey * sin(slant),
         c = -sizex * sin(slant), d = sizey * cos(slant);
  ps_convert(xr, yr, &x, &y);
  fprintf(my_plot_file, "%d %d m\n", (int)x, (int)y);
  fprintf(my_plot_file, "gsave \n %f rotate \n", rot);
  fprintf(my_plot_file, "basefont [%.4f %.4f %.4f %.4f 0 0] makefont setfont\n",
          a, b, c, d);
  switch (icent) {
  case 0:
    fprintf(my_plot_file, "( %s ) show \n grestore\n", str);
    break;
  case 1: /* centered */
    fprintf(my_plot_file,
            "(%s) dup stringwidth pop -2 div 0 rmoveto show \n grestore\n",
            str);
    break;
  case 2: /* left edge */
    fprintf(my_plot_file,
            "(%s) dup stringwidth pop neg 0 rmoveto show \n grestore\n", str);
    break;
  case 3: /* right edge */
    fprintf(my_plot_file,
            "(%s) dup stringwidth pop  0 rmoveto show \n grestore\n", str);
    break;
  }
}
Esempio n. 4
0
static void ps_begin(double xlo, double ylo, double xhi, double yhi, double sx,
                     double sy) {
  float x0, y0, x1, y1;
  ps_scale.xmin = xlo;
  ps_scale.ymin = ylo;
  ps_scale.ymax = yhi;
  ps_scale.xmax = xhi;
  ps_scale.xoff = 300;
  ps_scale.yoff = 300;
  ps_scale.angle = -90.;
  ps_scale.xscale = 1800. * sx * .2 / (xhi - xlo);
  ps_scale.yscale = 1800. * sy * .2 / (yhi - ylo);

  ps_set_text(-90., 0.0, 18.0, 18.0);
  ps_scale.letx = ps_scale.tx / ps_scale.xscale;
  ps_scale.lety = ps_scale.ty / ps_scale.yscale;
  ps_convert(xlo, ylo, &x0, &y0);
  ps_convert(xhi, yhi, &x1, &y1);
  fprintf(my_plot_file, "%s\n", "%!");
  fprintf(my_plot_file, "%s %g %g %g %g\n", "%%BoundingBox: ", .2 * x0, .2 * y0,
          .2 * x1, .2 * y1);
  fprintf(my_plot_file, "20 dict begin\n");
  fprintf(my_plot_file, "gsave\n");
  fprintf(my_plot_file, "/m {moveto} def\n");
  fprintf(my_plot_file, "/l {lineto} def\n");
  fprintf(my_plot_file, "/Cshow { currentpoint stroke moveto\n");
  fprintf(my_plot_file,
          "  dup stringwidth pop -2 div vshift rmoveto show } def\n");
  fprintf(my_plot_file, "/Lshow { currentpoint stroke moveto\n");
  fprintf(my_plot_file, "  0 vshift rmoveto show } def\n");
  fprintf(my_plot_file, "/Rshow { currentpoint stroke moveto\n");
  fprintf(my_plot_file,
          "  dup stringwidth pop neg vshift rmoveto show } def\n");
  fprintf(my_plot_file, "/C {setrgbcolor} def\n");
  fprintf(my_plot_file, "/G {setgray} def\n");
  fprintf(my_plot_file, "/S {stroke} def\n");
  fprintf(my_plot_file, "/HSB {sethsbcolor} def\n");
  fprintf(my_plot_file, "/RGB {setrgbcolor} def\n");
  fprintf(my_plot_file, "/FS {fill stroke} def\n");
  fprintf(my_plot_file, "630 -20 translate\n");
  fprintf(my_plot_file, "90 rotate\n");
  fprintf(my_plot_file, ".2 .2 scale\n");
  fprintf(my_plot_file, "/basefont /Times-Roman findfont def\n");
  ps_setline(0.0, 4);
}
Esempio n. 5
0
static void ps_rgb_bar(double x, double y, double wid, double len, double fill,
                       int flag, int rgb) {
  float x1, y1, x2, y2;
  float r = 0.0, g = 0.0, b = 0.0;
  if (rgb == 2) {
    ps_hsb_bar(x, y, wid, len, fill, flag);
    return;
  }
  if (fill < 0.0)
    fill = 0.0;
  if (fill > 1.0)
    fill = 1.0;
  switch (rgb) {
  case REDBLUE:
    fill = 1. - fill;
    b = (float)sqrt((double)(1.0 - fill * fill));
    r = (float)sqrt((double)(fill * (2.0 - fill)));
    break;
  case ROYGBIV:
    if (fill > .4999)
      r = 0.0;
    else
      r = (float)sqrt((float)(1. - 4 * fill * fill));
    g = (float)2 * sqrt((double)fill * (1. - fill));

    if (fill < .5001)
      b = 0.0;
    else
      b = (float)sqrt((float)(4 * (fill - .5) * (1.5 - fill)));
    break;
  }
  fprintf(my_plot_file, "%f %f %f RGB\n", r, g, b);
  ps_convert(x, y, &x1, &y1);
  ps_convert(x + wid, y + len, &x2, &y2);
  /*   fprintf(my_plot_file,"%f %f m \n %f %f l \n %f %f l \n %f %f l \n FS\n",
             x1,y1,x2,y1,x2,y2,x1,y2); */
  fprintf(my_plot_file, "%d %d m \n %d %d l \n %d %d l \n %d %d l \n FS\n",
          (int)x1, (int)y1, (int)x2, (int)y1, (int)x2, (int)y2, (int)x1,
          (int)y2);
  if (flag) {
    fprintf(my_plot_file, "0 G\n");
    ps_rect(x, y, wid, len);
  }
}
Esempio n. 6
0
 static void read(MY_HONEYWELL *data, uint8_t sensor) {
   selectSensor(sensor); //select to talk to the desired sensor
   /*uint8_t val[4] = {0};  //four bytes to store sensor data
     Wire.requestFrom(SSC_ADDR, (uint8_t) 4);    //request sensor data
     for (uint8_t i = 0; i <= 3; i++) {
       delay(4);                        // sensor might be missing, do not block by using Wire.available()
       val[i] = Wire.read();
     }
     Serial.println("Data Received");*/
   struct cs_raw ps;
   char p_str[10], t_str[10];
   uint8_t el;
   float p, t;
   el = ps_get_raw(SSC_ADDR, &ps);
   // for some reason my chip triggers a diagnostic fault
   // on 50% of powerups without a notable impact
   // to the output values.
   if ( el == 4 ) {
     Serial.println("err sensor missing");
   } else {
     if ( el == 3 ) {
       Serial.print("err diagnostic fault ");
       Serial.println(ps.status, BIN);
     }
     if ( el == 2 ) {
       // if data has already been feched since the last
       // measurement cycle
       Serial.print("warn stale data ");
       Serial.println(ps.status, BIN);
     }
     if ( el == 1 ) {
       // chip in command mode
       // no clue how to end up here
       Serial.print("warn command mode ");
       Serial.println(ps.status, BIN);
     }
     //Serial.print("status      ");
     //Serial.println(ps.status, BIN);
     //Serial.print("bridge_data ");
     //Serial.println(ps.bridge_data, DEC);
     //Serial.print("temp_data   ");
     //Serial.println(ps.temperature_data, DEC);
     //Serial.println("");
     ps_convert(ps, &p, &t, SSC_MIN, SSC_MAX, PRESSURE_MIN,
                PRESSURE_MAX);
     // floats cannot be easily printed out
     dtostrf(p, 2, 2, p_str);
     dtostrf(t, 2, 2, t_str);
     Serial.print("pressure    (Pa) ");
     Serial.println(p_str);
     Serial.print("temperature (dC) ");
     Serial.println(t_str);
     //Serial.println("");
     data->status=ps.status;
     data->rawPressure=ps.bridge_data;
     data->rawTemperature=ps.temperature_data;
     data->pressure = p;
     data->temperature = t;
     /*data->status = (val[0] & 0xc0) >> 6; // first 2 bits from first byte are the status
     data->rawPressure = ((val[0] & 0x3f) << 8) + val[1];
     data->rawTemperature = ((val[2] << 8) + (val[3] & 0xe0)) >> 5;
     if (data->rawTemperature == 65535)
       data->status = 4;
     if (data->status == 4) {
       data->pressure = -1;
       data->temperature = -1;
     }
     else {
       data->pressure = 1.0 * (data->rawPressure - SSC_MIN) * (PRESSURE_MAX - PRESSURE_MIN) / (SSC_MAX - SSC_MIN) + PRESSURE_MIN;
       data->temperature = (data->rawTemperature * 0.0977) - 50;
     }*/
   }
   return;
 }