51 lines
1016 B
C
51 lines
1016 B
C
#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
|