Files
esp32c3-smart-scale/components/scale_controller/include/scale_controller.h

51 lines
1016 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief 称重控制器配置
*/
typedef struct {
float calibration_factor; // 校准系数
int32_t tare_offset; // 初始皮重偏移
} scale_config_t;
/**
* @brief 初始化称重控制器
* @param config 配置参数
*/
void scale_controller_init(const scale_config_t *config);
/**
* @brief 更新皮重偏移(去皮)
* @param raw_avg 测量的多次原始值平均值
*/
void scale_controller_set_tare(int32_t raw_avg);
/**
* @brief 原始值转换为重量(带简单均值滤波)
* @param raw_val 采集到的最新 ADC 原始值
* @return float 转换并滤波后的重量g
*/
float scale_controller_raw_to_weight(int16_t raw_val);
/**
* @brief 重置滤波器缓冲区
*/
void scale_controller_filter_reset(void);
/**
* @brief 设置校准系数
* @param factor 校准系数
*/
void scale_controller_set_factor(float factor);
#ifdef __cplusplus
}
#endif