Exemple #1
0
void gui_set_vario_init()
{
    gui_list_set(gui_set_vario_item, gui_set_vario_action, 7, GUI_SETTINGS);

    set_vario_digital = eeprom_read_float(&config.vario.digital_vario_dampening);
    set_vario_avg = eeprom_read_float(&config.vario.avg_vario_dampening);
}
Exemple #2
0
void r3d2_init(void)
{
	NOTICE(0,"Initializing timer");
	// initialise timer used to get ticks of sensor detection and motor rotation
	timer_init();

	NOTICE(0,"timer1 starting");
	timer1_start();
	
	// initialise port to power on and get signal of the sensor 
	NOTICE(0,"Initializing sensor");	
	init_sensor();
	
	// power on the motor that drive the mirror
	NOTICE(0,"Initializing motor");
	motor_init();

	// first there is no robot detected, neither motor error
	robot_detected_value = robot_not_detected;
	motor_error_value = no_motor_error;

	robot_detected_timout_treshold = eeprom_read_byte(&eep_robot_detected_timout_treshold);
	surface_reflection_ratio = eeprom_read_float((float*)&eep_surface_reflection_ratio);
	robot_detected_angle_offset = eeprom_read_float((float*)&eep_robot_detected_angle_offset); 
	motor_rotating_timout_treshold = eeprom_read_byte(&eep_motor_rotating_timout_treshold);

	motor_rotating_timout_value = motor_rotating_timout_treshold;
	robot_detected_timout_value = 0;
}
	void init ()
	{
		min_cell_voltage = eeprom_read_float (TELEMETRY_EEPROM_MIN_CELL_VOLTAGE);
		nom_cell_voltage = eeprom_read_float (TELEMETRY_EEPROM_NOM_CELL_VOLTAGE);
		max_cell_voltage = eeprom_read_float (TELEMETRY_EEPROM_MAX_CELL_VOLTAGE);
		low_cell_voltage = eeprom_read_float (TELEMETRY_EEPROM_LOW_VOLTAGE);
		_cell_range = max_cell_voltage - min_cell_voltage;
	}
void init ()
{
	_current_sensor = eeprom_read_byte (ADC_BATTERY_EEPROM_CURRENT_SENSOR);
	_voltage_multiplier = eeprom_read_float (ADC_BATTERY_EEPROM_VOLTAGE_MULTIPLIER);
	if (_current_sensor)
		_current_multiplier = eeprom_read_float (ADC_BATTERY_EEPROM_CURRENT_MULTIPLIER);
	_interval = eeprom_read_word (ADC_BATTERY_EEPROM_UPDATE_INTERVAL);
	_voltage_channel = eeprom_read_byte (ADC_BATTERY_EEPROM_VOLTAGE_CHANNEL);
	_current_channel = eeprom_read_byte (ADC_BATTERY_EEPROM_CURRENT_CHANNEL);
}
Exemple #5
0
/**
 * Initialize PID controller and read settings from EEPROM
 */
void pid_init(void) {
#ifdef EEPROM_AVAILABLE
    /* Read vars from EEPROM */
    pid_p = eeprom_read_float(&ee_pid_p);
    pid_i = eeprom_read_float(&ee_pid_i);
    pid_d = eeprom_read_float(&ee_pid_d);
    pid_max_error_sum = eeprom_read_float(&ee_pid_max_error_sum);
    pid_error_cap = eeprom_read_float(&ee_pid_error_cap);
#endif /* EEPROM_AVAILABLE */
}
static void lcd_menu_change_material_select_material_details_callback(uint8_t nr)
{
    char buffer[32];
    char* c = buffer;

    if (led_glow_dir)
    {
        c = float_to_string(eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(nr)), c, PSTR("mm"));
        while(c < buffer + 10) *c++ = ' ';
        strcpy_P(c, PSTR("Flow:"));
        c += 5;
        c = int_to_string(eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(nr)), c, PSTR("%"));
    }else{
        c = int_to_string(eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(nr)), c, PSTR("C"));
#if TEMP_SENSOR_BED != 0
        *c++ = ' ';
        c = int_to_string(eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(nr)), c, PSTR("C"));
#endif
        while(c < buffer + 10) *c++ = ' ';
        strcpy_P(c, PSTR("Fan: "));
        c += 5;
        c = int_to_string(eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(nr)), c, PSTR("%"));
    }
    lcd_lib_draw_string(5, 53, buffer);
}
void lcd_material_set_material(uint8_t nr, uint8_t e)
{
    material[e].temperature = eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(nr));
#if TEMP_SENSOR_BED != 0
    material[e].bed_temperature = eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(nr));
#endif
    material[e].flow = eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(nr));

    material[e].fan_speed = eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(nr));
    material[e].diameter = eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(nr));
    eeprom_read_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(nr), 8);
    card.longFilename[8] = '\0';
    if (material[e].temperature > HEATER_0_MAXTEMP - 15)
        material[e].temperature = HEATER_0_MAXTEMP - 15;
#if TEMP_SENSOR_BED != 0
    if (material[e].bed_temperature > BED_MAXTEMP - 15)
        material[e].bed_temperature = BED_MAXTEMP - 15;
#endif
    material[e].change_temperature = eeprom_read_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(nr));
    material[e].change_preheat_wait_time = eeprom_read_byte(EEPROM_MATERIAL_CHANGE_WAIT_TIME(nr));
    if (material[e].change_temperature < 10)
        material[e].change_temperature = material[e].temperature;

    lcd_material_store_current_material();
}
Exemple #8
0
/**Returns the internal temperature if the device in degrees C*10000. (ex: 23.4567 would return 234567)
*
*	Note: The returned value should never be larger than 24 bits. It can probably be stored in a 24 bit number in the dataflash to save space.
*	TODO: Add a check to make sure the calibration data exsists
*/
int32_t AD7794GetInternalTemp(void)
{
	uint8_t SendData[2];
	uint32_t ADCData = 0;

	double slope;
	double intercept;
	double InternalTemp;
	//char OutputString[20];
	
	slope = 0.0001721912F;		//Deg C/count
	intercept = eeprom_read_float(&NV_AD7794_INTERNAL_TEMP_CAL);
	
	//Set up internal temperature
	//	-Unipolar
	//	-Gain of 1
	//	-Internal 1.17V reference
	//	-Buffered
	SendData[1] = (AD7794_CRH_UNIPOLAR|AD7794_CRH_GAIN_1);
	SendData[0] = (AD7794_CRL_REF_INT|AD7794_CRL_REF_DETECT|AD7794_CRL_BUFFER_ON|AD7794_CRL_CHANNEL_TEMP);
	AD7794WriteReg(AD7794_CR_REG_CONFIG, SendData);
	SendData[1] = AD7794_MRH_MODE_SINGLE;
	SendData[0] = (AD7794_MRL_CLK_INT_NOOUT | AD7794_MRL_UPDATE_RATE_10_HZ);
	AD7794WriteReg(AD7794_CR_REG_MODE, SendData);
	AD7794WaitReady();
	ADCData = AD7794GetData();
	
	InternalTemp = slope*(double)ADCData + intercept;
	
	//dtostrf(InternalTemp, 9, 4, OutputString);
	//printf_P(PSTR("Internal temperature is: %s C\n"), OutputString);
	
	return ((int32_t)(InternalTemp*10000.0F));
}
static void lcd_material_select_details_callback(uint8_t nr)
{
    uint8_t count = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    if (nr == 0)
    {
        
    }
    else if (nr <= count)
    {
        char buffer[32];
        char* c = buffer;
        nr -= 1;
        
        if (led_glow_dir)
        {
            c = float_to_string(eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(nr)), c, PSTR("mm"));
            while(c < buffer + 10) *c++ = ' ';
            strcpy_P(c, PSTR("Flow:"));
            c += 5;
            c = int_to_string(eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(nr)), c, PSTR("%"));
        }else{
            c = int_to_string(eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(nr)), c, PSTR("C"));
            *c++ = ' ';
            c = int_to_string(eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(nr)), c, PSTR("C"));
            while(c < buffer + 10) *c++ = ' ';
            strcpy_P(c, PSTR("Fan: "));
            c += 5;
            c = int_to_string(eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(nr)), c, PSTR("%"));
        }
        lcd_lib_draw_string(5, 53, buffer);
    }else{
        lcd_lib_draw_string_centerP(53, PSTR("Modify the settings"));
    }
}
Exemple #10
0
void init ()
{
	_ref = eeprom_read_byte (ADC_EEPROM_REF) << 6;
	_ref_voltage = eeprom_read_float (ADC_EEPROM_REF_VOLTAGE);

	ADMUX = _ref;
	ADCSRA |= _BV (ADEN) | _BV (ADPS0) | _BV (ADPS1) | _BV (ADPS2);
}
Exemple #11
0
static int eeprom_read_reference_voltage(float *val)
{
	unsigned address;

	eeprom_get_calibration_base_address(&address);
	eeprom_read_float(address + eeprom.voltage_ref_offset, val);

	return 0;
}
static void ReadCalibrationValues ( void )
{
	//printf("reading calibration constants from EEPROM\n");
	uint8_t signature = eeprom_read_byte((uint8_t*)(CALIBRATION_EEPROM_BASE + CALIBRATION_SIGNATURE_LOCATION));
	if (signature == CALIBRATION_SIGNATURE) {
		calibrationFloor = eeprom_read_float((float*)(CALIBRATION_EEPROM_BASE + CALIBRATION_FLOOR_LOCATION));
		calibrationScale = eeprom_read_float((float*)(CALIBRATION_EEPROM_BASE + CALIBRATION_SCALE_LOCATION));
	} else {
		//printf("Calibration signature doesn't match - using default values\n");
		calibrationFloor = 255.0;
		calibrationScale = 3.1909;
	}
	//char output[16];
	//dtostrf(calibrationFloor, 7, 4, output);
	//printf("FLOOR: %s\n", output);
	//dtostrf(calibrationScale, 7, 4, output);
	//printf("SCALE: %s\n", output);
}
static void ReadCompensationFlag ( void )
{
	compensation = eeprom_read_byte((uint16_t*)(CALIBRATION_EEPROM_BASE + COMPENSATION_FLAG_LOCATION));
	if (compensation == 0 || compensation == 1) {
		baselineVoltage = eeprom_read_float((float*)(CALIBRATION_EEPROM_BASE + BASELINE_VOLTAGE_LOCATION));
	} else {
		baselineVoltage = 4.2;
	}
}
bool lcd_material_verify_material_settings()
{
    SERIAL_ECHO_START;
    uint8_t max_mats = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    SERIAL_ECHOPAIR("Checking ", (unsigned long) max_mats);
    SERIAL_ECHOPAIR(" presets and ", (unsigned long)  EXTRUDERS);
    SERIAL_ECHOLNPGM (" extruder settings:");

    if (max_mats < 2 || max_mats > EEPROM_MATERIAL_SETTINGS_MAX_COUNT)
        return false;
    byte cnt =0;
    while(cnt < max_mats+EXTRUDERS)
        {
            SERIAL_ECHOPAIR("Checking preset # ",(unsigned long) cnt);
            if (eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt)) > HEATER_0_MAXTEMP)
                return false;
            if (eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt)) > BED_MAXTEMP)
                return false;
            if (eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt)) > 100)
                return false;
            if (eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt)) > 1000)
                return false;
            if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) > 10.0)
                return false;
            if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) < 0.1)
                return false;
            strcpy_P (material_name_buf,"???");
            eeprom_read_block(material_name_buf, EEPROM_MATERIAL_NAME_OFFSET(cnt), MATERIAL_NAME_LENGTH);
            material_name_buf[MATERIAL_NAME_LENGTH] = '\0';

            if (cnt >= max_mats )
                { SERIAL_ECHOPAIR(".....verified extruder setting # ",(unsigned long) cnt-max_mats);}
            else
                { SERIAL_ECHOPAIR(".....verified preset # ",(unsigned long) cnt);}
            SERIAL_ECHO(" (");
            SERIAL_ECHO(material_name_buf);

            SERIAL_ECHO(")");
            SERIAL_ECHOLN("");
            cnt++;
        }
    return true;
}
bool lcd_material_verify_material_settings()
{
    bool hasUPET = false;
    
    uint8_t cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    if (cnt < 2 || cnt > EEPROM_MATERIAL_SETTINGS_MAX_COUNT)
        return false;
    while(cnt > 0)
    {
        cnt --;
        if (eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt)) > HEATER_0_MAXTEMP)
            return false;
//        if (eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt)) > BED_MAXTEMP)
//            return false;
        if (eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt)) > 100)
            return false;
        if (eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt)) > 1000)
            return false;
        if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) > 10.0)
            return false;
        if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) < 0.1)
            return false;

        eeprom_read_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 8);
        if (strcmp_P(card.longFilename, PSTR("UPET")) == 0)
            hasUPET = true;
    }
    cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    if (!hasUPET && cnt < EEPROM_MATERIAL_SETTINGS_MAX_COUNT)
    {
        strcpy_P(card.longFilename, PSTR("UPET"));
        eeprom_write_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 5);
        eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt), 250);
//        eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt), 60);
        eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt), 50);
        eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt), 100);
        eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt), 2.85);
        
        eeprom_write_byte(EEPROM_MATERIAL_COUNT_OFFSET(), cnt + 1);
    }
    return true;
}
void lcd_material_read_current_material()
{
    for(uint8_t e=0; e<EXTRUDERS; e++)
    {
        material[e].temperature = eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        material[e].bed_temperature = eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        material[e].flow = eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));

        material[e].fan_speed = eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        material[e].diameter = eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
    }
}
//Загружаем в Holding Registers и в массив параметров значения из EEPROM
void ModbusInitValues()
{	
	for(uint8_t i = 0; i < coeff_list_SIZE; i++)
	{
		coeffs[i].value = eeprom_read_float((float*)(4 * i));
	}
	
	for (uint8_t i = 0; i < coeff_list_SIZE; i++)
	{
		usRegHoldingBuf[2 * i + MB_OFFSET + MB_Kp_Oz] = coeffs[i].array[0];
		usRegHoldingBuf[2 * i + MB_OFFSET + MB_Kp_Oz + 1] = coeffs[i].array[1];
	}
}
Exemple #18
0
static void eepromUpdateFloatSafe(float *eepromVariable, float *shadowVariable, float newValue)
{
	float readValue;
	eeprom_busy_wait();
	eeprom_update_float(eepromVariable, newValue);
	printf("EEPROM written\n");
	eeprom_busy_wait();
	readValue = eeprom_read_float(eepromVariable);
	if (readValue != newValue) {
		eepromCorrupt();
	} else {
		*shadowVariable = newValue;
	}
}
bool lcd_material_verify_material_settings()
{
    uint8_t cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    if (cnt < 2 || cnt > 16)
        return false;
    while(cnt > 0)
    {
        cnt --;
        if (eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt)) > HEATER_0_MAXTEMP)
            return false;
        if (eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt)) > BED_MAXTEMP)
            return false;
        if (eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt)) > 100)
            return false;
        if (eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt)) > 1000)
            return false;
        if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) > 10.0)
            return false;
        if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) < 0.1)
            return false;
    }
    return true;
}
Exemple #20
0
void Settings1()
{
	displayMode = SETTINGS1;
	displayValue = (uint16_t)(savedParametersList[HIGH_LIM] * 100);
	
	uint8_t pressCounter = 0;
	
	while(bit_is_set(PINC, MODE_BUTTON))
	{}
	
	_delay_ms(100);
	
	while(bit_is_clear(PINC, MODE_BUTTON))
	{
		if (bit_is_set(PINC, SET_BUTTON))
		{
			pressCounter++;
			if(savedParametersList[HIGH_LIM] < 0.99)
				savedParametersList[HIGH_LIM] += 0.01;
			else
				savedParametersList[HIGH_LIM] = 0.00;
		}
		else
		{
			pressCounter = 0;
		}
		
		if (pressCounter < 10)
		{
			_delay_ms(500);
		} 
		else
		{
			_delay_ms(100);
		}
		
		displayValue = (uint16_t)(savedParametersList[HIGH_LIM] * 100);
	}
		
	if (eeprom_read_float((float*)(HIGH_LIM * 4)) != savedParametersList[HIGH_LIM])
	{
		eeprom_write_float((float*)(HIGH_LIM * 4), savedParametersList[HIGH_LIM]);
	}
		
	Settings2();
	
	while(bit_is_set(PINC, MODE_BUTTON))
	{}
}
Exemple #21
0
int main(void)
{
	DDRB = 0x00;
	char eeprom_text[6];
	
	eeprom_read_block(eeprom_text, &text, 6);

	if(eeprom_read_word(&word) == 0xDEAD && 
	   eeprom_read_float(&flotante) == 5.55 && 
	   strcmp(eeprom_text, "Texto") == 0)
		PORTB = 1;

	
	while(1)
	{}
}
void calibration_load(void)
{
    if (eeprom_read_byte(&nv_cal_check) == 'c') {
        ox = eeprom_read_float(&nv_ox);
        oy = eeprom_read_float(&nv_oy);
        oz = eeprom_read_float(&nv_oz);
        sx = eeprom_read_float(&nv_sx);
        sy = eeprom_read_float(&nv_sy);
        sz = eeprom_read_float(&nv_sz);
    }
}
void lcd_material_set_material(uint8_t nr, uint8_t e)
{
    material[e].temperature = eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(nr));
    material[e].bed_temperature = eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(nr));
    material[e].flow = eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(nr));

    material[e].fan_speed = eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(nr));
    material[e].diameter = eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(nr));
    eeprom_read_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(nr), 8);
    card.longFilename[8] = '\0';
    if (material[e].temperature > HEATER_0_MAXTEMP - 15)
        material[e].temperature = HEATER_0_MAXTEMP - 15;
    if (material[e].bed_temperature > BED_MAXTEMP - 15)
        material[e].bed_temperature = BED_MAXTEMP - 15;
    
    lcd_material_store_current_material();
}
Exemple #24
0
/**Calibrates the internal temperature sensor. This function assumes that the internal temperature sensor will be read in unipolar mode with the internal 1.17V reference.
*
*	CurrentTemp The current temperature of the device. This value should be entered as 10000 times the temperature in C. EX: 25.4812C would be 254812.
*	
*	Note: NV_AD7794_INTERNAL_TEMP_CAL is the zero intercept of the temperature calibration. The slope is given in the datasheet.
*/
uint8_t AD7794InternalTempCal(uint32_t CurrentTemp)
{
	uint8_t i;
	uint8_t SendData[2];
	uint32_t RunningSum = 0;
	
	double cal;
	double slope;
	double intercept;
	double TempInput;
	char OutputString[15];
	
	slope = 0.0001721912F;		//Deg C/count
	TempInput = (double)CurrentTemp/10000.0F;
	
	cal = eeprom_read_float(&NV_AD7794_INTERNAL_TEMP_CAL);
	dtostrf(cal, 9, 4, OutputString);
	printf_P(PSTR("Current calibrated zero is: %s\n"), OutputString);
	printf_P(PSTR("Taking 10 readings from internal temperature sensor...\n"));
	
	//Measure internal temperature
	SendData[1] = (AD7794_CRH_UNIPOLAR|AD7794_CRH_GAIN_1);
	SendData[0] = (AD7794_CRL_REF_INT|AD7794_CRL_REF_DETECT|AD7794_CRL_BUFFER_ON|AD7794_CRL_CHANNEL_TEMP);
	AD7794WriteReg(AD7794_CR_REG_CONFIG, SendData);
	SendData[1] = AD7794_MRH_MODE_CONTINUOUS;
	SendData[0] = (AD7794_MRL_CLK_INT_NOOUT | AD7794_MRL_UPDATE_RATE_10_HZ);
	AD7794WriteReg(AD7794_CR_REG_MODE, SendData);
	
	for(i=0;i<10;i++)
	{
		AD7794WaitReady();
		RunningSum += AD7794GetData();
		
	}

	RunningSum = RunningSum/i;
	printf_P(PSTR("Internal Temperature: %lu counts\n"), RunningSum);
	
	intercept = TempInput - slope*(double)RunningSum;
	dtostrf(intercept, 9, 4, OutputString);
	printf_P(PSTR("New calibration is: %s\n"), OutputString);
	
	//eeprom_update_block((const void *)&TempCalArray, (void *)NV_AD7794_INTERNAL_TEMP_CAL, 3);
	eeprom_update_float(&NV_AD7794_INTERNAL_TEMP_CAL, intercept);
	return 0;
}
void lcd_material_read_current_material()
{
    for(uint8_t e=0; e<EXTRUDERS; e++)
        {
            material[e].temperature = eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
            material[e].bed_temperature = eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
            material[e].flow = eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));

            material[e].fan_speed = eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
            material[e].diameter = eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
            strcpy_P(material_name[e],PSTR("???"));

            eeprom_read_block(material_name[e], EEPROM_MATERIAL_NAME_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e), MATERIAL_NAME_LENGTH);
            material_name[e][MATERIAL_NAME_LENGTH] = '\0';

        }
}
Exemple #26
0
void menuInit()
{
	// Initialize all shadow variables
	eepromShadowIsPlatformDown = eeprom_read_byte(&eepromIsPlatformDown);
	eepromShadowCurrentProfile = eeprom_read_byte(&eepromCurrentProfile);
	if (eepromShadowCurrentProfile >= PROFILE_COUNT) {
		eepromCorrupt();
	}
	eepromShadowMenuState = eeprom_read_byte(&eepromMenuState);
	eeprom_read_block(currentProfileName, eepromProfileName[eepromShadowCurrentProfile], LCD_NUM_CHARACTERS+1);

	eepromShadowFwdThrow = eeprom_read_float(&eepromFwdThrow[eepromShadowCurrentProfile]);
	eepromShadowOverrideFwdThrow = eeprom_read_float(&eepromFwdThrow[PROFILE_COUNT-1]);

	eepromShadowRevThrow = eeprom_read_float(&eepromRevThrow[eepromShadowCurrentProfile]);
	eepromShadowOverrideRevThrow = eeprom_read_float(&eepromRevThrow[PROFILE_COUNT-1]);

	eepromShadowTurnThrow = eeprom_read_float(&eepromTurnThrow[eepromShadowCurrentProfile]);
	eepromShadowOverrideTurnThrow = eeprom_read_float(&eepromTurnThrow[PROFILE_COUNT-1]);

	eepromShadowTopFwdSpeed = eeprom_read_byte(&eepromTopFwdSpeed[eepromShadowCurrentProfile]);
	eepromShadowOverrideTopFwdSpeed = eeprom_read_byte(&eepromTopFwdSpeed[PROFILE_COUNT-1]);

	eepromShadowTopRevSpeed = eeprom_read_byte(&eepromTopRevSpeed[eepromShadowCurrentProfile]);
	eepromShadowOverrideTopRevSpeed = eeprom_read_byte(&eepromTopRevSpeed[PROFILE_COUNT-1]);

	eepromShadowTopTurnSpeed = eeprom_read_byte(&eepromTopTurnSpeed[eepromShadowCurrentProfile]);
	eepromShadowOverrideTopTurnSpeed = eeprom_read_byte(&eepromTopTurnSpeed[PROFILE_COUNT-1]);

	eepromShadowSensitivity = eeprom_read_byte(&eepromSensitivity[eepromShadowCurrentProfile]);
	if (eepromShadowSensitivity >= 10) {
		eepromCorrupt();
	}
	eepromShadowOverrideSensitivity = eeprom_read_byte(&eepromSensitivity[PROFILE_COUNT-1]);

	eepromShadowAcceleration = eeprom_read_byte(&eepromAcceleration[eepromShadowCurrentProfile]);
	eepromShadowOverrideAcceleration = eeprom_read_byte(&eepromAcceleration[PROFILE_COUNT-1]);

	eepromShadowDeceleration = eeprom_read_byte(&eepromDeceleration[eepromShadowCurrentProfile]);
	eepromShadowOverrideDeceleration = eeprom_read_byte(&eepromDeceleration[PROFILE_COUNT-1]);

	eepromShadowOuterDeadBand = eeprom_read_byte(&eepromOuterDeadBand[eepromShadowCurrentProfile]);
	eepromShadowOverrideOuterDeadBand = eeprom_read_byte(&eepromOuterDeadBand[PROFILE_COUNT-1]);

	eepromShadowCenterDeadBand = eeprom_read_byte(&eepromCenterDeadBand[eepromShadowCurrentProfile]);
	eepromShadowOverrideCenterDeadBand = eeprom_read_byte(&eepromCenterDeadBand[PROFILE_COUNT-1]);

	eepromShadowPropAsSwitch = eeprom_read_byte(&eepromPropAsSwitch[eepromShadowCurrentProfile]);
	eepromShadowOverridePropAsSwitch = eeprom_read_byte(&eepromPropAsSwitch[PROFILE_COUNT-1]);

	eepromShadowInvert = eeprom_read_byte(&eepromInvert[eepromShadowCurrentProfile]);
	eepromShadowOverrideInvert = eeprom_read_byte(&eepromInvert[PROFILE_COUNT-1]);
}
/*	loadReference: It loads the coefficients of the approximation for temperature
 * 				   dependance from the EEPROM in variables coefX2, coefY2, coefZ2,
 * 				   coefX, coefY, coefZ, constX, constY and constZ
 *	Parameters:	void
 *  Return:		void
 * 	
 */
void	WaspSensorParking::loadReference(void)
{
	int address;

	address = PARKING_ADDRESS_COEFX2;
	coefX2 = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_COEFY2;
	coefY2 = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_COEFZ2;
	coefZ2 = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_COEFX;
	coefX = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_COEFY;
	coefY = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_COEFZ;
	coefZ = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_CONSTX;
	constX = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_CONSTY;
	constY = eeprom_read_float((float*)(address));
	address = PARKING_ADDRESS_CONSTZ;
	constZ = eeprom_read_float((float*)(address));
}
void lcd_material_read_current_material()
{
    for(uint8_t e=0; e<EXTRUDERS; e++)
    {
        material[e].temperature = eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
#if TEMP_SENSOR_BED != 0
        material[e].bed_temperature = eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
#endif
        material[e].flow = eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));

        material[e].fan_speed = eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        material[e].diameter = eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        
        material[e].change_temperature = eeprom_read_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        material[e].change_preheat_wait_time = eeprom_read_byte(EEPROM_MATERIAL_CHANGE_WAIT_TIME(EEPROM_MATERIAL_SETTINGS_MAX_COUNT+e));
        if (material[e].change_temperature < 10)
            material[e].change_temperature = material[e].temperature;
    }
}
static void lcd_menu_material_export()
{
    if (!card.sdInserted)
    {
        LED_GLOW();
        lcd_lib_encoder_pos = MAIN_MENU_ITEM_POS(0);
        lcd_info_screen(lcd_menu_material_select);
        lcd_lib_draw_string_centerP(15, PSTR("No SD-CARD!"));
        lcd_lib_draw_string_centerP(25, PSTR("Please insert card"));
        lcd_lib_update_screen();
        card.release();
        return;
    }
    if (!card.isOk())
    {
        lcd_info_screen(lcd_menu_material_select);
        lcd_lib_draw_string_centerP(16, PSTR("Reading card..."));
        lcd_lib_update_screen();
        card.initsd();
        return;
    }

    card.setroot();
    card.openFile("MATERIAL.TXT", false);
    uint8_t count = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    for(uint8_t n=0; n<count; n++)
    {
        char buffer[32];
        strcpy_P(buffer, PSTR("[material]\n"));
        card.write_string(buffer);

        strcpy_P(buffer, PSTR("name="));
        char* ptr = buffer + strlen(buffer);
        eeprom_read_block(ptr, EEPROM_MATERIAL_NAME_OFFSET(n), 8);
        ptr[8] = '\0';
        strcat_P(buffer, PSTR("\n"));
        card.write_string(buffer);

        strcpy_P(buffer, PSTR("temperature="));
        ptr = buffer + strlen(buffer);
        int_to_string(eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(n)), ptr, PSTR("\n"));
        card.write_string(buffer);

#if TEMP_SENSOR_BED != 0
        strcpy_P(buffer, PSTR("bed_temperature="));
        ptr = buffer + strlen(buffer);
        int_to_string(eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(n)), ptr, PSTR("\n"));
        card.write_string(buffer);
#endif

        strcpy_P(buffer, PSTR("fan_speed="));
        ptr = buffer + strlen(buffer);
        int_to_string(eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(n)), ptr, PSTR("\n"));
        card.write_string(buffer);

        strcpy_P(buffer, PSTR("flow="));
        ptr = buffer + strlen(buffer);
        int_to_string(eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(n)), ptr, PSTR("\n"));
        card.write_string(buffer);

        strcpy_P(buffer, PSTR("diameter="));
        ptr = buffer + strlen(buffer);
        float_to_string(eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(n)), ptr, PSTR("\n\n"));
        card.write_string(buffer);

#ifdef USE_CHANGE_TEMPERATURE
        strcpy_P(buffer, PSTR("change_temp="));
        ptr = buffer + strlen(buffer);
        float_to_string(eeprom_read_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(n)), ptr, PSTR("\n\n"));
        card.write_string(buffer);
        
        strcpy_P(buffer, PSTR("change_wait="));
        ptr = buffer + strlen(buffer);
        float_to_string(eeprom_read_byte(EEPROM_MATERIAL_CHANGE_WAIT_TIME(n)), ptr, PSTR("\n\n"));
        card.write_string(buffer);
#endif
    }
    card.closefile();

    currentMenu = lcd_menu_material_export_done;
}
bool lcd_material_verify_material_settings()
{
    bool hasCPE = false;
    
    uint8_t cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    if (cnt < 2 || cnt > EEPROM_MATERIAL_SETTINGS_MAX_COUNT)
        return false;
    while(cnt > 0)
    {
        cnt --;
        if (eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt)) > HEATER_0_MAXTEMP)
            return false;
#if TEMP_SENSOR_BED != 0
        if (eeprom_read_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt)) > BED_MAXTEMP)
            return false;
#endif
        if (eeprom_read_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt)) > 100)
            return false;
        if (eeprom_read_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt)) > 1000)
            return false;
        if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) > 10.0)
            return false;
        if (eeprom_read_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt)) < 0.1)
            return false;

        eeprom_read_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 8);
        if (strcmp_P(card.longFilename, PSTR("UPET")) == 0)
        {
            strcpy_P(card.longFilename, PSTR("CPE"));
            eeprom_write_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 4);
        }
        if (strcmp_P(card.longFilename, PSTR("CPE")) == 0)
        {
            hasCPE = true;
        }

        if (eeprom_read_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(cnt)) > HEATER_0_MAXTEMP || eeprom_read_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(cnt)) < 10)
        {
            //Invalid temperature for change temperature.
            eeprom_write_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(cnt), eeprom_read_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt)));
            eeprom_write_byte(EEPROM_MATERIAL_CHANGE_WAIT_TIME(cnt), 0);
        }
    }
    cnt = eeprom_read_byte(EEPROM_MATERIAL_COUNT_OFFSET());
    if (!hasCPE && cnt < EEPROM_MATERIAL_SETTINGS_MAX_COUNT)
    {
        strcpy_P(card.longFilename, PSTR("CPE"));
        eeprom_write_block(card.longFilename, EEPROM_MATERIAL_NAME_OFFSET(cnt), 4);
        eeprom_write_word(EEPROM_MATERIAL_TEMPERATURE_OFFSET(cnt), 250);
        eeprom_write_word(EEPROM_MATERIAL_BED_TEMPERATURE_OFFSET(cnt), 60);
        eeprom_write_byte(EEPROM_MATERIAL_FAN_SPEED_OFFSET(cnt), 50);
        eeprom_write_word(EEPROM_MATERIAL_FLOW_OFFSET(cnt), 100);
        eeprom_write_float(EEPROM_MATERIAL_DIAMETER_OFFSET(cnt), 2.85);

        eeprom_write_word(EEPROM_MATERIAL_CHANGE_TEMPERATURE(cnt), 250);
        eeprom_write_byte(EEPROM_MATERIAL_CHANGE_WAIT_TIME(cnt), 0);

        eeprom_write_byte(EEPROM_MATERIAL_COUNT_OFFSET(), cnt + 1);
    }
    return true;
}