Ejemplo n.º 1
0
void	Algo::Pathfinding::initAlgo(thisData &data, const std::vector< ::Game::Map::Node *> &nodes, const Vector3d &from, const Vector3d &to, bool hardReinit) const {
  if (hardReinit) {
    data._data.clear();
    data._begin = NULL;
    data._target = NULL;
  }
  double v;
  double step = 1.0 / static_cast<double>(this->_map->precision);
  for (auto it : nodes) {
    if (it) {
      // Logger::getInstance()->logf("Pathfinding : %f <= %f <= %f", Logger::DEBUG, it->x, from.x, it->x + step);
      // Logger::getInstance()->logf("Pathfinding : %f <= %f <= %f", Logger::DEBUG, it->x, to.x, it->x + step);
      // Logger::getInstance()->logf("Pathfinding : %f <= %f <= %f", Logger::DEBUG, it->y, from.y, it->y + step);
      // Logger::getInstance()->logf("Pathfinding : %f <= %f <= %f", Logger::DEBUG, it->y, to.y, it->y + step);
      // Logger::getInstance()->log("", Logger::DEBUG);
      if (hardReinit && BETWEEN(it->x, from.x, it->x + step) && BETWEEN(it->y, from.y, it->y + step)) {
	data._begin = it;
      }
      if (hardReinit && BETWEEN(it->x, to.x, it->x + step) && BETWEEN(it->y, to.y, it->y + step)) {
	data._target = it;
      }
      v = INFINITE + DIST_NP(from, it);
      data._data[it].g = INFINITE;
      data._data[it].f = v;
      data._data[it].status = false;
      data._data[it].from = NULL;
    }
  }
  data._data[data._begin].g = 0;
  data._data[data._begin].f = data._data[data._begin].g + DIST_NN(from, to);
  data._data[data._begin].status = true;
}
Ejemplo n.º 2
0
Archivo: drw.c Proyecto: Dean4Devil/dwm
static size_t utf8validate(long *u, size_t i)
{
	if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
		*u = UTF_INVALID;
	for (i = 1; *u > utfmax[i]; ++i)
		;
	return i;
}
Ejemplo n.º 3
0
u32 secure_readl(void __iomem *c)
{
	if (BETWEEN(c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE))
		return __secure_readl(XLATE(c, MSM_MMSS_CLK_CTL_PHYS,
					MSM_MMSS_CLK_CTL_BASE));
	else if (BETWEEN(c, MSM_TCSR_BASE, MSM_TCSR_SIZE))
		return __secure_readl(XLATE(c, MSM_TCSR_PHYS, MSM_TCSR_BASE));
	return readl(c);
}
Ejemplo n.º 4
0
bool TRect::PtInRect(const TPoint &tPoint)
{
    l32 l32dx = tPoint.l32X - l32Left;
    l32 l32dy = tPoint.l32Y - l32Top;
    if (BETWEEN(l32dx, 0, l32Width) && BETWEEN(l32dy, 0, l32Height))
    {
        return true;
    }
    return false;
}
Ejemplo n.º 5
0
void secure_writel(u32 v, void __iomem *c)
{
	if (BETWEEN(c, MSM_MMSS_CLK_CTL_BASE, MSM_MMSS_CLK_CTL_SIZE))
		__secure_writel(v, XLATE(c, MSM_MMSS_CLK_CTL_PHYS,
					MSM_MMSS_CLK_CTL_BASE));
	else if (BETWEEN(c, MSM_TCSR_BASE, MSM_TCSR_SIZE))
		__secure_writel(v, XLATE(c, MSM_TCSR_PHYS, MSM_TCSR_BASE));
	else
		writel(v, c);
}
Ejemplo n.º 6
0
int G_GotoNextLevel(void)
{
  static byte doom2_next[32] = {
    2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
    12, 13, 14, 15, 31, 17, 18, 19, 20, 21,
    22, 23, 24, 25, 26, 27, 28, 29, 30, 1,
    32, 16
  };
  static byte doom_next[4][9] = {
    {12, 13, 19, 15, 16, 17, 18, 21, 14},
    {22, 23, 24, 25, 29, 27, 28, 31, 26},
    {32, 33, 34, 35, 36, 39, 38, 41, 37},
    {42, 49, 44, 45, 46, 47, 48, 11, 43}
  };

  int changed = false;

  // secret level
  doom2_next[14] = (haswolflevels ? 31 : 16);
  
  // shareware doom has only episode 1
  doom_next[0][7] = (gamemode == shareware ? 11 : 21);
  
  doom_next[2][7] = ((gamemode == registered) ||
    // the fourth episode for pre-ultimate complevels is not allowed.
    (compatibility_level < ultdoom_compatibility) ?
    11 : 41);
  
  if ((gamestate == GS_LEVEL) &&
      !deathmatch && !netgame &&
      !demorecording && !demoplayback &&
      !menuactive)
  {
    //doom2_next and doom_next are 0 biased, unlike gameepisode and gamemap
    int epsd = gameepisode - 1;
    int map = gamemap - 1;

    if (gamemode == commercial)
    {
      epsd = 1;
      map = doom2_next[BETWEEN(0, 31, map)];
    }
    else
    {
      int next = doom_next[BETWEEN(0, 3, epsd)][BETWEEN(0, 9, map)];
      epsd = next / 10;
      map = next % 10;
    }

    G_DeferedInitNew(gameskill, epsd, map);
    changed = true;
  }

  return changed;
}
Ejemplo n.º 7
0
void I_SDL_UpdateSoundParams(int handle, int vol, int sep)
{
    int         left, right;

    if (!sound_initialized || handle < 0 || handle >= NUM_CHANNELS)
        return;

    left = BETWEEN(0, (254 - sep) * vol / 127, 255);
    right = BETWEEN(0, sep * vol / 127, 255);

    Mix_SetPanning(handle, left, right);
}
Ejemplo n.º 8
0
static int check_init_constraints(unsigned page_size,
                                         unsigned mem_size,
                                         unsigned addr_space_size, 
                                         unsigned max_concurrent_operations)
{
    if (!(BETWEEN(MIN_PAGE_SIZE, MAX_PAGE_SIZE, page_size))) return ERROR;
    if (!(BETWEEN(MIN_MEM_SIZE, MAX_MEM_SIZE, mem_size))) return ERROR;
    if (!(BETWEEN(MIN_ADDR_SPACE_SIZE, MAX_ADDR_SPACE_SIZE, addr_space_size)))
        return ERROR;
    if (!(BETWEEN(MIN_MAX_CONCURRENT_OPERATIONS, MAX_MAX_CONCURRENT_OPERATIONS,
        max_concurrent_operations))) return ERROR;
    return SUCCESS;
}
Ejemplo n.º 9
0
bool CvCaptureCAM_Aravis::setProperty( int property_id, double value )
{
    switch ( property_id ) {
        case CV_CAP_PROP_EXPOSURE:
            if(exposureAvailable) {
                /* exposure time in seconds, like 1/100 s */
                value *= 1e6; // -> from s to us
                arv_camera_set_exposure_time(camera, exposure = BETWEEN(value, exposureMin, exposureMax));
                break;
            } else return false;

        case CV_CAP_PROP_FPS:
            if(fpsAvailable) {
                arv_camera_set_frame_rate(camera, fps = BETWEEN(value, fpsMin, fpsMax));
                break;
            } else return false;

        case CV_CAP_PROP_GAIN:
            if(gainAvailable) {
                arv_camera_set_gain(camera, gain = BETWEEN(value, gainMin, gainMax));
                break;
            } else return false;

        case CV_CAP_PROP_FOURCC:
            {
                ArvPixelFormat newFormat = pixelFormat;
                switch((int)value) {
                    case MODE_GRAY8:
                        newFormat = ARV_PIXEL_FORMAT_MONO_8;
                        break;
                    case MODE_GRAY12:
                        newFormat = ARV_PIXEL_FORMAT_MONO_12;
                        break;
                }
                if(newFormat != pixelFormat) {
                    stopCapture();
                    arv_camera_set_pixel_format(camera, pixelFormat = newFormat);
                    startCapture();
                }
            }
            break;

        default:
            return false;
    }

    return true;
}
Ejemplo n.º 10
0
/*
 * Intercept ioremap() requests for addresses in our fixed mapping regions.
 */
void __iomem *davinci_ioremap(unsigned long p, size_t size, unsigned int type)
{
	if (BETWEEN(p, IO_PHYS, IO_SIZE))
		return XLATE(p, IO_PHYS, IO_VIRT);

	return __arm_ioremap(p, size, type);
}
Ejemplo n.º 11
0
void get_send_timeout_count(const ComType com, const GetSendTimeoutCount *data) {
#ifdef BRICK_CAN_BE_MASTER
	if(data->communication_method > COM_WIFI2) {
#else
	if(data->communication_method > COM_SPI_STACK) {
#endif
		com_return_error(data, sizeof(GetSendTimeoutCountReturn), MESSAGE_ERROR_CODE_INVALID_PARAMETER, com);
		logblete("Communication Method %d does not exist (get_send_timeout_count)\n\r", data->communication_method);
		return;
	}

	GetSendTimeoutCountReturn gtcr;

	gtcr.header        = data->header;
	gtcr.header.length = sizeof(GetSendTimeoutCountReturn);
	gtcr.timeout_count = com_timeout_count[data->communication_method];

	send_blocking_with_timeout(&gtcr, sizeof(GetSendTimeoutCountReturn), com);
}

#ifdef BRICK_HAS_CO_MCU_SUPPORT
void set_spitfp_baudrate(const ComType com, const SetSPITFPBaudrate *data) {
	uint8_t port = tolower((uint8_t)data->bricklet_port) - 'a';
	if(port >= BRICKLET_NUM) {
		com_return_error(data, sizeof(GetSPITFPErrorCountReturn), MESSAGE_ERROR_CODE_INVALID_PARAMETER, com);
		logblete("Bricklet Port %d does not exist (set_spitfp_baudrate)\n\r", port);
		return;
	}

	if(bricklet_attached[port] == BRICKLET_INIT_CO_MCU) {
		bricklet_spitfp_baudrate[port] = BETWEEN(CO_MCU_MINIMUM_BAUDRATE, data->baudrate, CO_MCU_MAXIMUM_BAUDRATE);
	}

	com_return_setter(com, data);
}
Ejemplo n.º 12
0
void stepper_set_output_current(const uint16_t current) {
	Pin pin = PIN_PWR_DAC;
	const uint16_t new_current = BETWEEN(VREF_RES_MIN_CURRENT,
	                                     current,
	                                     VREF_MAX_CURRENT);

	if(new_current < VREF_RES_MAX_CURRENT) {
		pin.type = PIO_OUTPUT_0;
		pin.attribute = PIO_DEFAULT;
		PIO_Configure(&pin, 1);
		DACC_SetConversionData(DACC, SCALE(new_current,
		                                   VREF_RES_MIN_CURRENT,
	                                       VREF_RES_MAX_CURRENT,
	                                       VOLTAGE_MIN_VALUE,
	                                       VOLTAGE_MAX_VALUE));
	} else {
		DACC_SetConversionData(DACC, SCALE(new_current,
		                                   VREF_MIN_CURRENT,
	                                       VREF_MAX_CURRENT,
	                                       VOLTAGE_MIN_VALUE,
	                                       VOLTAGE_MAX_VALUE));
		pin.type = PIO_INPUT;;
		pin.attribute = PIO_DEFAULT;
		PIO_Configure(&pin, 1);
	}

	stepper_output_current = new_current;
}
Ejemplo n.º 13
0
fixed_t I_GetTimeFrac (void)
{
  unsigned long now;
  fixed_t frac;

  now = SDL_GetTicks();

  subframe++;

  if (tic_vars.step == 0)
  {
    frac = FRACUNIT;
  }
  else
  {
    extern int renderer_fps;
    if ((interpolation_method == 0) || (prevsubframe <= 0) || (renderer_fps <= 0))
    {
      frac = (fixed_t)((now - tic_vars.start + displaytime) * FRACUNIT / tic_vars.step);
    }
    else
    {
      frac = (fixed_t)((now - tic_vars.start) * FRACUNIT / tic_vars.step);
      frac = (unsigned int)((float)FRACUNIT * TICRATE * subframe / renderer_fps);
    }
    frac = BETWEEN(0, FRACUNIT, frac);
  }

  return frac;
}
Ejemplo n.º 14
0
void imu_blinkenlights(void) {
	if(!imu_use_leds) {
		return;
	}

	PWMC_SetDutyCycle(PWM, 0,
	                  blink_lookup[(BETWEEN(-1000, sensor_data.acc_x, 1000) +
	                                1000)/50]);
	PWMC_SetDutyCycle(PWM, 1,
	                  blink_lookup[(BETWEEN(-1000, sensor_data.acc_y, 1000) +
	                                1000)/50]);
	PWMC_SetDutyCycle(PWM, 2,
	                  blink_lookup[40 - (BETWEEN(-1000, sensor_data.acc_z, 1000) +
	                               1000)/50]);

	int16_t degree = sensor_data.eul_heading/16;
	if(degree < 0) {
		degree += 360;
	}

	if(degree < 90) {
		uint8_t index = degree * 40 / 90;
		TC0->TC_CHANNEL[0].TC_RA = blink_lookup[40-index];;
		TC0->TC_CHANNEL[1].TC_RA = 0;
		TC0->TC_CHANNEL[2].TC_RB = 0;
		PWMC_SetDutyCycle(PWM, 3, blink_lookup[40-index]);
	} else if(degree < 180) {
		uint8_t index = (degree - 90) * 40 / 90;
		TC0->TC_CHANNEL[0].TC_RA = blink_lookup[index];
		TC0->TC_CHANNEL[1].TC_RA = blink_lookup[40-index];
		TC0->TC_CHANNEL[2].TC_RB = 0;
		PWMC_SetDutyCycle(PWM, 3, 0);
	} else if(degree < 270) {
		uint8_t index = (degree - 180) * 40 / 90;
		TC0->TC_CHANNEL[0].TC_RA = 0;
		TC0->TC_CHANNEL[1].TC_RA = blink_lookup[index];
		TC0->TC_CHANNEL[2].TC_RB = blink_lookup[40-index];
		PWMC_SetDutyCycle(PWM, 3, 0);
	} else {
		uint8_t index = (degree - 270) * 40 / 90;
		TC0->TC_CHANNEL[0].TC_RA = 0;
		TC0->TC_CHANNEL[1].TC_RA = 0;
		TC0->TC_CHANNEL[2].TC_RB = blink_lookup[index];
		PWMC_SetDutyCycle(PWM, 3, blink_lookup[index]);
	}
}
Ejemplo n.º 15
0
point spline_at_y(splines *spl, int y)
{
	int i,j;
	double low, high, d, t;
	pointf c[4], pt2;
	point pt;
	static bezier bz;
	static splines *mem = NULL;

	if (mem != spl) {
		mem = spl;
		for (i = 0; i < spl->size; i++) {
			bz = spl->list[i];
			if (BETWEEN (bz.list[bz.size-1].y, y, bz.list[0].y))
				break;
		}
	}
	if (y > bz.list[0].y)
		pt = bz.list[0];
	else if (y < bz.list[bz.size-1].y)
		pt = bz.list[bz.size - 1];
	else {
		for (i = 0; i < bz.size; i += 3) {
			for (j = 0; j < 3; j++) {
				if ((bz.list[i+j].y <= y) && (y <= bz.list[i+j+1].y))
					break;
				if ((bz.list[i+j].y >= y) && (y >= bz.list[i+j+1].y))
					break;
			}
			if (j < 3)
				break;
		}
		assert (i < bz.size);
		for (j = 0; j < 4; j++) {
			c[j].x = bz.list[i + j].x;
			c[j].y = bz.list[i + j].y;
			/* make the spline be monotonic in Y, awful but it works for now */
			if ((j > 0) && (c[j].y > c[j - 1].y))
				c[j].y = c[j - 1].y;
		}
		low = 0.0; high = 1.0;
		do {
			t = (low + high) / 2.0;
			pt2 = Bezier (c, 3, t, NULL, NULL);
			d = pt2.y - y;
			if (ABS(d) <= 1)
				break;
			if (d < 0)
				high = t;
			else
				low = t;
		} while (1);
		pt.x = (int)pt2.x;
		pt.y = (int)pt2.y;
	}
	pt.y = y;
	return pt;
}
Ejemplo n.º 16
0
BOOL GameObject::isColliding(GameObject *object)
{
    assert(object != NULL);
    if (object != this)
    {
        if (object->getRoom() == getRoom())
        {
            RECT myRect,objectRect;
            getRect(&myRect);
            object->getRect(&objectRect);

            RECT newRect;

            // First get a rectangle that contains both rectangles here
            newRect.left   = (objectRect.left   < myRect.left   ? objectRect.left   : myRect.left);
            newRect.right  = (objectRect.right  > myRect.right  ? objectRect.right  : myRect.right);
            newRect.top    = (objectRect.top    < myRect.top    ? objectRect.top    : myRect.top);
            newRect.bottom = (objectRect.bottom > myRect.bottom ? objectRect.bottom : myRect.bottom);

            // now, traverse each point in that rectangle
            for (int row=newRect.top; row<newRect.bottom; row++)
            {
                // If this row is between the top/bottom of each object's rect
                if (BETWEEN(row,objectRect.top,objectRect.bottom) &&
                        BETWEEN(row,myRect.top,myRect.bottom) )
                {
                    for (int col=newRect.left; col<newRect.right; col++)
                    {
                        // If this column is between the top/bottom of each object's rect
                        // (which means that the x,y point col,row is within each object's rects)
                        if (BETWEEN(col,objectRect.left,objectRect.right) &&
                                BETWEEN(col,myRect.left,myRect.right) )
                        {
                            // See if the point is touching the object
                            if (object->isTouching(col,row) && isTouching(col,row))
                                return TRUE;
                        }
                    }
                }
            }
        }
    }

    return FALSE;
}
Ejemplo n.º 17
0
static int handle_menu(int x1, int y1)
{
    int x, y, a, i, j;

    /* scaled coordinates 0 - 999 */
    x = x1*1000/menubg->w;
    y = y1*1000/menubg->h;
    if (Y_REG(LINE2)) {
	for (i = 0; i < NUM_TATAMIS; i++) {
	    if (X_L(tatami_x[i])) {
		conf_tatamis[i] = !conf_tatamis[i];
		configured_tatamis = 0;

		for (j = 0; j < NUM_TATAMIS; j++)
		    if (conf_tatamis[j])
			configured_tatamis++;

		for (j = 0; j < NUM_TATAMIS; j++) {
		    if (configured_tatamis) show_tatami[j] = conf_tatamis[j];
		    else show_tatami[j] = match_list[j][1].blue && match_list[j][1].white;
		}

		return TRUE;
	    }
	}
    } else if (Y_REG(LINE3)) {
	if (X_R(R1) && display_type < 2) {
	    display_type++;
	    num_lines = numlines[display_type];
	    return TRUE;
	} else if (X_L(L1) && display_type > 0) {
	    display_type--;
	    num_lines = numlines[display_type];
	    return TRUE;
	}
    } else if (Y_REG(LINE4)) {
	if (X_R(R1) || X_L(L1))
	    red_background = !red_background;
	return TRUE;
    } else if (Y_REG(LINE5)) {
	if (X_R(L1))
	    mirror_display = !mirror_display;
	return TRUE;
    } else if (Y_REG(LINE7)) {
	if (BETWEEN(X0, X0_1)) {
	    emscripten_run_script("setfullscreen()");
	    menu_on = FALSE;
	    return TRUE;
	}
    } else if ( x > 38 && x < 119 && y > 840 && y < 960) {
	menu_on = FALSE;
	return TRUE;
    }

    return FALSE;
}
Ejemplo n.º 18
0
void
LKH::LKHAlg::Make4OptMove(Node * t1, Node * t2, Node * t3, Node * t4,
             Node * t5, Node * t6, Node * t7, Node * t8, int Case)
{
    if (SUC(t1) != t2)
        Reversed ^= 1;
    switch (Case) {
    case 1:
    case 2:
        Swap3(t1, t2, t3, t6, t5, t4, t7, t8, t1);
        return;
    case 3:
    case 4:
        Swap3(t1, t2, t3, t8, t7, t6, t5, t8, t1);
        return;
    case 5:
        if (!BETWEEN(t2, t7, t3))
            Swap3(t5, t6, t7, t2, t1, t4, t1, t4, t5);
        else if (BETWEEN(t2, t7, t6))
            Swap3(t5, t6, t7, t5, t8, t3, t3, t8, t1);
        else
            Swap3(t1, t2, t7, t7, t2, t3, t4, t7, t6);
        return;
    case 6:
        Swap3(t3, t4, t5, t6, t3, t2, t1, t6, t7);
        return;
    case 7:
        Swap3(t6, t5, t8, t2, t1, t4, t8, t5, t4);
        return;
    case 11:
        Swap3(t1, t2, t7, t3, t4, t5, t3, t6, t7);
        return;
    case 12:
        Swap3(t3, t4, t5, t7, t8, t1, t3, t6, t7);
        return;
    case 15:
        Swap3(t3, t4, t5, t3, t6, t7, t8, t3, t2);
        return;
    default:
        eprintf("Make4OptMove: Internal error");
    }
}
Ejemplo n.º 19
0
inline static const unsigned int count(const unsigned int &xmin, const unsigned int &xmax, const unsigned int &ymin, const unsigned int &ymax)
{
	unsigned int result = 0;
	for(unsigned int r = 0; r < rocks; ++ r)
	{
		if(BETWEEN(rock[r].x, xmin, xmax) && BETWEEN(rock[r].y, ymin, ymax))
			rock[r].moved = false;

		else if(BETWEEN(rock[r].y, xmin, xmax) && BETWEEN(rock[r].x, ymin, ymax))
		{
			rock[r].moved = true;
			result += rock[r].weight;
		}

		else
			return (1U << 31); // IMPOSSIBLE
	}

	return result;
}
Ejemplo n.º 20
0
void Px_SetPlaythrough( PxMixer *mixer, PxVolume volume ) {
   struct audio_info audio;
   PxInfo *info = (PxInfo *)mixer;
   if (ioctl(info->fd,AUDIO_GETINFO,&audio) < 0)  {
       return;
   }
   audio.monitor_gain =  AUDIO_MAX_GAIN * BETWEEN(0.0, (float)volume, 1.0);
   if (ioctl(info->fd,AUDIO_SETINFO,&audio) < 0)  {
       return;
   }
}
Ejemplo n.º 21
0
void Px_SetInputVolume( PxMixer *mixer, PxVolume volume ) {
   struct audio_info audio;
   PxInfo *info = (PxInfo *)mixer;
   if (ioctl(info->fd,AUDIO_GETINFO,&audio) < 0)  {
       return;
   }
   audio.record.gain =  AUDIO_MAX_GAIN * BETWEEN(0.0, (float)volume, 1.0);
   if (ioctl(info->fd,AUDIO_SETINFO,&audio) < 0)  {
       return;
   }
}
Ejemplo n.º 22
0
//Returns the new toolbar magnetization state accordingly to the current magnetization settings
WindowMagnetizer::MagnetizationState WindowMagnetizer::getNewMagnState(LPRECT tbRect)
{
	if(lockMagnState)
		return magnState;
	RECT mainWindowRect, toolbarRect; //Bounds of the two windows
	//Retrieve the bounds of the two windows
	GetWindowRect(mainWindow,&mainWindowRect);
	if(tbRect!=NULL)
		toolbarRect=*tbRect;
	else
		GetWindowRect(toolbar,&toolbarRect);
	magnOffset=toolbarRect.top-mainWindowRect.top;
	if(toolbarRect.top>mainWindowRect.bottom || toolbarRect.bottom<mainWindowRect.top)
		return WindowMagnetizer::NotMagnetized;
	else if(BETWEEN(mainWindowRect.left-toolbarRect.right,0,magnLimit))
		return WindowMagnetizer::OnLeftSide;
	else if(BETWEEN(toolbarRect.left-mainWindowRect.right,0,magnLimit))
		return WindowMagnetizer::OnRightSide;
	else
		return WindowMagnetizer::NotMagnetized;
}
Ejemplo n.º 23
0
void set_spitfp_baudrate_config(const ComType com, const SetSPITFPBaudrateConfig *data) {
	bricklet_spitfp_minimum_dynamic_baudrate = BETWEEN(CO_MCU_MINIMUM_BAUDRATE, data->minimum_dynamic_baudrate, CO_MCU_MAXIMUM_BAUDRATE);
	bricklet_spitfp_dynamic_baudrate_enabled = data->enable_dynamic_baudrate;

	// If we enable the dynamic baudrate, we start the dynamic approach with the default baudrate
	if(bricklet_spitfp_dynamic_baudrate_enabled) {
		bricklet_spitfp_baudrate_current = CO_MCU_DEFAULT_BAUDRATE;
	}

	com_return_setter(com, data);

	logbletd("set_spitfp_baudrate_config: %lu %d\n\r", bricklet_spitfp_minimum_dynamic_baudrate, bricklet_spitfp_dynamic_baudrate_enabled);
}
Ejemplo n.º 24
0
bool CDirList::IsTimeStamp(const wxString &s)
{
  bool bRtn = true;
  if(s.Len() != 15)
  {
    bRtn = false;
  }
  else if(s.GetChar(8) != '_')
  {
    bRtn = false;
  }
  else if(!nwxString::IsInteger(s.Left(8),false))
  {
    bRtn = false;
  }
  else if(!nwxString::IsInteger(s.Right(6),false))
  {
    bRtn = false;
  }
  else
  {
#define BETWEEN(n,min,max) ((n >= min) && (n <= max))

    int nY = atoi(s.Left(4).utf8_str());
    int nM = atoi(s.Mid(4,2).utf8_str());
    int nD = atoi(s.Mid(6,2).utf8_str());
    int nHH = atoi(s.Mid(9,2).utf8_str());
    int nMM = atoi(s.Mid(11,2).utf8_str());
    int nSS = atoi(s.Mid(13,2).utf8_str());
    // check year to see if newer than this software
    if( !BETWEEN(nY,2011,2099) )
    {
      bRtn = false;
    }
    else if( !BETWEEN(nM,1,12) )
    {
      bRtn = false;
    }
    else if( !BETWEEN(nD,1,MaxDayOfMonth(nY,nM)) )
    {
      bRtn = false;
    }
    else if( !BETWEEN(nHH,0,23) )
    {
      bRtn = false;
    }
    else if(! BETWEEN(nMM,0,59) )
    {
      bRtn = false;
    }
    else if(! BETWEEN(nSS,0,59) )
    {
      bRtn = false;
    }
  }
#undef BETWEEN
  return bRtn;
}
Ejemplo n.º 25
0
static void selscroll(struct st_term *term, int orig, int n)
{
	struct st_selection *sel = &term->sel;

	if (sel->type == SEL_NONE)
		return;

	if (BETWEEN(sel->p1.y, orig, term->bot) ||
	    BETWEEN(sel->p2.y, orig, term->bot)) {
		if ((sel->p1.y += n) > term->bot ||
		    (sel->p2.y += n) < term->top) {
			sel->type = SEL_NONE;
			return;
		}

		switch (sel->type) {
		case SEL_NONE:
			break;
		case SEL_REGULAR:
			if (sel->p1.y < term->top) {
				sel->p1.y = term->top;
				sel->p1.x = 0;
			}
			if (sel->p2.y > term->bot) {
				sel->p2.y = term->bot;
				sel->p2.x = term->size.y;
			}
			break;
		case SEL_RECTANGULAR:
			if (sel->p1.y < term->top)
				sel->p1.y = term->top;
			if (sel->p2.y > term->bot)
				sel->p2.y = term->bot;
			break;
		};
	}
}
Ejemplo n.º 26
0
int	parseSize(const char *str, t_game *game)
{
  int	i;
  int	j;
  int	row;
  int	col;
  char	*tmp;

  str += 11;
  i = 0;
  j = 0;
  while (str[i] && str[i] != ',' && ++i);
  if (!(tmp = malloc(sizeof(char) * (i + 1))))
    return (1);
  while (j < i && (tmp[j] = str[j]) && ++j);
  tmp[i] = '\0';
  str += ++i;
  if (!BETWEEN((row = my_getnbr(tmp)), MIN_ROW, MAX_ROW) ||
      !BETWEEN((col = my_getnbr(str)), MIN_COL, MAX_COL))
    return (free(tmp), write(2, "Incorrect size\n", 15), 1);
  game->height = row;
  game->width = col;
  return (free(tmp), 0);
}
Ejemplo n.º 27
0
int StatFilter::normalizeUrl(char *org, int iType, int portNum, char *normalized, int maxlen)
{
	int	urlleng = 0;
	char *pos=0, *dest=0;
	int	i=0;
	int	hasPort=0; // 원본 URL('org')이 포트 번호(':')를 포함하면 TURE
	while(1) {
		if (strncmp(org, "http://", 7)==0) org += 7;
		else break;
	}
	urlleng = strlen(org);
	for(pos = org+urlleng-1; *pos=='/'; pos--) {
		urlleng--;
	}

	dest = normalized;
	if (iType == FILTER_BY_DOMAIN) {
		strcpy(dest, "D ");
		dest += 2;
		maxlen -= 2;
	}

	if (urlleng > maxlen) urlleng = maxlen;

	for(pos=org,  i=0; i<urlleng; pos++, i++, dest++) {
		if (BETWEEN(*pos, 'A', 'Z'))
			*dest = *pos + 'a' - 'A';
		else
			*dest = *pos;
		if (*pos==':') hasPort = 1;
	}

	if (iType == FILTER_BY_DOMAIN && ! hasPort) {
	// 도메인에 포트번호가 없는 경우 디폴트 80 포트를 덧붙인다.
		if (portNum==0) portNum = 80;
		sprintf(dest, ":%d", portNum);
	}
	else {
		*dest = 0;
	}

	return urlleng;
}
Ejemplo n.º 28
0
int32_t current_from_analog_value(const int32_t value) {
    int32_t new_value = value;
    if(value > MAX_ADC_VALUE/4 && value < MAX_ADC_VALUE*3/4) {
        new_value += BC->offset;
    }

    BC->current_avg_sum += new_value;

    if(BC->tick % CURRENT_AVERAGE == 0) {
        BC->current_avg = BETWEEN(MIN_CURRENT,
                                  SCALE(BC->current_avg_sum/CURRENT_AVERAGE,
                                        0,
                                        MAX_ADC_VALUE,
                                        MIN_CURRENT_VALUE,
                                        MAX_CURRENT_VALUE),
                                  MAX_CURRENT);
        BC->current_avg_sum = 0;
    }

    return BC->current_avg;
}
Ejemplo n.º 29
0
Archivo: utf.c Proyecto: hadrianw/werf
size_t
utf8decode(const char *c, long *u, size_t clen)
{
	size_t i, j, len, type;
	long udecoded;

	*u = UTF_INVALID;
	if(!clen)
		return 0;
	udecoded = utf8decodebyte(c[0], &len);
	if(!BETWEEN(len, 1, UTF_SIZ))
		return 1;
	for(i = 1, j = 1; i < clen && j < len; ++i, ++j) {
		udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
		if(type != 0)
			return j;
	}
	if(j < len)
		return 0;
	*u = udecoded;
	utf8validate(u, len);
	return len;
}
Ejemplo n.º 30
0
rcolumn_t *R_GetPatchColumnClamped(rpatch_t *patch, int columnIndex)
{
    return &patch->columns[BETWEEN(0, columnIndex, patch->width - 1)];
}