CSSC-PC更新了7个文件
This commit is contained in:
parent
7e79e67c20
commit
926277efd4
@ -154,4 +154,6 @@ tags:
|
|||||||
### 颜色值映射过程:
|
### 颜色值映射过程:
|
||||||
1. 计算渐变色并分为N个
|
1. 计算渐变色并分为N个
|
||||||
2. 计算index=round((value-min)/((max-min)/N)),四舍五入
|
2. 计算index=round((value-min)/((max-min)/N)),四舍五入
|
||||||
3. 发送colormap[0]至colormap[index]
|
3. 发送colormap[0]至colormap[index]
|
||||||
|
### 主控:
|
||||||
|
华大[[MCU/华大/选型#[HC32L110C6](https //www.hdsc.com.cn/Category82-1389)|HC32L、HC32F]]系列及沁恒[[CH32V003]]系列,优选后者,便宜够用。
|
53
DIY/器件定位.md
Normal file
53
DIY/器件定位.md
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
---
|
||||||
|
updated: 2024-06-20
|
||||||
|
tags:
|
||||||
|
- 低功耗
|
||||||
|
- 屏
|
||||||
|
- 器件库
|
||||||
|
- BLE
|
||||||
|
- mcu
|
||||||
|
- led
|
||||||
|
---
|
||||||
|
|
||||||
|
## 方案对比
|
||||||
|
|
||||||
|
| 方案 | 示例 | 优点 | 缺点 |
|
||||||
|
| :------: | :---------: | :-----------: | :-----: |
|
||||||
|
| MCU+收发IC | Lora、2.4GHz | 通信距离远、响应快程序复杂 | 成本高、体积大 |
|
||||||
|
| 单MCU | BLE | 距离近,响应略慢 | 程序简单 |
|
||||||
|
| | | | |
|
||||||
|
|
||||||
|
定位需求本身不会远距离使用,响应时间在100ms内均可接受,故优选单MCU方案。
|
||||||
|
|
||||||
|
## 单MCU方案
|
||||||
|
MCU集成BLE,[[CH57x]]、[[CH582F]]等,单片约2元
|
||||||
|
Host端工作于广播模式,每个器件盒作为独立节点工作于扫描模式。
|
||||||
|
|
||||||
|
### 初始化
|
||||||
|
节点产生UUID,Host据此与器件关联并存入数据库
|
||||||
|
|
||||||
|
### 查找
|
||||||
|
1. Host查找数据库找出与搜索关键字匹配的UUID,并列出器件列表
|
||||||
|
2. 报文添加与指定器件列表关联的UUID及“仅查找”标识并持续广播
|
||||||
|
3. 节点群上电,并扫描可用节点,若与自身UUID匹配则亮灯指示
|
||||||
|
>节点端默认不带显示,可支持墨水屏显示器件列表。
|
||||||
|
> 报文添加“编辑”标识可编辑器件列表,编辑模式下节点会连接Host,并在连接后主动上报器件列表
|
||||||
|
> 为保证墨水屏寿命,每次节点上电均刷新屏幕
|
||||||
|
|
||||||
|
### 休眠
|
||||||
|
无线供电不用考虑休眠问题,上电后持续扫描即可。
|
||||||
|
电池供电需考虑谨慎优化功耗,必须合理休眠。
|
||||||
|
为调协功耗和响应速度,可设置两种唤醒间隔。
|
||||||
|
> 非工作状态1分钟唤醒一次,最好添加外围电路,沿用无线供电逻辑高电平唤醒;
|
||||||
|
> 工作状态1s唤醒一次。
|
||||||
|
|
||||||
|
## 供电
|
||||||
|
独立节点具有数量多,体积受限,功耗低的特点,供电方式直接影响使用体验。
|
||||||
|
|
||||||
|
| | 优点 | 缺点 |
|
||||||
|
|:----:|:---------------:|:--------------------------------:|
|
||||||
|
| 无线供电 | 体积小,开发难度低,使用灵活 | 无外壳,从零设计,独立供电单元,节点位置不够灵活 |
|
||||||
|
| 电池供电 | 成品墨水屏有外壳,自带电池供电 | 体积略大,有改造难度。主控特殊,不是常用的开发环境,有学习成本。 |
|
||||||
|
|
||||||
|
## 存储盒
|
||||||
|
5.5\*5.5cm盒性价比高,9元/30个。可容纳少量IC编带,能放1.54墨水屏
|
9
MCU/WCH-南京沁恒/CH32V003.md
Normal file
9
MCU/WCH-南京沁恒/CH32V003.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
updated: 2024-06-20
|
||||||
|
tags:
|
||||||
|
- mcu
|
||||||
|
- 串口
|
||||||
|
- 低功耗
|
||||||
|
---
|
||||||
|
价格低,[第三方库](https://github.com/cnlohr/ch32v003fun)使用方便,样例多,维护勤,占用资源低
|
||||||
|
![[Pasted image 20240620084329.png]]
|
@ -1,4 +1,4 @@
|
|||||||
# 产品
|
|
||||||
|
|
||||||
国产MCU的ADC性能基本不太行,所以手册一般不提供精度指标。经查询,华大部分产品有此指标。
|
国产MCU的ADC性能基本不太行,所以手册一般不提供精度指标。经查询,华大部分产品有此指标。
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# 0.5块
|
||||||
|
[[CH32V003]],够用
|
||||||
# 1-2块
|
# 1-2块
|
||||||
|
|
||||||
tssop封装,引脚少,rom/ram,适合简单功能 [HC32L110C6](https://www.hdsc.com.cn/Category82-1389) HC32F003、[HC32F005](https://www.hdsc.com.cn/Category83-1434)
|
tssop封装,引脚少,rom/ram,适合简单功能 [HC32L110C6](https://www.hdsc.com.cn/Category82-1389) HC32F003、[HC32F005](https://www.hdsc.com.cn/Category83-1434)
|
||||||
|
BIN
_resources/Pasted image 20240620084329.png
Normal file
BIN
_resources/Pasted image 20240620084329.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 309 KiB |
111
代码/状态机接收不定长数据.md
111
代码/状态机接收不定长数据.md
@ -27,9 +27,116 @@ tags:
|
|||||||
> http://www.rimelink.com/nd.jsp?id=38&_np=105_315
|
> http://www.rimelink.com/nd.jsp?id=38&_np=105_315
|
||||||
|
|
||||||
代码清单如下:
|
代码清单如下:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
/** * @brief Status of received communication frame */ typedef enum { STATUS_IDLE = (uint8_t)0, STATUS_HEAD, /* Rx Head=0x3C */ STATUS_TYPE, /* Rx Type */ STATUS_DATA, /* Data filed */ STATUS_TAIL, /* Tail=0x0D */ STATUS_END, /* End of this frame */ } COMM_TRM_STATUS_TypeDef; /** * @brief Data object for received communication frame */ typedef struct { uint8_t byCnt; /* Count of 1 field */ uint8_t byDataLen; /* Length of data field */ uint8_t byFrameLen; /* Length of frame */ COMM_TRM_STATUS_TypeDef eRxStatus; uint8_t a_byRxBuf[MAX_LEN_COMM_TRM_DATA]; } COMM_TRM_DATA; /** * @brief Data object for received communication frame. * @note Prevent race condition that accessed by both ISR and process. */ static COMM_TRM_DATA s_stComm2TrmData; /** * @brief Put a data that received by UART into buffer. * @note Prevent race condition this called by ISR. * @param uint8_t byData: the data received by UART. * @retval None */ void comm2trm_RxUartData(uint8_t byData) { /* Update status according to the received data */ switch (s_stComm2TrmData.eRxStatus) { case STATUS_IDLE: if (COMM_TRM_HEAD == byData) /* Is Head */ { s_stComm2TrmData.eRxStatus = STATUS_HEAD; } else { goto rx_exception; } break; case STATUS_HEAD: if (TYPE_INVALID_MIN < byData && byData < TYPE_INVALID_MAX) /* Valid type */ { s_stComm2TrmData.eRxStatus = STATUS_TYPE; } else { goto rx_exception; } break; case STATUS_TYPE: if (byData <= MAX_LEN_UART_FRAME_DATA) /* Valid data size */ { s_stComm2TrmData.eRxStatus = STATUS_DATA; s_stComm2TrmData.byDataLen = byData; } else { goto rx_exception; } break; case STATUS_DATA: if (s_stComm2TrmData.byCnt < s_stComm2TrmData.byDataLen) { ++s_stComm2TrmData.byCnt; } else { s_stComm2TrmData.eRxStatus = STATUS_TAIL; } break; case STATUS_TAIL: if (COMM_TRM_TAIL == byData) { /* We received a frame of data, now tell process to deal with it! */ process_poll(&Comm2TrmProcess); } else { goto rx_exception; } break; default: ASSERT(!"Error: Bad status of comm2trm_RxUartData().\r\n"); break; } /* Save the received data */ s_stComm2TrmData.a_byRxBuf[s_stComm2TrmData.byFrameLen++] = byData; return; rx_exception: ClearCommFrame(); return; } ```
|
/**
|
||||||
|
* @brief Status of received communication frame
|
||||||
|
*/
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
STATUS_IDLE = (uint8_t)0,
|
||||||
|
STATUS_HEAD, /* Rx Head=0x3C */
|
||||||
|
STATUS_TYPE, /* Rx Type */
|
||||||
|
STATUS_DATA, /* Data filed */
|
||||||
|
STATUS_TAIL, /* Tail=0x0D */
|
||||||
|
STATUS_END, /* End of this frame */
|
||||||
|
} COMM_TRM_STATUS_TypeDef;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data object for received communication frame
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t byCnt; /* Count of 1 field */
|
||||||
|
uint8_t byDataLen; /* Length of data field */
|
||||||
|
uint8_t byFrameLen; /* Length of frame */
|
||||||
|
COMM_TRM_STATUS_TypeDef eRxStatus;
|
||||||
|
uint8_t a_byRxBuf[MAX_LEN_COMM_TRM_DATA];
|
||||||
|
} COMM_TRM_DATA;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
* @brief Data object for received communication frame.
|
||||||
|
* @note Prevent race condition that accessed by both ISR and process.
|
||||||
|
*/
|
||||||
|
static COMM_TRM_DATA s_stComm2TrmData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Put a data that received by UART into buffer.
|
||||||
|
* @note Prevent race condition this called by ISR.
|
||||||
|
* @param uint8_t byData: the data received by UART.
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void comm2trm_RxUartData(uint8_t byData)
|
||||||
|
{
|
||||||
|
/* Update status according to the received data */
|
||||||
|
switch (s_stComm2TrmData.eRxStatus)
|
||||||
|
{
|
||||||
|
case STATUS_IDLE:
|
||||||
|
if (COMM_TRM_HEAD == byData) /* Is Head */
|
||||||
|
{
|
||||||
|
s_stComm2TrmData.eRxStatus = STATUS_HEAD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto rx_exception;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATUS_HEAD:
|
||||||
|
if (TYPE_INVALID_MIN < byData && byData < TYPE_INVALID_MAX) /* Valid type */
|
||||||
|
{
|
||||||
|
s_stComm2TrmData.eRxStatus = STATUS_TYPE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto rx_exception;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATUS_TYPE:
|
||||||
|
if (byData <= MAX_LEN_UART_FRAME_DATA) /* Valid data size */
|
||||||
|
{
|
||||||
|
s_stComm2TrmData.eRxStatus = STATUS_DATA;
|
||||||
|
s_stComm2TrmData.byDataLen = byData;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto rx_exception;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATUS_DATA:
|
||||||
|
if (s_stComm2TrmData.byCnt < s_stComm2TrmData.byDataLen)
|
||||||
|
{
|
||||||
|
++s_stComm2TrmData.byCnt;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_stComm2TrmData.eRxStatus = STATUS_TAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case STATUS_TAIL:
|
||||||
|
if (COMM_TRM_TAIL == byData)
|
||||||
|
{
|
||||||
|
/* We received a frame of data, now tell process to deal with it! */
|
||||||
|
process_poll(&Comm2TrmProcess);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
goto rx_exception;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(!"Error: Bad status of comm2trm_RxUartData().\r\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the received data */
|
||||||
|
s_stComm2TrmData.a_byRxBuf[s_stComm2TrmData.byFrameLen++] = byData;
|
||||||
|
return;
|
||||||
|
|
||||||
|
rx_exception:
|
||||||
|
ClearCommFrame();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user