Exemple #1
0
      float Bed_level::bed_level_virt_coord(const uint8_t x, const uint8_t y) {
        uint8_t ep = 0, ip = 1;

        if (!x || x == ABL_TEMP_POINTS_X - 1) {
          if (x) {
            ep = GRID_MAX_POINTS_X - 1;
            ip = GRID_MAX_POINTS_X - 2;
          }
          if (WITHIN(y, 1, ABL_TEMP_POINTS_Y - 2))
            return LINEAR_EXTRAPOLATION(z_values[ep][y - 1], z_values[ip][y - 1]);
          else
            return LINEAR_EXTRAPOLATION(bed_level_virt_coord(ep + 1, y), bed_level_virt_coord(ip + 1, y));
        }
        if (!y || y == ABL_TEMP_POINTS_Y - 1) {
          if (y) {
            ep = GRID_MAX_POINTS_Y - 1;
            ip = GRID_MAX_POINTS_Y - 2;
          }
          if (WITHIN(x, 1, ABL_TEMP_POINTS_X - 2))
            return LINEAR_EXTRAPOLATION(z_values[x - 1][ep], z_values[x - 1][ip]);
          else
            return LINEAR_EXTRAPOLATION(bed_level_virt_coord(x, ep + 1), bed_level_virt_coord(x, ip + 1));
        }
        return z_values[x - 1][y - 1];
      }
Exemple #2
0
Fichier : line.c Projet : kahrs/cda
selbox(Line *l,Rectangle r)
{
	int m;
	for (m = 0; l; l = l->next)
		switch(l->type) {
		case LINE:
			if (WITHIN(l->P,r)) {
				l->sel |= 3;
				m |= (l->mod |= LINEBOX);
			}
			if (WITHIN(l->Q,r)) {
				l->sel |= 12;
				m |= (l->mod |= LINEBOX);
			}
			break;
		case BOX:
		case MACRO:
		case DOTS:
		case INST:
			if (WITHIN(l->P,r) && WITHIN(l->Q,r)) {
				l->sel |= 15;
				m |= (l->mod |= BOXBOX);
			}
			break;
		case STRING:
			if (WITHIN(l->P,r)) {
				l->sel = 3;
				m |= (l->mod |= STRBOX);
			}
			break;
		}
	return m;
}
Exemple #3
0
int newbackside( float line )
{
    extern int dev_lmts();  /* in geom/limits.c */
    char *instr;
    int ie;
    float min_x;
    float max_x;
    float min_y;
    float max_y;
    float offset = 1.0;

    instr = malloc(80*sizeof(char));
    instr = "structure outf=suprem4temp.str";
    do_string(instr, NULL, 0);

/*    hack up grid here */
    dev_lmts(&min_x, &max_x, &min_y, &max_y);
    min_x *= 1.0e4;
    max_x *= 1.0e4;
    min_y *= 1.0e4;
    max_y *= 1.0e4;
    if (line < max_y)  {
	sprintf(instr, "etch silicon start x=%g y=%g", min_x - offset, line);
        do_string(instr, "/dev/null", 0);
	sprintf(instr, "etch silicon continue x=%g y=%g", max_x + offset, line);
        do_string(instr, "/dev/null", 0);
	sprintf(instr, "etch silicon continue x=%g y=%g", max_x + offset,
		max_y + offset);
        do_string(instr, "/dev/null", 0);
	sprintf(instr, "etch silicon done x=%g y=%g", min_x - offset,
		max_y + offset);
        do_string(instr, "/dev/null", 0);
	instr = "structure outf=etch.str";
	do_string(instr, "/dev/null", 0);

	/* now that we have the final structure, recompute the backside
	 *  boundary condition
	 */

	/* for now lets just walk through all the triangle.  it's inefficient
	 *	but should work
	 */
	for (ie = 0; ie < ne; ie++)  {
	    if (WITHIN(pt[nd[tri[ie]->nd[0]]->pt]->cord[1], line*1.0e-4))  {
	        if (WITHIN(pt[nd[tri[ie]->nd[1]]->pt]->cord[1], line*1.0e-4))
		    tri[ie]->nb[2] = BC_OFFSET + 1;
	        else
		  if (WITHIN(pt[nd[tri[ie]->nd[2]]->pt]->cord[1], line*1.0e-4))
		    tri[ie]->nb[1] = BC_OFFSET + 1;
	    }
	    else {
		if (WITHIN(pt[nd[tri[ie]->nd[1]]->pt]->cord[1], line*1.0e-4))
	          if (WITHIN(pt[nd[tri[ie]->nd[2]]->pt]->cord[1], line*1.0e-4))
		        tri[ie]->nb[0] = BC_OFFSET + 1;
	    }
	}
        free(instr);
    }
    return(0);
}
void BitmapDrawer::PlotRGB(int32 x, int32 y, rgb_color c){
	if (!WITHIN(0, x, mRight))	return;		// check boundaries
	if (!WITHIN(0, y, mBottom))	return;
   
	uint8 *bits = mBits + (x<<2) + mHeightLookup[ y ];
	bits[0]=c.blue;	bits[1]=c.green; bits[2]=c.red; bits[3]=c.alpha;
}
void BitmapDrawer::PlotBGR(int32 x, int32 y, rgb_color c){
	if (!WITHIN(0, x, mRight))	return;		// check boundaries
	if (!WITHIN(0, y, mBottom))	return;
   
	rgb_color *bits = (rgb_color*)mBits + x + mHeightLookup2[y];
	*bits=c;
}
/*******************************************************
* Set pixel  
*******************************************************/
void BitmapDrawer::PlotBGR(BPoint p, rgb_color c)
{
	if (!WITHIN(0, (int)p.x, mRight))	return;		// check boundaries
	if (!WITHIN(0, (int)p.y, mBottom))	return;
   
	rgb_color *bits = (rgb_color*)mBits + (int)p.x + mHeightLookup2[ (int)p.y ];
	*bits=c;
}
Exemple #7
0
/*! \brief The intersection point of two finite line segments, or return `{nan,nan}` if they do not intersect.
 *
 * Lines are given by a couple of a point in the line and a direction vector.
 * The two lines here are given by `{p,v}` and `{q,w}`.
 * The length of the segment is the length of the direction vector.
 * In other words, the extremity of segment `{p,v}` are `p` and `p+v`.
 */
inline bool lineSegment_intersection( move2 const& l1, move2 const& l2, real2& hitpoint, real& hitpoint_factor )
{
	real2 const factors= line_intersection_factors( l1.t, l1.r, l2.t, l2.r );
	if(!(  WITHIN( 0.0, factors.x, 1.0) && WITHIN( 0.0, factors.x, 1.0 )  ))
		return false;
	hitpoint_factor = factors.x;
	hitpoint = l1.t + l1.r*(factors.x);
	return true;
}
Exemple #8
0
BOOL CHistogramDlg::OnCommand( WPARAM wParam, LPARAM lParam )
{
	int id = LOWORD(wParam);					//unpack the message
	WORD codeNotify = HIWORD(wParam);
	HWND hControl = (HWND) lParam;

	int i, val;
	

	switch (id)
	{
		case IDC_CHANNELS:
			i=ChannelsCombo_Handle(id, codeNotify);
			if (!i)
				break;
			m_wChannel = i;
			set_histo_channel();
		break;
	
		case IDC_HISTOGRAM:
			// value changed
			if (WITHIN(codeNotify, HTN_CHANGED_FIRST, HTN_CHANGED_LAST))
				i = codeNotify-HTN_CHANGED_FIRST;
			else if (WITHIN(codeNotify, HTN_CHANGING_FIRST, HTN_CHANGING_LAST))
				i = codeNotify-HTN_CHANGING_FIRST;
			else if (codeNotify = HTN_BROWSE)
			{
				val = Histo_GetBrowse(hControl);
				histo_browse(val);
				break;
			}	
			else
				break;
			val = Histo_GetMark(hControl, i);
			histo_browse(val);
			histo_change_mark(i, val);
		break;

		case IDC_TAGS:
			// value changed
			if (WITHIN(codeNotify, TN_CHANGED_FIRST, TN_CHANGED_LAST))
				i = codeNotify-TN_CHANGED_FIRST;
			else if (WITHIN(codeNotify, TN_CHANGING_FIRST, TN_CHANGING_LAST))
				i = codeNotify-TN_CHANGING_FIRST;
			else
				break;
			val = Tag_GetMark(hControl, i);
			histo_browse(val);
			histo_change_mark(i, val);
		break;

   		default:
		break;
   }
return CWnd::OnCommand(wParam, lParam);
}
Exemple #9
0
 /**
  * From given list of configurations, convert them into affine matrices.
  * But filter out all the rectangles that are out of the given boundaries.
  **/
 vector<Mat> FAsTMatch::configsToAffine( vector<MatchConfig>& configs, vector<bool>& insiders ) {
     int no_of_configs = static_cast<int>(configs.size());
     vector<Mat> affines( no_of_configs );
     
     /* The boundary, between -10 to image size + 10 */
     Point2d top_left( -10., -10. );
     Point2d bottom_right( image.cols + 10, image.rows + 10 );
     
     
     /* These are for the calculations of affine transformed corners */
     int r1x  = 0.5 * ( templ.cols  - 1),
         r1y  = 0.5 * ( templ.rows - 1),
         r2x  = 0.5 * ( image.cols  - 1),
         r2y  = 0.5 * ( image.rows - 1);
     
     Mat corners = (Mat_<float>(3, 4) <<
                    1-(r1x+1), templ.cols-(r1x+1), templ.cols-(r1x+1),  1-(r1x+1),
                    1-(r1y+1), 1-(r1y+1)         , templ.rows-(r1y+1), templ.rows-(r1y+1),
                    1.0      , 1.0               , 1.0               , 1.0 );
     
     Mat transl = (Mat_<float>(4, 2) <<
                   r2x + 1, r2y + 1,
                   r2x + 1, r2y + 1,
                   r2x + 1, r2y + 1,
                   r2x + 1, r2y + 1 );
     
     insiders.assign( no_of_configs, false );
     
     /* Convert each configuration to corresponding affine transformation matrix */
     tbb::parallel_for( 0, no_of_configs, 1, [&](int i) {
         Mat affine = configs[i].getAffineMatrix();
         
         /* Check if our affine transformed rectangle still fits within our boundary */
         Mat affine_corners = (affine * corners).t();
         affine_corners =  affine_corners + transl;
         
         if( WITHIN( affine_corners.at<Point2f>(0), top_left, bottom_right) &&
             WITHIN( affine_corners.at<Point2f>(1), top_left, bottom_right) &&
             WITHIN( affine_corners.at<Point2f>(2), top_left, bottom_right) &&
             WITHIN( affine_corners.at<Point2f>(3), top_left, bottom_right) ) {
             
             affines[i]  = affine;
             insiders[i] = true;
         }
     });
     
     /* Filter out empty affine matrices (which initially don't fit within the preset boundary) */
     /* It's done this way, so that I could parallelize the loop */
     vector<Mat> result;
     for( int i = 0; i < no_of_configs; i++ ) {
         if( insiders[i] )
             result.push_back( affines[i] );
     }
     
     return result;
 }
  /**
   * M100 D
   *  Dump the free memory block from __brkval to the stack pointer.
   *  malloc() eats memory from the start of the block and the stack grows
   *  up from the bottom of the block. Solid test bytes indicate nothing has
   *  used that memory yet. There should not be anything but test bytes within
   *  the block. If so, it may indicate memory corruption due to a bad pointer.
   *  Unexpected bytes are flagged in the right column.
   */
  void dump_free_memory(const char *ptr, const char *sp) {
    //
    // Start and end the dump on a nice 16 byte boundary
    // (even though the values are not 16-byte aligned).
    //
    ptr = (char *)((uint16_t)ptr & 0xFFF0); // Align to 16-byte boundary
    sp  = (char *)((uint16_t)sp  | 0x000F); // Align sp to the 15th byte (at or above sp)

    // Dump command main loop
    while (ptr < sp) {
      print_hex_word((uint16_t)ptr);      // Print the address
      SERIAL_CHAR(':');
      for (uint8_t i = 0; i < 16; i++) {  // and 16 data bytes
        if (i == 8) SERIAL_CHAR('-');
        print_hex_byte(ptr[i]);
        SERIAL_CHAR(' ');
      }
      safe_delay(25);
      SERIAL_CHAR('|');                   // Point out non test bytes
      for (uint8_t i = 0; i < 16; i++) {
        char ccc = (char)ptr[i]; // cast to char before automatically casting to char on assignment, in case the compiler is broken
        if (&ptr[i] >= (const char*)command_queue && &ptr[i] < (const char*)(command_queue + sizeof(command_queue))) { // Print out ASCII in the command buffer area
          if (!WITHIN(ccc, ' ', 0x7E)) ccc = ' ';
        }
        else { // If not in the command buffer area, flag bytes that don't match the test byte
          ccc = (ccc == TEST_BYTE) ? ' ' : '?';
        }
        SERIAL_CHAR(ccc);
      }
      SERIAL_EOL();
      ptr += 16;
      safe_delay(25);
      idle();
    }
  }
Exemple #11
0
static void i2c_send(int channel, byte v) {
  if (WITHIN(channel, 0, DIGIPOT_I2C_NUM_CHANNELS - 1)) {
    pots[channel].i2c_start(((DIGIPOT_I2C_ADDRESS) << 1) | I2C_WRITE);
    pots[channel].i2c_write(v);
    pots[channel].i2c_stop();
  }
}
Exemple #12
0
static int verify_eterm(Process *p,Eterm element)
{
    Eterm *ptr;
    ErlHeapFragment* mbuf;

    switch (primary_tag(element)) {
    case TAG_PRIMARY_LIST:
        ptr = list_val(element);
        break;
    case TAG_PRIMARY_BOXED:
        ptr = boxed_val(element);
        break;
    default: /* Immediate or header/cp */
        return 1;
    }

    if (p) {
        if (IN_HEAP(p, ptr))
            return 1;

        for (mbuf = p->mbuf; mbuf; mbuf = mbuf->next) {
            if (WITHIN(ptr, &mbuf->mem[0], &mbuf->mem[0] + mbuf->used_size)) {
                return 1;
            }
        }
    }
    return 0;
}
Exemple #13
0
/**
 * M900: Get or Set Linear Advance K-factor
 *
 *  K<factor>   Set advance K factor
 */
void GcodeSuite::M900() {

  #if EXTRUDERS < 2
    constexpr uint8_t tmp_extruder = 0;
  #else
    const uint8_t tmp_extruder = parser.seenval('T') ? parser.value_int() : active_extruder;
    if (tmp_extruder >= EXTRUDERS) {
      SERIAL_ECHOLNPGM("?T value out of range.");
      return;
    }
  #endif

  if (parser.seenval('K')) {
    const float newK = parser.floatval('K');
    if (WITHIN(newK, 0, 10)) {
      planner.synchronize();
      planner.extruder_advance_K[tmp_extruder] = newK;
    }
    else
      SERIAL_ECHOLNPGM("?K value out of range (0-10).");
  }
  else {
    SERIAL_ECHO_START();
    #if EXTRUDERS < 2
      SERIAL_ECHOLNPAIR("Advance K=", planner.extruder_advance_K[0]);
    #else
      SERIAL_ECHOPGM("Advance K");
      LOOP_L_N(i, EXTRUDERS) {
        SERIAL_CHAR(' '); SERIAL_ECHO(int(i));
        SERIAL_CHAR('='); SERIAL_ECHO(planner.extruder_advance_K[i]);
      }
      SERIAL_EOL();
    #endif
  }
Exemple #14
0
//=======================================================================
//	void CPoly::SetCurrentPoint(LPPOINT lpPoint);
//
//		changes the coords of the current point to *lpPoint.
//=======================================================================
void CPoly::SetCurrentPoint(LPPOINT lpPoint)
//=======================================================================
{
	if (!WITHIN(CurPointPos, 0, EntriesUsed-1) || !Num)
		return;
	lpPoints[CurPointPos] = *lpPoint;
}
bool check(TetrisBoard b, Shape s, int x, int y)
{
    for (int i = 0; i < 4; ++i)
    {
        int xi = x + s[i][0];
        int yi = y + s[i][1];
        if (!WITHIN(0, xi, T_WIDTH) || !WITHIN(0, yi, T_HEIGHT))
        {
            return false;
        }
        if (b[xi][yi])
        {
            return false;
        }
    }
    return true;
}
Exemple #16
0
/**
 * M421: Set a single Mesh Bed Leveling Z coordinate
 *
 * Usage:
 *   M421 I<xindex> J<yindex> Z<linear>
 *   M421 I<xindex> J<yindex> Q<offset>
 */
void GcodeSuite::M421() {
  int8_t ix = parser.intval('I', -1), iy = parser.intval('J', -1);
  const bool hasI = ix >= 0,
             hasJ = iy >= 0,
             hasZ = parser.seen('Z'),
             hasQ = !hasZ && parser.seen('Q');

  if (!hasI || !hasJ || !(hasZ || hasQ))
    SERIAL_ERROR_MSG(MSG_ERR_M421_PARAMETERS);
  else if (!WITHIN(ix, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(iy, 0, GRID_MAX_POINTS_Y - 1))
    SERIAL_ERROR_MSG(MSG_ERR_MESH_XY);
  else {
    z_values[ix][iy] = parser.value_linear_units() + (hasQ ? z_values[ix][iy] : 0);
    #if ENABLED(ABL_BILINEAR_SUBDIVISION)
      bed_level_virt_interpolate();
    #endif
  }
}
Exemple #17
0
//=======================================================================
//	LPPOINT CurrentPoint(LPPOINT lpPoint)
//		lpPoint: The point structure to fill.  Can NOT be NULL.
//
//		Sets *lpPoint to be the current point.
//   	Returns lpPoint or NULL (as in GetPoint()).
//=======================================================================
LPPOINT CPoly::CurrentPoint(LPPOINT lpPoint)
//=======================================================================
{
	
	if (!WITHIN(CurPointPos, 0, EntriesUsed-1) || !Num)
		return(NULL);
	*lpPoint = lpPoints[CurPointPos];
	return(lpPoint);
}
static const char *prv_get_font_key_for_value(int32_t value) {
#if PBL_RECT
  if (WITHIN(value, -9999, 9999)) {
    return FONT_KEY_LECO_32_BOLD_NUMBERS;
  } else if (WITHIN(value, -99999, 99999)) {
    return FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM;
  } else {
    return FONT_KEY_LECO_20_BOLD_NUMBERS;
  }
#elif PBL_ROUND
  if (WITHIN(value, -99999, 99999)) {
    return FONT_KEY_LECO_32_BOLD_NUMBERS;
  } else {
    return FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM;
  }
#else
#error "Unknown display shape type!"
#endif
}
void goal_star_number_window_set_value(GoalStarNumberWindow *number_window, int32_t value) {
  if (number_window &&
      (value != number_window->value) &&
      WITHIN(value, number_window->min, number_window->max)) {
    number_window->value = value;
    snprintf(number_window->value_text, GOAL_STAR_CONFIGURATION_STRING_BUFFER_LENGTH, "%"PRId32"",
             number_window->value);
    prv_update_value_text_layer(number_window);
  }
}
Exemple #20
0
Fichier : line.c Projet : kahrs/cda
slashbox(Line *l,Rectangle r)
{
	int m;
	for (m = 0; l; l = l->next)
		switch(l->type) {
		case LINE:
			if (WITHIN(l->P,r)) {
				l->sel |= 3;
				m |= (l->mod |= LINEBOX);
			}
			if (WITHIN(l->Q,r)) {
				l->sel |= 12;
				m |= (l->mod |= LINEBOX);
			}
			if (l->sel != 0 && l->sel != 15
				&& (l->X == l->U || l->Y == l->V)) {	/* clip */
				Line *n = newline(l->Q,l->next);
				l->next = n;
				l->Q = n->P = rclipl(r,canon(l->r));
				n->sel = l->sel&12;
				n->sel |= n->sel>>2;
				l->sel &= 3;
				l->sel |= l->sel<<2;
				l = l->next;
			}
			break;
		case BOX:
		case MACRO:
		case DOTS:
		case INST:
			if (WITHIN(l->P,r) && WITHIN(l->Q,r)) {
				l->sel |= 15;
				m |= (l->mod |= BOXBOX);
			}
			break;
		case STRING:
			if (WITHIN(l->P,r)) {
				l->sel = 3;
				m |= (l->mod |= STRBOX);
			}
			break;
		}
Exemple #21
0
//************************************************************************
//
// PARAMETERS:
//			int num-the number of points to check
// DESCRIPTION:
//			Checks all points starting at lpFirst+1, for tolerence 
//			to line lpFirst,lpLast.
// RETURNS:
//			True if Tolerance conditions are met.
//************************************************************************
LOCAL  BOOL check_tolerance(LPPOINT lpFirst, LPPOINT lpLast, int num, int Tolerance)
//************************************************************************
{
	int dx, dy, xmin, xmax, ymin, ymax;
	double x, y, tolerance;
	POINT start, test;
	
	
	if (num<1)
		return(TRUE);
	tolerance = .25 + Tolerance;
	start = *lpFirst;
	dx = lpLast->x - start.x;
	dy = lpLast->y - start.y;
	xmin = min(start.x-Tolerance, lpLast->x-Tolerance);
	xmax = max(start.x+Tolerance, lpLast->x+Tolerance);
	ymin = min(start.y-Tolerance, lpLast->y-Tolerance);
	ymax = max(start.y+Tolerance, lpLast->y+Tolerance);
	
	for (;num>0;num--)
	{
		test = *++lpFirst;
		if (dy)
		{
			x = (test.y-start.y)*(double)dx/dy + start.x;
			if (WITHIN(test.x, x-tolerance, x+tolerance))
				if (WITHIN(x, xmin, xmax))
					continue;
		}
		if (dx)
		{
			y = (test.x-start.x)*(double)dy/dx + start.y;
			if (WITHIN(test.y, y-tolerance, y+tolerance))
				if (WITHIN(y, ymin, ymax))
					continue;
		}
		break;
	}
	if (num>0)
		return(FALSE);
	return(TRUE);
}
Exemple #22
0
 // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
 char* ftostr4sign(const float &f) {
   const int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
   if (!WITHIN(i, -99, 999)) return i16tostr4sign((int)f);
   const bool neg = i < 0;
   const int ii = neg ? -i : i;
   conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');
   conv[4] = DIGIMOD(ii, 10);
   conv[5] = '.';
   conv[6] = DIGIMOD(ii, 1);
   return &conv[3];
 }
Exemple #23
0
 // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
 char *ftostr4sign(const float& fx) {
   const int x = fx * 10;
   if (!WITHIN(x, -99, 999)) return itostr4sign((int)fx);
   const bool neg = x < 0;
   const int xx = neg ? -x : x;
   conv[3] = neg ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
   conv[4] = DIGIMOD(xx, 10);
   conv[5] = '.';
   conv[6] = DIGIMOD(xx, 1);
   return &conv[3];
 }
Exemple #24
0
void erts_check_stack(Process *p)
{
    Eterm *elemp;
    Eterm *stack_start = p->heap + p->heap_sz;
    Eterm *stack_end = p->htop;

    if (p->stop > stack_start)
        erl_exit(1,
                 "<%lu.%lu.%lu>: Stack underflow\n",
                 internal_pid_channel_no(p->common.id),
                 internal_pid_number(p->common.id),
                 internal_pid_serial(p->common.id));

    if (p->stop < stack_end)
        erl_exit(1,
                 "<%lu.%lu.%lu>: Stack overflow\n",
                 internal_pid_channel_no(p->common.id),
                 internal_pid_number(p->common.id),
                 internal_pid_serial(p->common.id));

    for (elemp = p->stop; elemp < stack_start; elemp++) {
        int in_mbuf = 0;
        Eterm *ptr;
        ErlHeapFragment* mbuf;
        switch (primary_tag(*elemp)) {
        case TAG_PRIMARY_LIST:
            ptr = list_val(*elemp);
            break;
        case TAG_PRIMARY_BOXED:
            ptr = boxed_val(*elemp);
            break;
        default: /* Immediate or cp */
            continue;
        }
        if (IN_HEAP(p, ptr))
            continue;
        for (mbuf = p->mbuf; mbuf; mbuf = mbuf->next)
            if (WITHIN(ptr, &mbuf->mem[0], &mbuf->mem[0] + mbuf->used_size)) {
                in_mbuf = 1;
                break;
            }
        if (in_mbuf)
            continue;

        erl_exit(1,
                 "<%lu.%lu.%lu>: Wild stack pointer\n",
                 internal_pid_channel_no(p->common.id),
                 internal_pid_number(p->common.id),
                 internal_pid_serial(p->common.id));
    }

}
Exemple #25
0
//=======================================================================
//	WORD CPoly::IsHandle()
//		If the current point is a control point for a curve then it 
//		returns the handle number (1 for first, 2 for second, etc).
//		Otherwise it returns 0.
//=======================================================================
WORD CPoly::IsHandle()
//=======================================================================
{
	int i;
	
	if(CurPointPos < 0)
		return(FALSE);
	i = get_curve_index(CurPointPos);
	if (!i)
		return(FALSE);
	if(!WITHIN(i, 2, BEZIER_IN-1))
		return(FALSE);
	return(i-1);
}
Exemple #26
0
/**
 * M226: Wait until the specified pin reaches the state required (M226 P<pin> S<state>)
 */
void GcodeSuite::M226() {
  if (parser.seen('P')) {
    const int pin_number = PARSED_PIN_INDEX('P', 0),
              pin_state = parser.intval('S', -1); // required pin state - default is inverted
    const pin_t pin = GET_PIN_MAP_PIN(pin_number);

    if (WITHIN(pin_state, -1, 1) && pin > -1) {
      if (pin_is_protected(pin))
        protected_pin_err();
      else {
        int target = LOW;
        planner.synchronize();
        pinMode(pin, INPUT);
        switch (pin_state) {
          case 1: target = HIGH; break;
          case 0: target = LOW; break;
          case -1: target = !digitalRead(pin); break;
        }
        while (digitalRead(pin) != target) idle();
      }
    } // pin_state -1 0 1 && pin > -1
  } // parser.seen('P')
}
Exemple #27
0
BOOL CToneBalanceDlg::OnCommand( WPARAM wParam, LPARAM lParam )
{
	int id = LOWORD(wParam);					//unpack the message
	WORD codeNotify = HIWORD(wParam);
	HWND hControl = (HWND) lParam;
	HWND hDlg = GetSafeHwnd();

	int i, val;
	BOOL Bool;
	HWND hActiveWnd;
	LPIMAGE lpImage = NULL;
	

	lpImage = GetImage();

	switch (id)
	{
		case IDC_CHANNELS:
			i=ChannelsCombo_Handle(id, codeNotify);
			if (!i)
				break;
			m_lpData->wChannel = i;
			set_quarter_channel(m_lpData->wChannel);
		break;
	
		case IDC_QUART1_PROBE:
		case IDC_QUART2_PROBE:
		case IDC_QUART3_PROBE:
			if (!Probe_Begin(codeNotify))
				break;
			CheckDlgButton(id, YES );
			m_lpData->iProbe = id-IDC_QUART1_PROBE;
			if (m_lpData->iProbe == 0)
				m_lpData->OriginalValue = m_lpData->iShadow;
			else if (m_lpData->iProbe == 1)
				m_lpData->OriginalValue = m_lpData->iMidtone;
			else
				m_lpData->OriginalValue = m_lpData->iHighlight;
			// unpreview
			UnAutoPreview();
		break;

		case IDC_QUART1_VALUE:
		case IDC_QUART2_VALUE:
		case IDC_QUART3_VALUE:
			if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) )
				break;
			if ( codeNotify != EN_CHANGE)
				break;
			val = GetDlgItemSpin(hDlg, id, &Bool, NO);
			if (!Bool)
				break;
			// convert to 'real' location
			if (id == IDC_QUART2_VALUE && m_bUseMidPer)
			  	i = m_lpData->iShadow + (LONG)val*(m_lpData->iHighlight-m_lpData->iShadow)/100;
			else
				i = FROM_DISPLAY(val);
			if (id != IDC_QUART2_VALUE)
				val = INT_MAX;
			change_mark(m_lpData,  id-IDC_QUART1_VALUE, i, val);
			AutoPreview(m_lpData->lpMap, m_bAutoPreview, NO);
		break;
		
		case IDC_MINHIGHLIGHT:
			if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) )
				break;
			if ( codeNotify != EN_CHANGE)
				break;
			i = GetDlgItemSpin(hDlg, id, &Bool, NO);
			if (!Bool)
				break;
			i = FROM_DISPLAY(i);
			m_lpData->lpMap->Pnt[2].y = i;
			m_lpData->lpMap->Pnt[1].y = (m_lpData->lpMap->Pnt[2].y+m_lpData->lpMap->Pnt[0].y)/2;
			AutoPreview(m_lpData->lpMap,m_bAutoPreview, YES);
		break;
		
		case IDC_MAXSHADOW:
			if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) )
				break;
			if ( codeNotify != EN_CHANGE)
				break;
			i = GetDlgItemSpin(hDlg, id, &Bool, NO);
			if (!Bool)
				break;
			i = FROM_DISPLAY(i);
			m_lpData->lpMap->Pnt[0].y = i;
			m_lpData->lpMap->Pnt[1].y = (m_lpData->lpMap->Pnt[2].y+m_lpData->lpMap->Pnt[0].y)/2;
			AutoPreview(m_lpData->lpMap, m_bAutoPreview, YES);
		break;
		
		case IDC_HISTOGRAM:
			// value changed
			if (WITHIN(codeNotify, HTN_CHANGED_FIRST, HTN_CHANGED_LAST))
			{
				i = codeNotify-HTN_CHANGED_FIRST;
				Bool = TRUE;
			}
			else if (WITHIN(codeNotify, HTN_CHANGING_FIRST, HTN_CHANGING_LAST))
			{
				i = codeNotify-HTN_CHANGING_FIRST;
				Bool = FALSE;
			}
			else
				break;
			val = Histo_GetMark(hControl, i);
			change_mark(m_lpData, i, val, INT_MAX);
			AutoPreview(m_lpData->lpMap, m_bAutoPreview, Bool);
		break;
		
		case IDC_TAGS:
			// value changed
			if (WITHIN(codeNotify, TN_CHANGED_FIRST, TN_CHANGED_LAST))
			{
				i = codeNotify-TN_CHANGED_FIRST;
				Bool = TRUE;
			}
			else if (WITHIN(codeNotify, TN_CHANGING_FIRST, TN_CHANGING_LAST))
			{
				i = codeNotify-TN_CHANGING_FIRST;
				Bool = FALSE;
			}
			else
				break;
			val = Tag_GetMark(hControl, i);
			change_mark(m_lpData, i, val, INT_MAX);
			AutoPreview(m_lpData->lpMap, m_bAutoPreview, Bool);
		break;

//		case IDC_PREVIEW:
//	  		AutoPreview_Button(m_lpData->lpMap);
//		break;
		
		
//		case IDC_QUART_DEFAULTS:
//			// setup channel with sacrifice defaults
//			set_sacrifice(m_lpData, m_lpData->wChannel);
//			// setup the actual histogram and controls 
//			set_quarter_channel(m_lpData->wChannel);
//			AutoPreview(m_lpData->lpMap, m_bAutoPreview, YES);
//		break;
	
		


   		default:
		break;
   }
return CWnd::OnCommand(wParam, lParam);
}
Exemple #28
0
static gboolean
calc_undistorted_coords (gdouble  wx,
                         gdouble  wy,
                         gdouble *x,
                         gdouble *y)
{
  gboolean inside;
  gdouble  phi, phi2;
  gdouble  xx, xm, ym, yy;
  gint     xdiff, ydiff;
  gdouble  r;
  gdouble  m;
  gdouble  xmax, ymax, rmax;
  gdouble  x_calc, y_calc;
  gdouble  xi, yi;
  gdouble  circle, angl, t, angle;
  gint     x1, x2, y1, y2;

  /* initialize */

  phi = 0.0;
  r   = 0.0;

  x1     = 0;
  y1     = 0;
  x2     = img_width;
  y2     = img_height;
  xdiff  = x2 - x1;
  ydiff  = y2 - y1;
  xm     = xdiff / 2.0;
  ym     = ydiff / 2.0;
  circle = pcvals.circle;
  angle  = pcvals.angle;
  angl   = (gdouble) angle / 180.0 * G_PI;

  if (pcvals.polrec)
    {
      if (wx >= cen_x)
        {
          if (wy > cen_y)
            {
              phi = G_PI - atan (((double)(wx - cen_x))/
                                 ((double)(wy - cen_y)));
            }
          else if (wy < cen_y)
            {
              phi = atan (((double)(wx - cen_x))/((double)(cen_y - wy)));
            }
          else
            {
              phi = G_PI / 2;
            }
        }
      else if (wx < cen_x)
        {
          if (wy < cen_y)
            {
              phi = 2 * G_PI - atan (((double)(cen_x -wx)) /
                                     ((double)(cen_y - wy)));
            }
          else if (wy > cen_y)
            {
              phi = G_PI + atan (((double)(cen_x - wx))/
                                 ((double)(wy - cen_y)));
            }
          else
            {
              phi = 1.5 * G_PI;
            }
        }

      r   = sqrt (SQR (wx - cen_x) + SQR (wy - cen_y));

      if (wx != cen_x)
        {
          m = fabs (((double)(wy - cen_y)) / ((double)(wx - cen_x)));
        }
      else
        {
          m = 0;
        }

      if (m <= ((double)(y2 - y1) / (double)(x2 - x1)))
        {
          if (wx == cen_x)
            {
              xmax = 0;
              ymax = cen_y - y1;
            }
          else
            {
              xmax = cen_x - x1;
              ymax = m * xmax;
            }
        }
      else
        {
          ymax = cen_y - y1;
          xmax = ymax / m;
        }

      rmax = sqrt ( (double)(SQR (xmax) + SQR (ymax)) );

      t = ((cen_y - y1) < (cen_x - x1)) ? (cen_y - y1) : (cen_x - x1);
      rmax = (rmax - t) / 100 * (100 - circle) + t;

      phi = fmod (phi + angl, 2*G_PI);

      if (pcvals.backwards)
        x_calc = x2 - 1 - (x2 - x1 - 1)/(2*G_PI) * phi;
      else
        x_calc = (x2 - x1 - 1)/(2*G_PI) * phi + x1;

      if (pcvals.inverse)
        y_calc = (y2 - y1)/rmax   * r   + y1;
      else
        y_calc = y2 - (y2 - y1)/rmax * r;
    }
  else
    {
      if (pcvals.backwards)
        phi = (2 * G_PI) * (x2 - wx) / xdiff;
      else
        phi = (2 * G_PI) * (wx - x1) / xdiff;

      phi = fmod (phi + angl, 2 * G_PI);

      if (phi >= 1.5 * G_PI)
        phi2 = 2 * G_PI - phi;
      else if (phi >= G_PI)
        phi2 = phi - G_PI;
      else if (phi >= 0.5 * G_PI)
        phi2 = G_PI - phi;
      else
        phi2 = phi;

      xx = tan (phi2);
      if (xx != 0)
        m = (double) 1.0 / xx;
      else
        m = 0;

      if (m <= ((double)(ydiff) / (double)(xdiff)))
        {
          if (phi2 == 0)
            {
              xmax = 0;
              ymax = ym - y1;
            }
          else
            {
              xmax = xm - x1;
              ymax = m * xmax;
            }
        }
      else
        {
          ymax = ym - y1;
          xmax = ymax / m;
        }

      rmax = sqrt ((double)(SQR (xmax) + SQR (ymax)));

      t = ((ym - y1) < (xm - x1)) ? (ym - y1) : (xm - x1);

      rmax = (rmax - t) / 100.0 * (100 - circle) + t;

      if (pcvals.inverse)
        r = rmax * (double)((wy - y1) / (double)(ydiff));
      else
        r = rmax * (double)((y2 - wy) / (double)(ydiff));

      xx = r * sin (phi2);
      yy = r * cos (phi2);

      if (phi >= 1.5 * G_PI)
        {
          x_calc = (double)xm - xx;
          y_calc = (double)ym - yy;
        }
      else if (phi >= G_PI)
        {
          x_calc = (double)xm - xx;
          y_calc = (double)ym + yy;
        }
      else if (phi >= 0.5 * G_PI)
        {
          x_calc = (double)xm + xx;
          y_calc = (double)ym + yy;
        }
      else
        {
          x_calc = (double)xm + xx;
          y_calc = (double)ym - yy;
        }
    }

  xi = (int) (x_calc + 0.5);
  yi = (int) (y_calc + 0.5);

  inside = (WITHIN (0, xi, img_width - 1) && WITHIN (0, yi, img_height - 1));
  if (inside)
    {
      *x = x_calc;
      *y = y_calc;
    }
  return inside;
}
Exemple #29
0
/**
 * M48: Z probe repeatability measurement function.
 *
 * Usage:
 *   M48 <P#> <X#> <Y#> <V#> <E> <L#> <S>
 *     P = Number of sampled points (4-50, default 10)
 *     X = Sample X position
 *     Y = Sample Y position
 *     V = Verbose level (0-4, default=1)
 *     E = Engage Z probe for each reading
 *     L = Number of legs of movement before probe
 *     S = Schizoid (Or Star if you prefer)
 *
 * This function requires the machine to be homed before invocation.
 */
void GcodeSuite::M48() {

  if (axis_unhomed_error()) return;

  const int8_t verbose_level = parser.byteval('V', 1);
  if (!WITHIN(verbose_level, 0, 4)) {
    SERIAL_ECHOLNPGM("?(V)erbose level is implausible (0-4).");
    return;
  }

  if (verbose_level > 0)
    SERIAL_ECHOLNPGM("M48 Z-Probe Repeatability Test");

  const int8_t n_samples = parser.byteval('P', 10);
  if (!WITHIN(n_samples, 4, 50)) {
    SERIAL_ECHOLNPGM("?Sample size not plausible (4-50).");
    return;
  }

  const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_RAISE;

  float X_current = current_position[X_AXIS],
        Y_current = current_position[Y_AXIS];

  const float X_probe_location = parser.linearval('X', X_current + X_PROBE_OFFSET_FROM_EXTRUDER),
              Y_probe_location = parser.linearval('Y', Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER);

  if (!position_is_reachable_by_probe(X_probe_location, Y_probe_location)) {
    SERIAL_ECHOLNPGM("? (X,Y) out of bounds.");
    return;
  }

  bool seen_L = parser.seen('L');
  uint8_t n_legs = seen_L ? parser.value_byte() : 0;
  if (n_legs > 15) {
    SERIAL_ECHOLNPGM("?Number of legs in movement not plausible (0-15).");
    return;
  }
  if (n_legs == 1) n_legs = 2;

  const bool schizoid_flag = parser.boolval('S');
  if (schizoid_flag && !seen_L) n_legs = 7;

  /**
   * Now get everything to the specified probe point So we can safely do a
   * probe to get us close to the bed.  If the Z-Axis is far from the bed,
   * we don't want to use that as a starting point for each probe.
   */
  if (verbose_level > 2)
    SERIAL_ECHOLNPGM("Positioning the probe...");

  // Disable bed level correction in M48 because we want the raw data when we probe

  #if HAS_LEVELING
    const bool was_enabled = planner.leveling_active;
    set_bed_leveling_enabled(false);
  #endif

  setup_for_endstop_or_probe_move();

  float mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples];

  // Move to the first point, deploy, and probe
  const float t = probe_pt(X_probe_location, Y_probe_location, raise_after, verbose_level);
  bool probing_good = !isnan(t);

  if (probing_good) {
    randomSeed(millis());

    for (uint8_t n = 0; n < n_samples; n++) {
      if (n_legs) {
        const int dir = (random(0, 10) > 5.0) ? -1 : 1;  // clockwise or counter clockwise
        float angle = random(0, 360);
        const float radius = random(
          #if ENABLED(DELTA)
            (int) (0.1250000000 * (DELTA_PRINTABLE_RADIUS)),
            (int) (0.3333333333 * (DELTA_PRINTABLE_RADIUS))
          #else
            (int) 5.0, (int) (0.125 * MIN(X_BED_SIZE, Y_BED_SIZE))
          #endif
        );

        if (verbose_level > 3) {
          SERIAL_ECHOPAIR("Starting radius: ", radius);
          SERIAL_ECHOPAIR("   angle: ", angle);
          SERIAL_ECHOPGM(" Direction: ");
          if (dir > 0) SERIAL_ECHOPGM("Counter-");
          SERIAL_ECHOLNPGM("Clockwise");
        }

        for (uint8_t l = 0; l < n_legs - 1; l++) {
          float delta_angle;

          if (schizoid_flag)
            // The points of a 5 point star are 72 degrees apart.  We need to
            // skip a point and go to the next one on the star.
            delta_angle = dir * 2.0 * 72.0;

          else
            // If we do this line, we are just trying to move further
            // around the circle.
            delta_angle = dir * (float) random(25, 45);

          angle += delta_angle;

          while (angle > 360.0)   // We probably do not need to keep the angle between 0 and 2*PI, but the
            angle -= 360.0;       // Arduino documentation says the trig functions should not be given values
          while (angle < 0.0)     // outside of this range.   It looks like they behave correctly with
            angle += 360.0;       // numbers outside of the range, but just to be safe we clamp them.

          X_current = X_probe_location - (X_PROBE_OFFSET_FROM_EXTRUDER) + cos(RADIANS(angle)) * radius;
          Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius;

          #if DISABLED(DELTA)
            X_current = constrain(X_current, X_MIN_POS, X_MAX_POS);
            Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS);
          #else
            // If we have gone out too far, we can do a simple fix and scale the numbers
            // back in closer to the origin.
            while (!position_is_reachable_by_probe(X_current, Y_current)) {
              X_current *= 0.8;
              Y_current *= 0.8;
              if (verbose_level > 3) {
                SERIAL_ECHOPAIR("Pulling point towards center:", X_current);
                SERIAL_ECHOLNPAIR(", ", Y_current);
              }
            }
          #endif
          if (verbose_level > 3) {
            SERIAL_ECHOPGM("Going to:");
            SERIAL_ECHOPAIR(" X", X_current);
            SERIAL_ECHOPAIR(" Y", Y_current);
            SERIAL_ECHOLNPAIR(" Z", current_position[Z_AXIS]);
          }
          do_blocking_move_to_xy(X_current, Y_current);
        } // n_legs loop
      } // n_legs

      // Probe a single point
      sample_set[n] = probe_pt(X_probe_location, Y_probe_location, raise_after, 0);

      // Break the loop if the probe fails
      probing_good = !isnan(sample_set[n]);
      if (!probing_good) break;

      /**
       * Get the current mean for the data points we have so far
       */
      float sum = 0.0;
      for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
      mean = sum / (n + 1);

      NOMORE(min, sample_set[n]);
      NOLESS(max, sample_set[n]);

      /**
       * Now, use that mean to calculate the standard deviation for the
       * data points we have so far
       */
      sum = 0.0;
      for (uint8_t j = 0; j <= n; j++)
        sum += sq(sample_set[j] - mean);

      sigma = SQRT(sum / (n + 1));
      if (verbose_level > 0) {
        if (verbose_level > 1) {
          SERIAL_ECHO(n + 1);
          SERIAL_ECHOPAIR(" of ", (int)n_samples);
          SERIAL_ECHOPAIR_F(": z: ", sample_set[n], 3);
          if (verbose_level > 2) {
            SERIAL_ECHOPAIR_F(" mean: ", mean, 4);
            SERIAL_ECHOPAIR_F(" sigma: ", sigma, 6);
            SERIAL_ECHOPAIR_F(" min: ", min, 3);
            SERIAL_ECHOPAIR_F(" max: ", max, 3);
            SERIAL_ECHOPAIR_F(" range: ", max-min, 3);
          }
          SERIAL_EOL();
        }
      }

    } // n_samples loop
  }

  STOW_PROBE();

  if (probing_good) {
    SERIAL_ECHOLNPGM("Finished!");

    if (verbose_level > 0) {
      SERIAL_ECHOPAIR_F("Mean: ", mean, 6);
      SERIAL_ECHOPAIR_F(" Min: ", min, 3);
      SERIAL_ECHOPAIR_F(" Max: ", max, 3);
      SERIAL_ECHOLNPAIR_F(" Range: ", max-min, 3);
    }

    SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6);
    SERIAL_EOL();
  }

  clean_up_after_endstop_or_probe_move();

  // Re-enable bed level correction if it had been on
  #if HAS_LEVELING
    set_bed_leveling_enabled(was_enabled);
  #endif

  report_current_position();
}
Exemple #30
0
Fichier : line.c Projet : kahrs/cda
selpt(Line *dl,Point p)
{
	int s,m,prop;
	Rectangle r;
	Line *l=dl;
	for (m = 0; l; l = l->next) {
		r = l->r;
		prop = 0;
		switch (l->type) {
		case LINE:
			if (EQ(p,P))
				l->sel = 3;
			else if (EQ(p,Q))
				l->sel = 12;
			else if (Y == p.y && Y == V && (p.x-X)*(U-p.x) > 0)
				prop = 1;
			else if (X == p.x && X == U && (p.y-Y)*(V-p.y) > 0)
				prop = 1;
			else
				continue;
			m |= (l->mod |= LINEHIT);
			if (prop) {
				l->sel = 15;
				m |= selbox(dl,canon(r));
			}
			break;
		case BOX:
		case MACRO:
			if (EQ(p,ul(r)))
				selborder(dl,l->sel=3,r);
			else if (EQ(p,lr(r)))
				selborder(dl,l->sel=12,r);
			else if (EQ(p,ll(r)))
				selborder(dl,l->sel=9,r);
			else if (EQ(p,ur(r)))
				selborder(dl,l->sel=6,r);
			else if (l->type == BOX && IN(p,r)) {
				l->sel = 15;
				m |= selbox(dl,r);
			}
			else
				continue;
			m |= (l->mod |= BOXHIT);
			break;
		case INST:
			if (WITHIN(p,r)) {
				l->sel = 15;
				m |= (l->mod |= BOXHIT) | selbox(dl,r);
			}
			break;	
		case DOTS:
			if (EQ(p,ul(r)))
				l->sel=3;
			else if (EQ(p,lr(r)))
				l->sel=12;
			else if (EQ(p,ll(r)))
				l->sel=9;
			else if (EQ(p,ur(r)))
				l->sel=6;
			else if (IN(p,r))
				l->sel = 15;
			else
				continue;
			m |= (l->mod |= DOTHIT);
			break;
		case STRING:
			if (EQ(p,P)) {
				l->sel = 3;
				m |= (l->mod |= STRHIT);
			}
			break;
		}
	}
	return m;
}