Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions dcsFiles/TheWay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function LuaExportStop()
crosshair:setVisible(false)
end

local data
local keys = nil
local busy = false;
local isPressed = false
local currCommandIndex = 1
Expand All @@ -58,14 +58,8 @@ local lastNeedDepress = true
local whenToDepress = nil
local crosshairVisible = false
local stringtoboolean={ ["true"]=true, ["false"]=false }
function LuaExportBeforeNextFrame()
if upstreamLuaExportBeforeNextFrame ~= nil then
successful, err = pcall(upstreamLuaExportBeforeNextFrame)
if not successful then
log.write("THEWAY", log.ERROR, "Error in upstream LuaExportBeforeNextFrame function" .. tostring(err))
end
end

function pressKeys()
if busy then
if isPressed then
-- check if the time has come to depress
Expand All @@ -79,9 +73,6 @@ function LuaExportBeforeNextFrame()
currCommandIndex = currCommandIndex + 1
end
else
-- Prepare for new button push
local decodedData = JSON:decode(data)
local keys = decodedData["payload"]
--check if there are buttons left to press
if currCommandIndex <= #keys then
lastDevice = keys[currCommandIndex]["device"]
Expand All @@ -97,32 +88,53 @@ function LuaExportBeforeNextFrame()
isPressed = true
else
--if there's nothing else to press, we are done
keys = nil
busy = false
currCommandIndex = 1
end
end
else
local client, err = tcpServer:accept()
if client ~= nil then
client:settimeout(10)
data, err = client:receive()
if err then
log.write("THEWAY", log.ERROR, "Error at receiving: " .. err)
end
end
end

if data then
local keys = JSON:decode(data)
if keys["type"] == "waypoints" then
busy = true
elseif keys["type"] == "crosshair" then
local shouldBeVisible = stringtoboolean[keys["payload"]]
crosshair:setVisible(shouldBeVisible)
end
function checkSocket()
local client, err = tcpServer:accept()
if client ~= nil then
client:settimeout(10)
local data, err = client:receive()
if err then
log.write("THEWAY", log.ERROR, "Error at receiving: " .. err)
end

if data then
local decodedData = JSON:decode(data)
if decodedData["type"] == "waypoints" then
keys = decodedData["payload"]
busy = true
currCommandIndex = 1
elseif decodedData["type"] == "crosshair" then
local shouldBeVisible = stringtoboolean[decodedData["payload"]]
crosshair:setVisible(shouldBeVisible)
elseif decodedData["type"] == "abort" then
keys = nil
busy = false
currCommandIndex = 1
end
end
end
end

function LuaExportBeforeNextFrame()
if upstreamLuaExportBeforeNextFrame ~= nil then
successful, err = pcall(upstreamLuaExportBeforeNextFrame)
if not successful then
log.write("THEWAY", log.ERROR, "Error in upstream LuaExportBeforeNextFrame function" .. tostring(err))
end
end

pressKeys()
checkSocket()
end

function LuaExportAfterNextFrame()
if upstreamLuaExportAfterNextFrame ~= nil then
successful, err = pcall(upstreamLuaExportAfterNextFrame)
Expand All @@ -145,6 +157,7 @@ function LuaExportAfterNextFrame()
message["coords"]["lat"] = tostring(coords.latitude)
message["coords"]["long"] = tostring(coords.longitude)
message["elev"] = tostring(elevation)
message["busy"] = busy
local toSend = JSON:encode(message)

if pcall(function()
Expand Down
5 changes: 5 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function App() {
ipcRenderer.send("messageToDcs", commands);
}, [dcsWaypoints, module, userPreferences]);

const handleAbort = useCallback(async() => {
ipcRenderer.send("messageToDcs", { type: "abort" });
}, []);

const handleFileSave = useCallback(() => {
ipcRenderer.send("saveFile", JSON.stringify(dcsWaypoints));
}, [dcsWaypoints]);
Expand Down Expand Up @@ -112,6 +116,7 @@ function App() {
<Box sx={{ height: "15%" }}>
<TransferControls
onTransfer={handleTransfer}
onAbort={handleAbort}
onSaveFile={handleFileSave}
/>
</Box>
Expand Down
41 changes: 29 additions & 12 deletions src/components/TransferControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,37 @@ import { useSelector } from "react-redux";

const TransferControls = (props) => {
const waypointList = useSelector((state) => state.waypoints.dcsWaypoints);
const { module } = useSelector((state) => state.dcsPoint);
const { module, busy } = useSelector((state) => state.dcsPoint);
const allowSaveFile = waypointList.length > 0;
const allowTransfer = allowSaveFile && module && module !== "Spectator";

function button() {
if(busy) {
return <Fab
variant="extended"
color="warning"
onClick={props.onAbort}
>
<Typography variant="button" pr={2}>
<b>Abort transfer</b>
</Typography>
<SendIcon />
</Fab>;
} else {
return <Fab
variant="extended"
color="primary"
onClick={props.onTransfer}
disabled={!allowTransfer}
>
<Typography variant="button" pr={2}>
<b>Transfer to DCS</b>
</Typography>
<SendIcon />
</Fab>;
}
}

return (
<>
<Grid
Expand All @@ -32,17 +59,7 @@ const TransferControls = (props) => {
</Tooltip>
</Grid>
<Grid item>
<Fab
variant="extended"
color="primary"
onClick={props.onTransfer}
disabled={!allowTransfer}
>
<Typography variant="button" pr={2}>
<b>Transfer to DCS</b>
</Typography>
<SendIcon />
</Fab>
{ button() }
</Grid>
</Grid>
</>
Expand Down
5 changes: 3 additions & 2 deletions src/store/dcsPoint.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { createSlice } from "@reduxjs/toolkit";

const initialState = { module: null, lat: null, long: null, elev: null };
const initialState = { module: null, lat: null, long: null, elev: null, busy: null };

const dcsPointSlice = createSlice({
name: "dcsPoint",
initialState,
reducers: {
changeCoords(state, action) {
// { "model": "F-16C_50", "coords": { "lat": "41.905925545347", "long": "43.783457188399"} , "elev": "1677.6647949219"}
// { "model": "F-16C_50", "coords": { "lat": "41.905925545347", "long": "43.783457188399"} , "elev": "1677.6647949219", "busy": false}
state.module = action.payload.model;
state.lat = Number(action.payload.coords.lat);
state.long = Number(action.payload.coords.long);
state.elev = Number(action.payload.elev);
state.busy = action.payload.busy;
},
},
});
Expand Down