feat(ch934x): 添加GPIO方向控制和串口参数配置功能
- 添加Ch934xMode和GpioDirection枚举类定义 - 实现GPIO方向控制相关方法(setGpioDir/queryGpioDirFromCache) - 添加GPIO使能控制(enableGpio)和数量/组数查询(getGpiocount/getGpiogroup) - 实现串口参数配置(setSerialParameter)包括波特率/数据位/停止位/校验位/流控 - 添加Break信号控制(setBreak)功能 - 实现当前串口模式查询(getCurrentMode) - 添加设备连接状态查询(isConnected)和已打开设备列表获取(getConnectedDevices) - 更新文档说明GPIO方向控制和串口参数配置用法 - 在示例应用中添加相关功能按钮和操作逻辑
This commit is contained in:
@@ -378,6 +378,148 @@ class _Ch934xSerialExamplePageState extends State<Ch934xSerialExamplePage> {
|
||||
icon: const Icon(Icons.input),
|
||||
label: const Text('读取 GPIO0'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
if (!_portOpened) return;
|
||||
final ok = await _plugin.setBreak(true);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = ok ? 'Break 已设置' : 'Break 失败');
|
||||
},
|
||||
icon: const Icon(Icons.pause),
|
||||
label: const Text('SetBreak'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
if (!_portOpened) return;
|
||||
final mode = await _plugin.getCurrentMode();
|
||||
if (!mounted) return;
|
||||
final label = switch (mode) {
|
||||
Ch934xMode.normal => '普通',
|
||||
Ch934xMode.hardflow => '硬件流控',
|
||||
Ch934xMode.gpio => 'GPIO',
|
||||
_ => '未知($mode)',
|
||||
};
|
||||
setState(() => _status = '当前模式: $label');
|
||||
},
|
||||
icon: const Icon(Icons.settings),
|
||||
label: const Text('当前模式'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final device = _selectedDevice;
|
||||
if (device == null) {
|
||||
setState(() => _status = '请先选择设备');
|
||||
return;
|
||||
}
|
||||
final cnt = await _plugin.getGpiocount(device.deviceId);
|
||||
final grp = await _plugin.getGpiogroup(device.deviceId);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = 'GPIO 数量=$cnt, 组数=$grp');
|
||||
},
|
||||
icon: const Icon(Icons.developer_board),
|
||||
label: const Text('GPIO 信息'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final device = _selectedDevice;
|
||||
if (device == null) {
|
||||
setState(() => _status = '请先选择设备');
|
||||
return;
|
||||
}
|
||||
if (!_portOpened) {
|
||||
setState(() => _status = '请先打开串口');
|
||||
return;
|
||||
}
|
||||
final ok = await _plugin.enableGpio(
|
||||
chipType: device.deviceType,
|
||||
gpioGroup: 0,
|
||||
enable: 1,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = ok ? 'GPIO 已使能' : '使能 GPIO 失败');
|
||||
},
|
||||
icon: const Icon(Icons.toggle_on),
|
||||
label: const Text('使能GPIO'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
if (!_portOpened) return;
|
||||
final ok = await _plugin.setGpioDir(
|
||||
gpioGroup: 0,
|
||||
gpioNumber: 0,
|
||||
dir: GpioDirection.out,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = ok ? 'GPIO0 方向设为输出' : '设置方向失败');
|
||||
},
|
||||
icon: const Icon(Icons.swap_vert),
|
||||
label: const Text('GPIO方向'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
if (!_portOpened) return;
|
||||
final dir = await _plugin.queryGpioDirFromCache(
|
||||
gpioGroup: 0,
|
||||
gpioNumber: 0,
|
||||
);
|
||||
if (!mounted) return;
|
||||
final label = switch (dir) {
|
||||
GpioDirection.in_ => '输入',
|
||||
GpioDirection.out => '输出',
|
||||
_ => '未知($dir)',
|
||||
};
|
||||
setState(() => _status = 'GPIO0 方向缓存: $label');
|
||||
},
|
||||
icon: const Icon(Icons.visibility),
|
||||
label: const Text('查方向缓存'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final device = _selectedDevice;
|
||||
if (device == null) {
|
||||
setState(() => _status = '请先选择设备');
|
||||
return;
|
||||
}
|
||||
final connected = await _plugin.isConnected(device.deviceId);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = connected ? '设备已连接' : '设备未连接');
|
||||
},
|
||||
icon: const Icon(Icons.link),
|
||||
label: const Text('是否已连'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final ids = await _plugin.getConnectedDevices();
|
||||
if (!mounted) return;
|
||||
setState(() => _status = '已打开设备: ${ids.isEmpty ? "无" : ids.join(", ")}');
|
||||
},
|
||||
icon: const Icon(Icons.list),
|
||||
label: const Text('已开设备'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
if (!_portOpened) return;
|
||||
final ok = await _plugin.setSerialParameter(
|
||||
baud: 9600, dataBit: 8, stopBit: 1, parityBit: 0, flow: false,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = ok ? '已设为 9600/8/1/N' : '设参失败');
|
||||
},
|
||||
icon: const Icon(Icons.tune),
|
||||
label: const Text('波特率9600'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
if (!_portOpened) return;
|
||||
final ok = await _plugin.setSerialParameter(
|
||||
baud: 115200, dataBit: 8, stopBit: 1, parityBit: 0, flow: false,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _status = ok ? '已设为 115200/8/1/N' : '设参失败');
|
||||
},
|
||||
icon: const Icon(Icons.tune),
|
||||
label: const Text('波特率115200'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
Reference in New Issue
Block a user