暂存,测试0x21转0x33
This commit is contained in:
parent
ee8dc69fb9
commit
dfa16f5c79
|
@ -189,7 +189,7 @@ uint16_t Get_Stable_Reading(uint8_t cnt, uint32_t timeout_ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
last = current;
|
last = current;
|
||||||
rt_thread_mdelay(200);
|
rt_thread_mdelay(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // 超时
|
return 0; // 超时
|
||||||
|
@ -243,7 +243,7 @@ int APP_Calibration_Handle(void)
|
||||||
if (i == 10)
|
if (i == 10)
|
||||||
{
|
{
|
||||||
gas_calibration_voltage = (uint16_t)(gas_calibration_voltage / 10);
|
gas_calibration_voltage = (uint16_t)(gas_calibration_voltage / 10);
|
||||||
|
|
||||||
calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节
|
calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节
|
||||||
calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节
|
calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节
|
||||||
LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]);
|
LOG_D("calibration_buf[0] = %X calibration_buf[1] = %X", calibration_buf[0], calibration_buf[1]);
|
||||||
|
@ -262,7 +262,7 @@ int APP_Calibration_Handle(void)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
gas_calibration_voltage = Get_Stable_Reading(5, 10000);//10s内连续5次稳定,则认为其标定浓度稳定,进行标定
|
gas_calibration_voltage = Get_Stable_Reading(10, 10000);//10s内连续10次稳定,则认为其标定浓度稳定,进行标定
|
||||||
if(gas_calibration_voltage == 0)
|
if(gas_calibration_voltage == 0)
|
||||||
{
|
{
|
||||||
LOG_D("标定超时,标定错误");
|
LOG_D("标定超时,标定错误");
|
||||||
|
@ -285,7 +285,7 @@ int APP_Calibration_Handle(void)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
|
@ -302,8 +302,38 @@ int BSP_Ml307_Init (struct Ml307_Ops *ops, rt_uint8_t version)
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bcd_to_decimal(uint8_t bcd)
|
||||||
|
{
|
||||||
|
uint8_t high = (bcd >> 4) * 10;
|
||||||
|
uint8_t low = bcd & 0x0F;
|
||||||
|
return high + low;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t decimal_to_bcd(uint8_t decimal)
|
||||||
|
{
|
||||||
|
uint8_t high = (decimal / 10) & 0x0F;
|
||||||
|
uint8_t low = (decimal % 10) & 0x0F;
|
||||||
|
return (high << 4) | low;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test(uint8_t a)
|
||||||
|
{
|
||||||
|
uint8_t b;
|
||||||
|
LOG_D("in = 0x%02X, %d", a, a);
|
||||||
|
b = a;
|
||||||
|
b = bcd_to_decimal(b);
|
||||||
|
LOG_D("in = 0x%02X, %d", b, b);
|
||||||
|
b = decimal_to_bcd(b);
|
||||||
|
LOG_D("in = 0x%02X, %d", b, b);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
MSH_CMD_EXPORT(test, "test");
|
||||||
|
|
||||||
|
|
||||||
int _Update_Valve_Data (struct Ml307_Ops *ops)
|
int _Update_Valve_Data (struct Ml307_Ops *ops)
|
||||||
{
|
{
|
||||||
|
uint8_t valtage = 0;
|
||||||
|
|
||||||
ops->body->valve_num = Flash_Get_Valve_Num();
|
ops->body->valve_num = Flash_Get_Valve_Num();
|
||||||
if (ops->body->valve_num == 0) // 确保至少有一个阀门数据体
|
if (ops->body->valve_num == 0) // 确保至少有一个阀门数据体
|
||||||
{
|
{
|
||||||
|
@ -315,6 +345,8 @@ int _Update_Valve_Data (struct Ml307_Ops *ops)
|
||||||
LOG_D ("valve_num: %d", ops->body->valve_num);
|
LOG_D ("valve_num: %d", ops->body->valve_num);
|
||||||
rt_memcpy (&ops->body->valve_data[0], &valve[0], sizeof (struct valve_t));
|
rt_memcpy (&ops->body->valve_data[0], &valve[0], sizeof (struct valve_t));
|
||||||
// rt_memset(&valve[0].valve_connct_status, 0, (sizeof(struct valve_t) - 7)); // 清空阀门包数据,等待下次更新,如果没更新说明断开了
|
// rt_memset(&valve[0].valve_connct_status, 0, (sizeof(struct valve_t) - 7)); // 清空阀门包数据,等待下次更新,如果没更新说明断开了
|
||||||
|
valtage = ops->body->valve_data[0].valve_voltage; //将十六进制转为十进制
|
||||||
|
ops->body->valve_data[0].valve_voltage = (valtage >> 4) * 16 + (valtage & 0x0F);
|
||||||
}
|
}
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue