reflow-oven-control-sw/stm-firmware/include/reflow-controller/settings/settings.h

104 lines
3.7 KiB
C

/* Reflow Oven Controller
*
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
*
* This file is part of the Reflow Oven Controller Project.
*
* The reflow oven controller is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the reflow oven controller project.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SETTINGS_SETTINGS_H__
#define __SETTINGS_SETTINGS_H__
#include <stdbool.h>
/**
* @brief Settings for the PID controller that are stored in the config file
*/
struct oven_pid_settings {
float kd; /**< @brief Derivate term */
float kp; /**< @brief Proportional term */
float ki; /**< @brief Integral term */
float kd_tau; /**< @brief Time constant of the derivate term's low pass filter */
float t_sample; /**< @brief Sampling time in seconds. @warning The loading function expects the file to hold a ms value */
float max_integral; /**< @brief Maximum value of the intgral term */
};
/**
* @brief Results of a setting loading
*/
enum settings_load_result {
SETT_LOAD_SUCCESS = 0, /**< @brief Setting loaded successfully */
SETT_LOAD_FILE_NOT_FOUND, /**< @brief File not found. This is only used by Settings on the SD card */
SETT_LOAD_ERR, /**< @brief Generic loading error */
SETT_LOAD_DISK_ERR, /**< @brief Disk access failure during loading */
};
#define SETTINGS_PID_PARAMETER_FILE "pid.conf"
/**
* @brief Save the calibration
* @param sens_deviation
* @param offset
* @return 0 if successful, -1 if generic error, -2 if medium unavailable
*/
int settings_save_calibration(float sens_deviation, float offset, bool active);
/**
* @brief Load the calibration
*
* If an EEPROM is present, it is first tried to be retrieved from EEPROM.
* If there is no EEPROM or there is no valid data inside, it is tried to be loaded from SD card.
*
* @param sens_dev Sensiotivity deviation
* @param offset Offset
* @return 0 if successful and calibration valid
*/
int settings_load_calibration(float *sens_dev, float *offset);
/**
* @brief Load PID overn parameters from file on SD card. This function is not implemented for EEPROM.
* @param settings settings
* @return Load result
*/
enum settings_load_result settings_load_pid_oven_parameters(struct oven_pid_settings *settings);
/**
* @brief read the configured overtemperature limit
* @param[out] over_temp_limit Overtemperature limit in degrees Celsius
* @return Load result
*/
enum settings_load_result settings_load_overtemp_limit(float *over_temp_limit);
/**
* @brief Save the overtemperature limit
* @param over_temp_limit Limit in degrees Celsius
* @param active Overtemperature limit active. If false: The config is delted and the controller uses its default limit
* @return 0 if successful
*/
int settings_save_overtemp_limit(float over_temp_limit, bool active);
/**
* @brief Setup the settings module
*
* This function has to be called before performing any settings operations.
* It checks if an EEPTROM is connected and sets the appropriate settings storage in this case.
*
* EEPROM storage will only be available for HW versions > 1.3. Some functions require an EEPROM because the counterpart
* on the SD card is not defined. These functions will fail without an EEPROM.
*/
void settings_setup(void);
#endif /* __SETTINGS_SETTINGS_H__ */