Example #1
0
File: BA.c Project: kaisert/kilobot
static void compute_rseed()
{
    int16_t seed = 0;
    seed = (get_ambient_light() + measure_voltage()) * get_ambient_light();
    srand(seed);
    message_out(rand(), rand(), rand());
    get_message();
    seed += message_rx[0] + message_rx[1] * message_rx[2] + (message_rx[3] << 2);
    srand(seed);
    message_out(rand(), rand(), rand());
    get_message();
    seed += message_rx[0] - message_rx[1] * message_rx[2] + (message_rx[3] << 2);
    srand(seed);
}
Example #2
0
static inline int measure_capacity(void)
{
	int val, tmp;
	tmp = measure_voltage();
	if((tmp>4200000) || (get_charge_status() == 0x1))
	{
		printf("%s: get from PMU and adc is 100.\n", __FUNCTION__);
		return 100;
	}
	
	val = (tmp - 3600000) / (600000 / 100);
	printf("%s: get from adc is %d.\n", __FUNCTION__, val);
	return val;
}
Example #3
0
void measurements_task(void)
{
	if (G_voltage_Measurement_s >= VOLTAGE_MEASUREMENT_PERIOD)
	{
		G_voltage_Measurement_s = 0;
			
		if(G_voltage_measurement_Buff.index >= VOLTAGE_MEASUREMENT_BUFF_SIZE)
		{
			G_voltage_measurement_Buff.index = 0;
		}
	
		G_voltage_measurement_Buff.buff[G_voltage_measurement_Buff.index] = measure_voltage();
		G_voltage_measurement_Buff.index++;
		
		if(!(G_voltage_measurement_Buff.length >= VOLTAGE_MEASUREMENT_BUFF_SIZE))
			G_voltage_measurement_Buff.length++;
	}
	if (G_windAngle_measurement_s >= WIND_ANGLE_MEASUREMENT_PERIOD)
	{//kai sitie buferiai persipildo juos nunulina control task
		G_windAngle_measurement_s = 0;
		
		if(G_WindAngle_Buff.index >= WIND_ANGLE_BUFF_SIZE)
		{
			G_WindAngle_Buff.index = 0;
		}
		
		G_WindAngle_Buff.buff[G_voltage_measurement_Buff.index] = measure_windAngle();
		G_WindAngle_Buff.index++;
		
		if(!(G_WindAngle_Buff.length >= VOLTAGE_MEASUREMENT_BUFF_SIZE))
			G_WindAngle_Buff.length++;
		
	}
	//matavaimai bus atliekami pertrauktimi, pasinaudojus kitu taimeriu
	if (G_windSpeed_measurement_s >= WIND_SPEED_MEASUREMENT_PERIOD)
	{
		G_windSpeed_measurement_s = 0;
		if(G_WindSpeed_Buff.index >= WIND_ANGLE_BUFF_SIZE)
		{
			G_WindSpeed_Buff.index = 0;
		}
		
		G_WindSpeed_Buff.buff[G_voltage_measurement_Buff.index] = G_anemometer_freq_s;
		G_WindSpeed_Buff.index++;
		
		if(!(G_WindSpeed_Buff.length >= VOLTAGE_MEASUREMENT_BUFF_SIZE))
			G_WindSpeed_Buff.length++;
		//TODO: implement
	}
}