diff --git a/src/ble/parser.ts b/src/ble/parser.ts index 1f93c7c..cbaff6f 100644 --- a/src/ble/parser.ts +++ b/src/ble/parser.ts @@ -83,6 +83,19 @@ export const parseLogs = (finishedLog: string, lastLog: string) => { } } + // DEVICE + const lastDeviceLine = checkForLastLine(COMMANDS.DEVICE.readCommand!, lines) + + if (lastDeviceLine) { + const value = valueChecker(lastDeviceLine, COMMANDS.DEVICE) + if (value) { + results.push({ + value, + command: COMMANDS.DEVICE, + }) + } + } + // SENSOR const lastSensorLine = checkForLastLine(COMMANDS.SENSOR.readCommand!, lines) diff --git a/src/ble/types.ts b/src/ble/types.ts index 222e90d..1ad7aa9 100644 --- a/src/ble/types.ts +++ b/src/ble/types.ts @@ -20,6 +20,7 @@ export enum CommandNames { SENSOR = "SENSOR", TRAP = "TRAP", LORAWAN = "LORAWAN", + DEVICE = "DEVICE", } /** @@ -144,6 +145,10 @@ export const COMMANDS: { writeCommand: () => "dfu", readRegex: /(Device will enter DFU mode after disconnecting.)\s*/, }, + [CommandNames.DEVICE]: { + name: CommandNames.DEVICE, + readCommand: "device", + }, } type CharacteristicProperty = diff --git a/src/navigation/screens/Home.tsx b/src/navigation/screens/Home.tsx index cce21d0..36771a7 100644 --- a/src/navigation/screens/Home.tsx +++ b/src/navigation/screens/Home.tsx @@ -72,8 +72,10 @@ export const Home = memo(() => { }, [isFocused]) useEffect(() => { + if (!isFocused) return + const interval = setInterval(() => { - if (!isBleBusy) { + if (!isBleBusy && isFocused) { startScan(10) } else { log("Scanning already taking place, skipping.") diff --git a/src/navigation/screens/TerminalScreen.tsx b/src/navigation/screens/TerminalScreen.tsx index 58bbce1..5b95c7e 100644 --- a/src/navigation/screens/TerminalScreen.tsx +++ b/src/navigation/screens/TerminalScreen.tsx @@ -1,8 +1,7 @@ import { useRoute, useIsFocused } from "@react-navigation/native" -import * as React from "react" import { useState } from "react" import { useCallback } from "react" -import { useEffect } from "react" +import { useEffect, useRef } from "react" import { Keyboard, @@ -38,7 +37,7 @@ type Props = { } export const Terminal = ({ embed }: Props) => { - const scrollViewRef = React.useRef() + const scrollViewRef = useRef() const { params: { deviceId }, } = useRoute>() @@ -47,12 +46,13 @@ export const Terminal = ({ embed }: Props) => { const isFocused = useIsFocused() const { write, pingsPause, disconnectDevice } = useBleActions() const device = useSelectDevice({ deviceId }) - const [offset, setOffset] = useState(0) const logs = deviceLogs[deviceId] const configuration = useAppSelector((state) => state.configuration) const config = configuration[deviceId] const { spacing, colors, appPadding } = useExtendedTheme() + const offset = useRef(0) + const { get: getBattery, commandLoading: batteryLoading } = useCommand({ deviceId, command: COMMANDS.BATTERY, @@ -61,6 +61,10 @@ export const Terminal = ({ embed }: Props) => { deviceId, command: COMMANDS.VERSION, }) + const { get: getDevice, commandLoading: deviceLoading } = useCommand({ + deviceId, + command: COMMANDS.DEVICE, + }) const { get: getId, commandLoading: idLoading } = useCommand({ deviceId, command: COMMANDS.ID, @@ -135,7 +139,7 @@ export const Terminal = ({ embed }: Props) => { scrollViewRef.current && scrollViewRef.current.scrollToEnd({ animated: true }) - setOffset(0) + offset.current = 0 }, [autoscroll, deviceLogs]) const [isKeyboardVisible, setIsKeyboardVisible] = useState(false) @@ -176,10 +180,10 @@ export const Terminal = ({ embed }: Props) => { }: NativeSyntheticEvent) => { const { layoutMeasurement, contentOffset, contentSize } = nativeEvent const currentOffset = nativeEvent.contentOffset.y - const goingUp = currentOffset < offset + const goingUp = currentOffset < offset.current const isOnBottom = - layoutMeasurement.height + contentOffset.y >= contentSize.height - 15 - setOffset(currentOffset) + layoutMeasurement.height + contentOffset.y >= contentSize.height - 50 + offset.current = currentOffset if (goingUp) { toggleAutoscroll(false) @@ -204,8 +208,17 @@ export const Terminal = ({ embed }: Props) => { } }, []) - const { HEARTBEAT, APPEUI, SENSOR, LORAWAN, DEVEUI, BATTERY, VERSION, ID } = - config + const { + HEARTBEAT, + APPEUI, + SENSOR, + LORAWAN, + DEVEUI, + BATTERY, + VERSION, + ID, + DEVICE, + } = config if ( !HEARTBEAT?.loaded || @@ -215,6 +228,7 @@ export const Terminal = ({ embed }: Props) => { !DEVEUI?.loaded || !BATTERY?.loaded || !VERSION?.loaded || + !DEVICE?.loaded || !ID?.loaded ) { return @@ -223,7 +237,7 @@ export const Terminal = ({ embed }: Props) => { return ( - + {!isKeyboardVisible && ( { )} )} - + { + + Actions + + + + + + + + + + + + + + + + ID @@ -295,6 +338,29 @@ export const Terminal = ({ embed }: Props) => { + + Device + + + + {DEVICE.loaded && ( + + Device name:{" "} + {deviceLoading ? ( + "Loading..." + ) : ( + {DEVICE.value} + )} + + )} + + + + + + Version @@ -341,35 +407,6 @@ export const Terminal = ({ embed }: Props) => { - - Actions - - - - - - - - - - - - - - - - Heartbeat @@ -545,6 +582,12 @@ const formatHeartbeat = (s?: string) => { } const styles = StyleSheet.create({ + container: { + flex: 1, + flexDirection: "row", + alignItems: "center", + justifyContent: "center", + }, scrollContainer: { flex: 1 }, scroll: { flex: 1 }, view: { height: 150 }, @@ -556,7 +599,6 @@ const styles = StyleSheet.create({ input: { flexDirection: "row", alignItems: "center", - height: 40, }, inputText: { flex: 2 }, buttons: {