Browse Source

蓝牙及设备状态

master
zhangjiming 4 months ago
parent
commit
8c2e917744
  1. 6
      src/App.tsx
  2. 10
      src/pages/Bluetooth.tsx
  3. 14
      src/services/mobileWsType.ts
  4. 4
      src/store/features/contextSlice.ts
  5. 3
      src/store/features/measureSlice.ts

6
src/App.tsx

@ -13,10 +13,9 @@ import icon_4_u from './assets/tabIcon/icon_tab4_u.svg';
import { appWebview, bridgeOb, emitBridgeEvent, registerBridgeFunc } from './utils/bridge';
import { useAppDispatch } from './utils/hooks';
import { addNewPoint, updateTaskState } from './store/features/measureSlice';
import { DeviceStatus, TrackRecordSig } from './services/wsTypes';
import { updateBleList, updateDevice, updateSyncProgress } from './store/features/contextSlice';
import { createWebSocket, sharedWsUrl } from './services/socket';
import { updateUploadStatus } from './store/features/historySlice';
import { fetchRailTypes } from './store/features/baseData';
const BottomBar = () => {
const navigate = useNavigate();
@ -70,11 +69,12 @@ const BottomBar = () => {
function App() {
const dispatch = useAppDispatch();
dispatch(fetchRailTypes());
useEffect(() => {
const subscription = bridgeOb.subscribe((datagram) => {
if (datagram.type === 'measure-event') {
dispatch(updateTaskState(datagram.data.event));
dispatch(updateTaskState(datagram.data));
} else if (datagram.type === 'measure-point') {
dispatch(addNewPoint(datagram.data));
} else if (datagram.type === 'peripheral-status') {

10
src/pages/Bluetooth.tsx

@ -20,21 +20,21 @@ export default function Bluetooth() {
};
}, []);
const onConnect = (id: string) => {
Bridge.connectPeripheral({ id }).then((res) => {
const onConnect = (mac: string) => {
Bridge.connectPeripheral({ mac }).then((res) => {
if (!res.success) {
Toast.show(res.message);
} else {
dispatch(updateBleLinkStatus({id, link: true}))
dispatch(updateBleLinkStatus({mac, link: true}))
}
});
};
const onDisconnect = (id: string) => {
const onDisconnect = (mac: string) => {
Bridge.disconnectPeripheral().then((res) => {
if (!res.success) {
Toast.show(res.message);
} else {
dispatch(updateBleLinkStatus({id, link: false}))
dispatch(updateBleLinkStatus({mac, link: false}))
}
});
};

14
src/services/mobileWsType.ts

@ -11,14 +11,12 @@ export type PeripheralStatus = {
export type MeasureEvent = {
type: 'measure-event';
data: {
event:
| 'START_RECORD_LEFT'
| 'FINISH_RECORD_LEFT'
| 'START_RECORD_RIGHT'
| 'FINISH_RECORD_RIGHT'
| 'WRONG_SIDE';
};
data:
| 'START_RECORD_LEFT'
| 'FINISH_RECORD_LEFT'
| 'START_RECORD_RIGHT'
| 'FINISH_RECORD_RIGHT'
| 'WRONG_SIDE';
};
export type MeasurePoint = {

4
src/store/features/contextSlice.ts

@ -100,9 +100,9 @@ export const contextSlice = createSlice({
state.bleList = action.payload;
},
updateBleLinkStatus: (state, action: PayloadAction<{ id: string; link: boolean }>) => {
updateBleLinkStatus: (state, action: PayloadAction<{ mac: string; link: boolean }>) => {
state.bleList = state.bleList.map((ble) => {
if (ble.mac === action.payload.id) {
if (ble.mac === action.payload.mac) {
ble.linked = action.payload.link;
}
return ble;

3
src/store/features/measureSlice.ts

@ -18,7 +18,8 @@ function isLeftFinished(state: MeasureState) {
if (
state.taskState === 'FINISH_RECORD_LEFT' ||
state.taskState === 'START_RECORD_RIGHT' ||
state.taskState === 'FINISH_RECORD_RIGHT'
state.taskState === 'FINISH_RECORD_RIGHT' ||
state.taskState === 'FINISH_RECORD'
)
return true;
return false;

Loading…
Cancel
Save