From c8fb2882cbe1fb0a533e3adfb622fee35b2ca531 Mon Sep 17 00:00:00 2001 From: Haoyu Wang Date: Thu, 23 Nov 2023 00:42:00 +0800 Subject: [PATCH 1/5] added 'input as tgt' for f15e --- package-lock.json | 4 +- src/moduleCommands/GetModuleCommands.js | 12 ++- src/moduleCommands/askUserAboutSeat.js | 9 +- src/moduleCommands/f15e.js | 120 ++++++++++++++++++++---- 4 files changed, 119 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 606aa7a..4a89473 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "theway", - "version": "2.2.0", + "version": "2.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "theway", - "version": "2.2.0", + "version": "2.3.0", "dependencies": { "electron-devtools-installer": "^3.2.0", "electron-is-dev": "^2.0.0", diff --git a/src/moduleCommands/GetModuleCommands.js b/src/moduleCommands/GetModuleCommands.js index c85b6b9..4266645 100644 --- a/src/moduleCommands/GetModuleCommands.js +++ b/src/moduleCommands/GetModuleCommands.js @@ -11,10 +11,14 @@ import uh60l from "./uh60l"; export default function getModuleCommands(module, waypoints) { switch (module) { - case "F-15ESE_pilotA": - case "F-15ESE_wsoA": - case "F-15ESE_pilotB": - case "F-15ESE_wsoB": + case "F-15ESE_pilotATGT": + case "F-15ESE_wsoATGT": + case "F-15ESE_pilotBTGT": + case "F-15ESE_wsoBTGT": + case "F-15ESE_pilotANOTTGT": + case "F-15ESE_wsoANOTTGT": + case "F-15ESE_pilotBNOTTGT": + case "F-15ESE_wsoBNOTTGT": f15e.slotVariant = module; return f15e.createButtonCommands(waypoints); case "F-16C_50": diff --git a/src/moduleCommands/askUserAboutSeat.js b/src/moduleCommands/askUserAboutSeat.js index f3b65b3..baadab1 100644 --- a/src/moduleCommands/askUserAboutSeat.js +++ b/src/moduleCommands/askUserAboutSeat.js @@ -48,7 +48,14 @@ const askUserAboutSeat = async (module, userPreferences) => { op2: "B{1/B}", // op2: "B" // removed because its a nice touch to keep the explicitness of this here, instead of making it more inline. }).then((chosenRoute) => route = chosenRoute); } - return `F-15ESE_${seat.toLowerCase()}${(route === 'A{1/A}' ? "A" : "B")}`; + + let tgt; + await TwoOptionsDialog({ + title: "Input as TGT?", + op1: "YES", + op2: "NO", + }).then((asTGT) => tgt = asTGT); + return `F-15ESE_${seat.toLowerCase()}${(route === 'A{1/A}' ? "A" : "B")}${(tgt === 'YES' ? "TGT" : "NOTTGT")}`; } else if (module === "UH-60L") { if (moduleSpecificPreferences?.includes("Hide")) return "UH-60L"; else { diff --git a/src/moduleCommands/f15e.js b/src/moduleCommands/f15e.js index 1653774..2a45b18 100644 --- a/src/moduleCommands/f15e.js +++ b/src/moduleCommands/f15e.js @@ -17,21 +17,30 @@ class f15e { "shift": 3033, "A" : 3020, "B" : 3022, + "." : 3029, }; static createButtonCommands(waypoints) { let f15eUFCDevice; - if (["F-15ESE_pilotA", "F-15ESE_pilotB"].includes(this.slotVariant)) { + if (["F-15ESE_pilotATGT", "F-15ESE_pilotBTGT", "F-15ESE_pilotANOTTGT", "F-15ESE_pilotBNOTTGT"].includes(this.slotVariant)) { f15eUFCDevice = 56; } else { f15eUFCDevice = 57; } let route; // This should reduce length of code by a lot, and make it more readable. - if (this.slotVariant === "F-15ESE_pilotA" || this.slotVariant === "F-15ESE_wsoA") { + if (this.slotVariant === "F-15ESE_pilotATGT" || this.slotVariant === "F-15ESE_wsoATGT" + || this.slotVariant === "F-15ESE_pilotANOTTGT" || this.slotVariant === "F-15ESE_wsoANOTTGT") { route = this.#f15eNumberCodes["A"]; } else { route = this.#f15eNumberCodes["B"]; } + let tgt; + if (this.slotVariant === "F-15ESE_pilotATGT" || this.slotVariant === "F-15ESE_wsoATGT" + || this.slotVariant === "F-15ESE_pilotBTGT" || this.slotVariant === "F-15ESE_wsoBTGT") { + tgt = true; + } else { + tgt = false; + } { // Doesnt need to be Splice-Cleared because payload is created *each time* the function is called, and isnt static. @@ -111,22 +120,49 @@ class f15e { } ); } - payload.push( - { // press shift - device: f15eUFCDevice, - code: this.#f15eNumberCodes["shift"], - delay: this.delay, - activate: 1, - addDepress: "true", - }, - { // route letter - device: f15eUFCDevice, - code: route, - delay: this.delay, - activate: 1, - addDepress: "true", - } - ) + if (tgt == true) { + payload.push( + { // press . + device: f15eUFCDevice, + code: this.#f15eNumberCodes["."], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // press shift + device: f15eUFCDevice, + code: this.#f15eNumberCodes["shift"], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // route letter + device: f15eUFCDevice, + code: route, + delay: this.delay, + activate: 1, + addDepress: "true", + } + ) + } else { + payload.push( + { // press shift + device: f15eUFCDevice, + code: this.#f15eNumberCodes["shift"], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // route letter + device: f15eUFCDevice, + code: route, + delay: this.delay, + activate: 1, + addDepress: "true", + } + ) + } + // ============================================================ @@ -259,7 +295,52 @@ class f15e { addDepress: "true", }); } - payload.push({ // Menu UFC button + + if (tgt == true) { + payload.push({ // Menu UFC button + device: f15eUFCDevice, + code: 3038, + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // Enter 1 button (This re-selects the first waypoint) + device: f15eUFCDevice, + code: this.#f15eNumberCodes[1], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // press . + device: f15eUFCDevice, + code: this.#f15eNumberCodes["."], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // press shift + device: f15eUFCDevice, + code: 3033, + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // enter route letter + device: f15eUFCDevice, + code: route, + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // Waypoint UFC button + device: f15eUFCDevice, + code: 3010, + delay: this.delay, + activate: 1, + addDepress: "true", + },); + } else { + payload.push({ // Menu UFC button device: f15eUFCDevice, code: 3038, delay: this.delay, @@ -294,6 +375,7 @@ class f15e { activate: 1, addDepress: "true", },); + } return payload; } From dbc5d43ce67334486b1056edc1523e6cb0af071e Mon Sep 17 00:00:00 2001 From: Haoyu Wang Date: Thu, 23 Nov 2023 21:35:12 +0800 Subject: [PATCH 2/5] added 'input for JDAMs' for f15e --- TheWay.lua | 7 ++ src/components/TwoOptionsDialog.js | 17 +++ src/moduleCommands/GetModuleCommands.js | 16 +-- src/moduleCommands/askUserAboutSeat.js | 32 ++++- src/moduleCommands/f15e.js | 149 ++++++++++++++++-------- 5 files changed, 160 insertions(+), 61 deletions(-) diff --git a/TheWay.lua b/TheWay.lua index 55343fe..d92b02b 100644 --- a/TheWay.lua +++ b/TheWay.lua @@ -38,6 +38,8 @@ local lastDevice = "" local lastCode = "" local lastNeedDepress = true local whenToDepress = nil +local sleep = false +local sleepTime = 0 function LuaExportBeforeNextFrame() if upstreamLuaExportBeforeNextFrame ~= nil then successful, err = pcall(upstreamLuaExportBeforeNextFrame) @@ -57,6 +59,9 @@ function LuaExportBeforeNextFrame() end isPressed = false currCommandIndex = currCommandIndex + 1 + if sleep == true then + socket.select(nil, nil, sleepTime / 1000) + end end else -- Prepare for new button push @@ -69,6 +74,8 @@ function LuaExportBeforeNextFrame() lastNeedDepress = stringtoboolean[keys[currCommandIndex]["addDepress"]] local delay = tonumber(keys[currCommandIndex]["delay"]) local activate = tonumber(keys[currCommandIndex]["activate"]) + sleep = stringtoboolean[keys[currCommandIndex]["sleep"]] + sleepTime = tonumber(keys[currCommandIndex]["sleepTime"]) --ms -- Push the button GetDevice(lastDevice):performClickableAction(lastCode, activate) --Store the time when we will need to depress diff --git a/src/components/TwoOptionsDialog.js b/src/components/TwoOptionsDialog.js index 0efc60c..bc90070 100644 --- a/src/components/TwoOptionsDialog.js +++ b/src/components/TwoOptionsDialog.js @@ -42,4 +42,21 @@ const MuiDialog = ({isOpen, onResolve, onReject, title, op1, op2}) => { ); }; +const SimpleDialog = ({isOpen, onResolve, onReject, title, op1, op2}) => { + const handleOptionSelected = (option) => { + onResolve(option); + } + + return ( + + {title} + + + + + + ); +}; + export const TwoOptionsDialog = createModal(MuiDialog); +export const TwoOptionsSimpleDialog = createModal(SimpleDialog); diff --git a/src/moduleCommands/GetModuleCommands.js b/src/moduleCommands/GetModuleCommands.js index 4266645..153ed0c 100644 --- a/src/moduleCommands/GetModuleCommands.js +++ b/src/moduleCommands/GetModuleCommands.js @@ -11,14 +11,14 @@ import uh60l from "./uh60l"; export default function getModuleCommands(module, waypoints) { switch (module) { - case "F-15ESE_pilotATGT": - case "F-15ESE_wsoATGT": - case "F-15ESE_pilotBTGT": - case "F-15ESE_wsoBTGT": - case "F-15ESE_pilotANOTTGT": - case "F-15ESE_wsoANOTTGT": - case "F-15ESE_pilotBNOTTGT": - case "F-15ESE_wsoBNOTTGT": + case "F-15ESE_pilotAJDAM": + case "F-15ESE_wsoAJDAM": + case "F-15ESE_pilotBJDAM": + case "F-15ESE_wsoBJDAM": + case "F-15ESE_pilotANOJDAM": + case "F-15ESE_wsoANOJDAM": + case "F-15ESE_pilotBNOJDAM": + case "F-15ESE_wsoBNOJDAM": f15e.slotVariant = module; return f15e.createButtonCommands(waypoints); case "F-16C_50": diff --git a/src/moduleCommands/askUserAboutSeat.js b/src/moduleCommands/askUserAboutSeat.js index baadab1..8fbd131 100644 --- a/src/moduleCommands/askUserAboutSeat.js +++ b/src/moduleCommands/askUserAboutSeat.js @@ -1,4 +1,4 @@ -import {TwoOptionsDialog} from "../components/TwoOptionsDialog"; +import {TwoOptionsDialog, TwoOptionsSimpleDialog} from "../components/TwoOptionsDialog"; import {AlertDialog} from "../components/AlertDialog"; const askUserAboutSeat = async (module, userPreferences) => { @@ -49,13 +49,33 @@ const askUserAboutSeat = async (module, userPreferences) => { }).then((chosenRoute) => route = chosenRoute); } - let tgt; - await TwoOptionsDialog({ - title: "Input as TGT?", + let jdam; + await TwoOptionsSimpleDialog({ + title: "Input for JDAMs?", op1: "YES", op2: "NO", - }).then((asTGT) => tgt = asTGT); - return `F-15ESE_${seat.toLowerCase()}${(route === 'A{1/A}' ? "A" : "B")}${(tgt === 'YES' ? "TGT" : "NOTTGT")}`; + }).then((forJDAM) => jdam = forJDAM); + + if (seat === "Pilot" && jdam === "YES") { + await AlertDialog({ + title: "Make sure:", + content: + "1. Your RIGHT MPD is on Smart Weapons page.\n" + + "2. Used 'NXT STA' to select the bomb you want to start with.\n" + + "3. Do not program the JDAMs in PACS.(Recommend)" + }); + } else if (seat === "WSO" && jdam === "YES") { + await AlertDialog({ + title: "Make sure:", + content: + "1. The airplane's master mode is A/G\n" + + "2. Your RIGHT MPD(Green display) is on Smart Weapons page.\n" + + "3. Used 'NXT STA' to select the bomb you want to start with.\n" + + "4. Do not program the JDAMs in PACS.(Recommend)" + }); + } + + return `F-15ESE_${seat.toLowerCase()}${(route === 'A{1/A}' ? "A" : "B")}${(jdam === 'YES' ? "JDAM" : "NOJDAM")}`; } else if (module === "UH-60L") { if (moduleSpecificPreferences?.includes("Hide")) return "UH-60L"; else { diff --git a/src/moduleCommands/f15e.js b/src/moduleCommands/f15e.js index 2a45b18..54bc84e 100644 --- a/src/moduleCommands/f15e.js +++ b/src/moduleCommands/f15e.js @@ -18,28 +18,56 @@ class f15e { "A" : 3020, "B" : 3022, "." : 3029, + "PB1" : 3061, + "PB2" : 3062, + "AG" : 3127, }; + static pushJDAMOps(payload, MPDcode) { + let push_delay = 2000; + payload.push({ + device: MPDcode, + code: this.#f15eNumberCodes["PB1"], + delay: push_delay, + activate: 1, + addDepress: "true", + fastDepress: "true", + }); + payload.push({ + device: MPDcode, + code: this.#f15eNumberCodes["PB2"], + delay: this.delay, + activate: 1, + addDepress: "true", + }); + } + static createButtonCommands(waypoints) { let f15eUFCDevice; - if (["F-15ESE_pilotATGT", "F-15ESE_pilotBTGT", "F-15ESE_pilotANOTTGT", "F-15ESE_pilotBNOTTGT"].includes(this.slotVariant)) { + let f15eACC = 32; + let f15eMPDRight; + let frontSeat = false; + if (["F-15ESE_pilotAJDAM", "F-15ESE_pilotBJDAM", "F-15ESE_pilotANOJDAM", "F-15ESE_pilotBNOJDAM"].includes(this.slotVariant)) { f15eUFCDevice = 56; + f15eMPDRight = 36; + frontSeat = true; } else { f15eUFCDevice = 57; + f15eMPDRight = 39; } let route; // This should reduce length of code by a lot, and make it more readable. - if (this.slotVariant === "F-15ESE_pilotATGT" || this.slotVariant === "F-15ESE_wsoATGT" - || this.slotVariant === "F-15ESE_pilotANOTTGT" || this.slotVariant === "F-15ESE_wsoANOTTGT") { + if (this.slotVariant === "F-15ESE_pilotAJDAM" || this.slotVariant === "F-15ESE_wsoAJDAM" + || this.slotVariant === "F-15ESE_pilotANOJDAM" || this.slotVariant === "F-15ESE_wsoANOJDAM") { route = this.#f15eNumberCodes["A"]; } else { route = this.#f15eNumberCodes["B"]; } - let tgt; - if (this.slotVariant === "F-15ESE_pilotATGT" || this.slotVariant === "F-15ESE_wsoATGT" - || this.slotVariant === "F-15ESE_pilotBTGT" || this.slotVariant === "F-15ESE_wsoBTGT") { - tgt = true; + let jdam; + if (this.slotVariant === "F-15ESE_pilotAJDAM" || this.slotVariant === "F-15ESE_wsoAJDAM" + || this.slotVariant === "F-15ESE_pilotBJDAM" || this.slotVariant === "F-15ESE_wsoBJDAM") { + jdam = true; } else { - tgt = false; + jdam = false; } { @@ -103,7 +131,23 @@ class f15e { }, ]; // =================== end of setup =================== + + + // =================== Set Master Mode =================== + if (jdam === true && frontSeat === true) { + payload.push( + { // AG Switch + device: f15eACC, + code: this.#f15eNumberCodes["AG"], + delay: this.delay, + activate: 1, + addDepress: "true", + } + ); + } + // =================== end of master mode setup =================== + // =================== Enter Waypoint numbers =================== for (const waypoint of waypoints) { let waypointNumber = waypoints.indexOf(waypoint) + 1; @@ -120,7 +164,7 @@ class f15e { } ); } - if (tgt == true) { + if (jdam === true) { payload.push( { // press . device: f15eUFCDevice, @@ -143,7 +187,7 @@ class f15e { activate: 1, addDepress: "true", } - ) + ); } else { payload.push( { // press shift @@ -296,49 +340,60 @@ class f15e { }); } - if (tgt == true) { + if (jdam === true) { payload.push({ // Menu UFC button device: f15eUFCDevice, code: 3038, delay: this.delay, activate: 1, addDepress: "true", - }, - { // Enter 1 button (This re-selects the first waypoint) - device: f15eUFCDevice, - code: this.#f15eNumberCodes[1], - delay: this.delay, - activate: 1, - addDepress: "true", - }, - { // press . - device: f15eUFCDevice, - code: this.#f15eNumberCodes["."], - delay: this.delay, - activate: 1, - addDepress: "true", - }, - { // press shift - device: f15eUFCDevice, - code: 3033, - delay: this.delay, - activate: 1, - addDepress: "true", - }, - { // enter route letter - device: f15eUFCDevice, - code: route, - delay: this.delay, - activate: 1, - addDepress: "true", - }, - { // Waypoint UFC button - device: f15eUFCDevice, - code: 3010, - delay: this.delay, - activate: 1, - addDepress: "true", - },); + }); + + for (const waypoint of waypoints) { + let waypointNumber = waypoints.indexOf(waypoint) + 1; + for (let i = 0; i < (waypointNumber + '').length; i++) { + // eslint-disable-next-line default-case + let digit = (waypointNumber + '').charAt(i); + payload.push( + { // Waypoint Digit + device: f15eUFCDevice, + code: this.#f15eNumberCodes[digit], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // press . + device: f15eUFCDevice, + code: this.#f15eNumberCodes["."], + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // press shift + device: f15eUFCDevice, + code: 3033, + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // enter route letter + device: f15eUFCDevice, + code: route, + delay: this.delay, + activate: 1, + addDepress: "true", + }, + { // Waypoint UFC button + device: f15eUFCDevice, + code: 3010, + delay: this.delay, + activate: 1, + addDepress: "true", + } + ); + this.pushJDAMOps(payload, f15eMPDRight); + } + } } else { payload.push({ // Menu UFC button device: f15eUFCDevice, From a69955fee7a58a037f9438af038b44c3f10dcd69 Mon Sep 17 00:00:00 2001 From: Haoyu Wang Date: Thu, 23 Nov 2023 23:15:06 +0800 Subject: [PATCH 3/5] fixed f15e 'input for JDAMs' delay bug --- TheWay.lua | 7 ------- src/moduleCommands/f15e.js | 4 +--- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/TheWay.lua b/TheWay.lua index d92b02b..55343fe 100644 --- a/TheWay.lua +++ b/TheWay.lua @@ -38,8 +38,6 @@ local lastDevice = "" local lastCode = "" local lastNeedDepress = true local whenToDepress = nil -local sleep = false -local sleepTime = 0 function LuaExportBeforeNextFrame() if upstreamLuaExportBeforeNextFrame ~= nil then successful, err = pcall(upstreamLuaExportBeforeNextFrame) @@ -59,9 +57,6 @@ function LuaExportBeforeNextFrame() end isPressed = false currCommandIndex = currCommandIndex + 1 - if sleep == true then - socket.select(nil, nil, sleepTime / 1000) - end end else -- Prepare for new button push @@ -74,8 +69,6 @@ function LuaExportBeforeNextFrame() lastNeedDepress = stringtoboolean[keys[currCommandIndex]["addDepress"]] local delay = tonumber(keys[currCommandIndex]["delay"]) local activate = tonumber(keys[currCommandIndex]["activate"]) - sleep = stringtoboolean[keys[currCommandIndex]["sleep"]] - sleepTime = tonumber(keys[currCommandIndex]["sleepTime"]) --ms -- Push the button GetDevice(lastDevice):performClickableAction(lastCode, activate) --Store the time when we will need to depress diff --git a/src/moduleCommands/f15e.js b/src/moduleCommands/f15e.js index 54bc84e..70dfce7 100644 --- a/src/moduleCommands/f15e.js +++ b/src/moduleCommands/f15e.js @@ -24,14 +24,12 @@ class f15e { }; static pushJDAMOps(payload, MPDcode) { - let push_delay = 2000; payload.push({ device: MPDcode, code: this.#f15eNumberCodes["PB1"], - delay: push_delay, + delay: 2000, activate: 1, addDepress: "true", - fastDepress: "true", }); payload.push({ device: MPDcode, From 32a06686ce1d9db00c3e72651374ce477cca98a3 Mon Sep 17 00:00:00 2001 From: Haoyu Wang Date: Sat, 25 Nov 2023 18:11:39 +0800 Subject: [PATCH 4/5] developing 'input as PP MSN' for fa18 --- src/components/FourOptionsDialog.js | 28 ++ src/moduleCommands/GetModuleCommands.js | 2 + src/moduleCommands/askUserAboutSeat.js | 68 +-- src/moduleCommands/fa18.js | 552 ++++++++++++++++++------ 4 files changed, 489 insertions(+), 161 deletions(-) create mode 100644 src/components/FourOptionsDialog.js diff --git a/src/components/FourOptionsDialog.js b/src/components/FourOptionsDialog.js new file mode 100644 index 0000000..beaacec --- /dev/null +++ b/src/components/FourOptionsDialog.js @@ -0,0 +1,28 @@ +import { + Button, + Dialog, + DialogTitle, + Stack, + } from "@mui/material"; + import { createModal } from "react-modal-promise"; + + const FourSimpleDialog = ({ isOpen, onResolve, onReject, title, op1, op2, op3, op4 }) => { + const handleOptionSelected = (option) => { + onResolve(option); + }; + + return ( + + {title} + + + + + + + + ); + }; + + export const FourOptionsSimpleDialog = createModal(FourSimpleDialog); + \ No newline at end of file diff --git a/src/moduleCommands/GetModuleCommands.js b/src/moduleCommands/GetModuleCommands.js index d077378..0ba20ea 100644 --- a/src/moduleCommands/GetModuleCommands.js +++ b/src/moduleCommands/GetModuleCommands.js @@ -34,9 +34,11 @@ export default function getModuleCommands(module, waypoints, buttonExtraDelay) { return f16.createButtonCommands(waypoints); } case "FA-18C_hornet": + case "FA-18C_hornetPP": case "FA-18E": case "FA-18F": case "EA-18G": { + fa18.slotVariant = module; fa18.extraDelay = buttonExtraDelay; return fa18.createButtonCommands(waypoints); } diff --git a/src/moduleCommands/askUserAboutSeat.js b/src/moduleCommands/askUserAboutSeat.js index 01cca37..2057599 100644 --- a/src/moduleCommands/askUserAboutSeat.js +++ b/src/moduleCommands/askUserAboutSeat.js @@ -27,16 +27,30 @@ const askUserAboutSeat = async (module, userPreferences) => { module === "FA-18F" || module === "EA-18G" ) { - if (moduleSpecificPreferences?.includes("Hide")) return "FA-18C_hornet"; - else { - return AlertDialog({ - title: "Please make sure that", - content: - "1. PRECISE option is boxed in HSI > DATA\n" + - "2. You are not in the TAC menu\n" + - "3. You are in the 00°00.0000' coordinate format", - }).then(() => "FA-18C_hornet"); + let PPinput; + await TwoOptionsSimpleDialog({ + title: "Input as PP MSN?", + op1: "YES", + op2: "NO", + }).then((pp) => (PPinput = pp)); + + if (moduleSpecificPreferences?.includes("Hide") === false) { + if (PPinput === "YES") { + AlertDialog({ + title: "Please make sure that", + content: "Your LEFT MDI is on PP MSN Page!\n", + }); + } else { + AlertDialog({ + title: "Please make sure that", + content: + "1. PRECISE option is boxed in HSI > DATA\n" + + "2. You are not in the TAC menu\n" + + "3. You are in the 00°00.0000' coordinate format", + }); + } } + return `FA-18C_hornet${PPinput === "YES" ? "PP" : ""}`; } else if (module === "F-15ESE") { let seat; if (moduleSpecificPreferences?.includes("Pilot")) seat = "Pilot"; @@ -67,23 +81,25 @@ const askUserAboutSeat = async (module, userPreferences) => { op2: "NO", }).then((forJDAM) => (jdam = forJDAM)); - if (seat === "Pilot" && jdam === "YES") { - await AlertDialog({ - title: "Make sure:", - content: - "1. Your RIGHT MPD is on Smart Weapons page.\n" + - "2. Used 'NXT STA' to select the bomb you want to start with.\n" + - "3. Do not program the JDAMs in PACS.(Recommend)", - }); - } else if (seat === "WSO" && jdam === "YES") { - await AlertDialog({ - title: "Make sure:", - content: - "1. The airplane's master mode is A/G\n" + - "2. Your RIGHT MPD(Green display) is on Smart Weapons page.\n" + - "3. Used 'NXT STA' to select the bomb you want to start with.\n" + - "4. Do not program the JDAMs in PACS.(Recommend)", - }); + if (moduleSpecificPreferences?.includes("Hide") === false) { + if (seat === "Pilot" && jdam === "YES") { + await AlertDialog({ + title: "Make sure:", + content: + "1. Your RIGHT MPD is on Smart Weapons page.\n" + + "2. Used 'NXT STA' to select the bomb you want to start with.\n" + + "3. Do not program the JDAMs in PACS.(Recommend)", + }); + } else if (seat === "WSO" && jdam === "YES") { + await AlertDialog({ + title: "Make sure:", + content: + "1. The airplane's master mode is A/G\n" + + "2. Your RIGHT MPD(Green display) is on Smart Weapons page.\n" + + "3. Used 'NXT STA' to select the bomb you want to start with.\n" + + "4. Do not program the JDAMs in PACS.(Recommend)", + }); + } } return `F-15ESE_${seat.toLowerCase()}${route === "A{1/A}" ? "A" : "B"}${ diff --git a/src/moduleCommands/fa18.js b/src/moduleCommands/fa18.js index f24c09b..003eff5 100644 --- a/src/moduleCommands/fa18.js +++ b/src/moduleCommands/fa18.js @@ -1,10 +1,18 @@ +import { + FourOptionsSimpleDialog, +} from "../components/FourOptionsDialog"; + class fa18 { + static slotVariant = ""; static extraDelay = 0; static #delay100 = this.extraDelay + 100; static #delay200 = this.extraDelay + 200; static #delay500 = this.extraDelay + 500; static #delay800 = this.extraDelay + 800; static #delay1000 = this.extraDelay + 1000; + static device_UFC = 25; + static device_AMPCD = 37; + static device_MDILeft = 35; static #kuKeycodes = { 1: 3019, 2: 3020, @@ -16,14 +24,44 @@ class fa18 { 8: 3026, 9: 3027, 0: 3018, + PB1: 3011, + PB2: 3012, + PB3: 3013, + PB4: 3014, + PB5: 3015, + PB6: 3016, + PB7: 3017, + PB8: 3018, + PB9: 3019, + PB10: 3020, + PB11: 3021, + PB12: 3022, + PB13: 3023, + PB14: 3024, + PB15: 3025, + PB16: 3026, + PB17: 3027, + PB18: 3028, + PB19: 3029, + PB20: 3030, + UFCOpt1: 3010, + UFCOpt2: 3011, + UFCOpt3: 3012, + UFCOpt4: 3013, + UFCOpt5: 3014, + UFCEnter: 3029, + UFCNorth: 3020, + UFCSouth: 3026, + UFCEast: 3024, + UFCWest: 3022, }; static #codesPayload = []; - static #addKeyboardCode(character) { + static #addKeyboardCode(payload, character) { const characterCode = this.#kuKeycodes[character.toLowerCase()]; if (characterCode !== undefined) - this.#codesPayload.push({ - device: 25, + payload.push({ + device: this.device_UFC, code: characterCode, delay: this.#delay100, activate: 1, @@ -31,186 +69,430 @@ class fa18 { }); } - static createButtonCommands(waypoints) { - this.#codesPayload = []; - //enter the SUPT menu - this.#codesPayload.push({ - device: 37, - code: 3028, - delay: this.#delay100, + static generatePPMSNCommands(wpt, payload) { + //select STEP + payload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB13"], + delay: this.#delay500, activate: 1, addDepress: "true", }); - this.#codesPayload.push({ - device: 37, - code: 3028, - delay: this.#delay100, + + //select TGT UFC + payload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB14"], + delay: this.#delay800, activate: 1, addDepress: "true", }); - //select HSD - this.#codesPayload.push({ - device: 37, - code: 3012, - delay: this.#delay100, + + //select UFC POSN + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt3"], + delay: this.#delay200, activate: 1, addDepress: "true", }); - //select DATA - this.#codesPayload.push({ - device: 37, - code: 3020, - delay: this.#delay100, + + //=============== Input Latitude =============== + //select UFC LAT + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt1"], + delay: this.#delay200, activate: 1, addDepress: "true", }); - for (const waypoint of waypoints) { - //increment waypoint - this.#codesPayload.push({ - device: 37, - code: 3022, - delay: this.#delay500, - activate: 1, - addDepress: "true", - }); - //press UFC - this.#codesPayload.push({ - device: 37, - code: 3015, - delay: this.#delay800, + //Type hem + if (wpt.latHem === "N") { + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCNorth"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //press position 1 - this.#codesPayload.push({ - device: 25, - code: 3010, - delay: this.#delay200, + } else { + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCSouth"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //Type hem - if (waypoint.latHem === "N") { - this.#codesPayload.push({ - device: 25, - code: 3020, - delay: this.#delay100, - activate: 1, - addDepress: "true", - }); - } else { - this.#codesPayload.push({ - device: 25, - code: 3026, - delay: this.#delay100, - activate: 1, - addDepress: "true", - }); - } - //enter first lat digits - const firstLat = waypoint.lat.substring(0, waypoint.lat.length - 5); - const last4Lat = waypoint.lat.substring(waypoint.lat.length - 5); - //Type lat - for (let i = 0; i < firstLat.length; i++) { - this.#addKeyboardCode(firstLat.charAt(i)); - } - //press enter - this.#codesPayload.push({ - device: 25, - code: 3029, - delay: this.#delay1000, + } + //enter first lat digits + const firstLat = wpt.lat.substring(0, wpt.lat.length - 5); + const format_last4lat = (Number(wpt.lat.substring(wpt.lat.length - 4)) * 60 / 10000.0).toFixed(2).toString(); + const first_lat_str = firstLat + format_last4lat.substring(0, format_last4lat.length - 3); + const second_lat_str = format_last4lat.substring(format_last4lat.length - 2); + //Type lat + for (let i = 0; i < first_lat_str.length; i++) { + this.#addKeyboardCode(payload, first_lat_str.charAt(i)); + } + //press enter + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //enter last 2 digits + for (let i = 0; i < second_lat_str.length; i++) { + this.#addKeyboardCode(payload, second_lat_str.charAt(i)); + } + //press enter + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //=============== end of Input Latitude =============== + + + //=============== Input Longitude =============== + //select UFC LON + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt3"], + delay: this.#delay200, + activate: 1, + addDepress: "true", + }); + + //Type hem + if (wpt.longHem === "E") { + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEast"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //enter last 4 digits - for (let i = 0; i < last4Lat.length; i++) { - this.#addKeyboardCode(last4Lat.charAt(i)); - } - //press enter - this.#codesPayload.push({ - device: 25, - code: 3029, - delay: this.#delay1000, + } else { + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCWest"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //Type hem - if (waypoint.longHem === "E") { - this.#codesPayload.push({ - device: 25, - code: 3024, - delay: this.#delay100, - activate: 1, - addDepress: "true", - }); - } else { - this.#codesPayload.push({ - device: 25, - code: 3022, - delay: this.#delay100, + } + //enter first long digits + + const firstLong = wpt.long.substring(0, wpt.long.length - 4); + const format_last4long = (Number(wpt.long.substring(wpt.long.length - 3)) * 60 / 10000.0).toFixed(2).toString(); + const first_long_str = firstLong + format_last4long.substring(0, format_last4long.length - 3); + const second_long_str = format_last4long.substring(format_last4long.length - 2); + //Type long + for (let i = 0; i < first_long_str.length; i++) { + this.#addKeyboardCode(payload, first_long_str.charAt(i)); + } + //press enter + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //enter last 4 digits + for (let i = 0; i < second_long_str.length; i++) { + this.#addKeyboardCode(payload, second_long_str.charAt(i)); + } + //press enter + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //=============== end of Input Longitude =============== + + //select TGT UFC + payload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB14"], + delay: this.#delay800, + activate: 1, + addDepress: "true", + }); + //select TGT UFC + payload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB14"], + delay: this.#delay800, + activate: 1, + addDepress: "true", + }); + + //=============== Input Elevation =============== + //select UFC ELEV + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt4"], + delay: this.#delay200, + activate: 1, + addDepress: "true", + }); + + //press position 3 to select feet + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt3"], + delay: this.#delay200, + activate: 1, + addDepress: "true", + }); + //Type elev + for (let i = 0; i < wpt.elev.length; i++) { + this.#addKeyboardCode(payload, wpt.elev.charAt(i)); + } + //press enter + payload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay500, + activate: 1, + addDepress: "true", + }); + //=============== end of Input Elevation =============== + + //select TGT UFC + payload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB14"], + delay: this.#delay800, + activate: 1, + addDepress: "true", + }); + } + + static async createPPInputCommands(waypoints, payload) { + let stations; + await FourOptionsSimpleDialog({ + title: "How many STATIONs for each PP msn?", + op1: "1", + op2: "2", + op3: "3", + op4: "4", + }).then((sta) => (stations = Number(sta))); + + let inputNum = stations * 5; + + let ppmsn = 0; + let sta = 0; + for (let i = 0; i < Object.keys(waypoints).length() && i < inputNum; i++) { + let wpt = waypoints[i]; + this.generatePPMSNCommands(wpt, payload); + sta += 1; + if (sta === stations) { + ppmsn += 1; + sta = 0; + //select next PP MSN + payload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB6"] + ppmsn, + delay: this.#delay500, activate: 1, addDepress: "true", }); } - //enter first long digits + } + } - const firstLong = waypoint.long.substring(0, waypoint.long.length - 4); - const last4Long = waypoint.long.substring(waypoint.long.length - 4); - //Type long - for (let i = 0; i < firstLong.length; i++) { - this.#addKeyboardCode(firstLong.charAt(i)); - } - //press enter + static createButtonCommands(waypoints) { + this.#codesPayload = []; + if (this.slotVariant === "FA-18C_hornetPP") { + this.createPPInputCommands(waypoints, this.#codesPayload); + } + else { + //enter the SUPT menu this.#codesPayload.push({ - device: 25, - code: 3029, - delay: this.#delay1000, + device: this.device_AMPCD, + code: this.#kuKeycodes["PB18"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //enter last 4 digits - for (let i = 0; i < last4Long.length; i++) { - this.#addKeyboardCode(last4Long.charAt(i)); - } - //press enter this.#codesPayload.push({ - device: 25, - code: 3029, - delay: this.#delay1000, + device: this.device_AMPCD, + code: this.#kuKeycodes["PB18"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //press position 3 to select elevation + //select HSD this.#codesPayload.push({ - device: 25, - code: 3012, - delay: this.#delay200, + device: this.device_AMPCD, + code: this.#kuKeycodes["PB2"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //press position 1 to select feet + //select DATA this.#codesPayload.push({ - device: 25, - code: 3010, - delay: this.#delay200, + device: this.device_AMPCD, + code: this.#kuKeycodes["PB10"], + delay: this.#delay100, activate: 1, addDepress: "true", }); - //Type elev - for (let i = 0; i < waypoint.elev.length; i++) { - this.#addKeyboardCode(waypoint.elev.charAt(i)); + + for (const waypoint of waypoints) { + //increment waypoint + this.#codesPayload.push({ + device: this.device_AMPCD, + code: this.#kuKeycodes["PB12"], + delay: this.#delay500, + activate: 1, + addDepress: "true", + }); + //press UFC + this.#codesPayload.push({ + device: this.device_AMPCD, + code: this.#kuKeycodes["PB5"], + delay: this.#delay800, + activate: 1, + addDepress: "true", + }); + //press position 1 + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt1"], + delay: this.#delay200, + activate: 1, + addDepress: "true", + }); + //Type hem + if (waypoint.latHem === "N") { + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCNorth"], + delay: this.#delay100, + activate: 1, + addDepress: "true", + }); + } else { + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCSouth"], + delay: this.#delay100, + activate: 1, + addDepress: "true", + }); + } + //enter first lat digits + const firstLat = waypoint.lat.substring(0, waypoint.lat.length - 5); + const last4Lat = waypoint.lat.substring(waypoint.lat.length - 5); + //Type lat + for (let i = 0; i < firstLat.length; i++) { + this.#addKeyboardCode(this.#codesPayload, firstLat.charAt(i)); + } + //press enter + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //enter last 4 digits + for (let i = 0; i < last4Lat.length; i++) { + this.#addKeyboardCode(this.#codesPayload, last4Lat.charAt(i)); + } + //press enter + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //Type hem + if (waypoint.longHem === "E") { + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEast"], + delay: this.#delay100, + activate: 1, + addDepress: "true", + }); + } else { + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCWest"], + delay: this.#delay100, + activate: 1, + addDepress: "true", + }); + } + //enter first long digits + + const firstLong = waypoint.long.substring(0, waypoint.long.length - 4); + const last4Long = waypoint.long.substring(waypoint.long.length - 4); + //Type long + for (let i = 0; i < firstLong.length; i++) { + this.#addKeyboardCode(this.#codesPayload, firstLong.charAt(i)); + } + //press enter + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //enter last 4 digits + for (let i = 0; i < last4Long.length; i++) { + this.#addKeyboardCode(this.#codesPayload, last4Long.charAt(i)); + } + //press enter + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay1000, + activate: 1, + addDepress: "true", + }); + //press position 3 to select elevation + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt3"], + delay: this.#delay200, + activate: 1, + addDepress: "true", + }); + //press position 1 to select feet + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCOpt1"], + delay: this.#delay200, + activate: 1, + addDepress: "true", + }); + //Type elev + for (let i = 0; i < waypoint.elev.length; i++) { + this.#addKeyboardCode(this.#codesPayload, waypoint.elev.charAt(i)); + } + //press enter + this.#codesPayload.push({ + device: this.device_UFC, + code: this.#kuKeycodes["UFCEnter"], + delay: this.#delay500, + activate: 1, + addDepress: "true", + }); } - //press enter - this.#codesPayload.push({ - device: 25, - code: 3029, - delay: this.#delay500, - activate: 1, - addDepress: "true", - }); } - return this.#codesPayload; } } From 0c1f62ab83cbd3b8d37607cf27b1f5a8c3c13253 Mon Sep 17 00:00:00 2001 From: Haoyu Wang Date: Sun, 26 Nov 2023 00:54:35 +0800 Subject: [PATCH 5/5] implemented 'Input for PP MSN' of fa18 --- TheWay.lua | 19 +- src/moduleCommands/GetModuleCommands.js | 5 +- src/moduleCommands/askUserAboutSeat.js | 30 ++- src/moduleCommands/fa18.js | 269 +++++++++++++++--------- 4 files changed, 221 insertions(+), 102 deletions(-) diff --git a/TheWay.lua b/TheWay.lua index d67e5af..d44db8d 100644 --- a/TheWay.lua +++ b/TheWay.lua @@ -38,6 +38,8 @@ local lastDevice = "" local lastCode = "" local lastNeedDepress = true local whenToDepress = nil +local moreWait = false +local waitTime = nil function LuaExportBeforeNextFrame() if upstreamLuaExportBeforeNextFrame ~= nil then successful, err = pcall(upstreamLuaExportBeforeNextFrame) @@ -58,6 +60,11 @@ function LuaExportBeforeNextFrame() isPressed = false currCommandIndex = currCommandIndex + 1 end + elseif moreWait then + local currTime = socket.gettime() + if currTime >= waitTime then + moreWait = false + end else -- Prepare for new button push local keys = JSON:decode(data) @@ -66,9 +73,19 @@ function LuaExportBeforeNextFrame() lastDevice = keys[currCommandIndex]["device"] lastCode = keys[currCommandIndex]["code"] local stringtoboolean = { ["true"] = true,["false"] = false } - lastNeedDepress = stringtoboolean[keys[currCommandIndex]["addDepress"]] + local addDepress_str = keys[currCommandIndex]["addDepress"] + --lastNeedDepress = stringtoboolean[keys[currCommandIndex]["addDepress"]] local delay = tonumber(keys[currCommandIndex]["delay"]) local activate = tonumber(keys[currCommandIndex]["activate"]) + + if addDepress_str == "fa18wait" then + moreWait = true + waitTime = socket.gettime() + (delay / 1000) + 0.05 + lastNeedDepress = true + else + lastNeedDepress = stringtoboolean[addDepress_str] + end + -- Push the button GetDevice(lastDevice):performClickableAction(lastCode, activate) --Store the time when we will need to depress diff --git a/src/moduleCommands/GetModuleCommands.js b/src/moduleCommands/GetModuleCommands.js index 0ba20ea..1c7ea13 100644 --- a/src/moduleCommands/GetModuleCommands.js +++ b/src/moduleCommands/GetModuleCommands.js @@ -34,7 +34,10 @@ export default function getModuleCommands(module, waypoints, buttonExtraDelay) { return f16.createButtonCommands(waypoints); } case "FA-18C_hornet": - case "FA-18C_hornetPP": + case "FA-18C_hornetPP1": + case "FA-18C_hornetPP2": + case "FA-18C_hornetPP3": + case "FA-18C_hornetPP4": case "FA-18E": case "FA-18F": case "EA-18G": { diff --git a/src/moduleCommands/askUserAboutSeat.js b/src/moduleCommands/askUserAboutSeat.js index 2057599..886d0da 100644 --- a/src/moduleCommands/askUserAboutSeat.js +++ b/src/moduleCommands/askUserAboutSeat.js @@ -2,6 +2,7 @@ import { TwoOptionsDialog, TwoOptionsSimpleDialog, } from "../components/TwoOptionsDialog"; +import { FourOptionsSimpleDialog } from "../components/FourOptionsDialog"; import { AlertDialog } from "../components/AlertDialog"; const askUserAboutSeat = async (module, userPreferences) => { @@ -34,14 +35,29 @@ const askUserAboutSeat = async (module, userPreferences) => { op2: "NO", }).then((pp) => (PPinput = pp)); - if (moduleSpecificPreferences?.includes("Hide") === false) { + let stations = ""; + if (PPinput === "YES") { + await FourOptionsSimpleDialog({ + title: "How many STATIONs carry this weapon?", + op1: "1", + op2: "2", + op3: "3", + op4: "4", + }).then((sta) => (stations = sta)); + } + + let hide = false; + if (moduleSpecificPreferences?.includes("Hide")) { + hide = true; + } + if (hide === false) { if (PPinput === "YES") { - AlertDialog({ + await AlertDialog({ title: "Please make sure that", content: "Your LEFT MDI is on PP MSN Page!\n", }); } else { - AlertDialog({ + await AlertDialog({ title: "Please make sure that", content: "1. PRECISE option is boxed in HSI > DATA\n" + @@ -50,7 +66,7 @@ const askUserAboutSeat = async (module, userPreferences) => { }); } } - return `FA-18C_hornet${PPinput === "YES" ? "PP" : ""}`; + return `FA-18C_hornet${PPinput === "YES" ? "PP" : ""}${stations}`; } else if (module === "F-15ESE") { let seat; if (moduleSpecificPreferences?.includes("Pilot")) seat = "Pilot"; @@ -81,7 +97,11 @@ const askUserAboutSeat = async (module, userPreferences) => { op2: "NO", }).then((forJDAM) => (jdam = forJDAM)); - if (moduleSpecificPreferences?.includes("Hide") === false) { + let hide = false; + if (moduleSpecificPreferences?.includes("Hide")) { + hide = true; + } + if (hide === false) { if (seat === "Pilot" && jdam === "YES") { await AlertDialog({ title: "Make sure:", diff --git a/src/moduleCommands/fa18.js b/src/moduleCommands/fa18.js index 003eff5..66547d4 100644 --- a/src/moduleCommands/fa18.js +++ b/src/moduleCommands/fa18.js @@ -1,9 +1,7 @@ -import { - FourOptionsSimpleDialog, -} from "../components/FourOptionsDialog"; - +import { AlertDialog } from "../components/AlertDialog"; class fa18 { static slotVariant = ""; + static stations = 4; static extraDelay = 0; static #delay100 = this.extraDelay + 100; static #delay200 = this.extraDelay + 200; @@ -57,264 +55,345 @@ class fa18 { }; static #codesPayload = []; - static #addKeyboardCode(payload, character) { + static #addKeyboardCode(character, wait) { const characterCode = this.#kuKeycodes[character.toLowerCase()]; if (characterCode !== undefined) - payload.push({ - device: this.device_UFC, - code: characterCode, - delay: this.#delay100, - activate: 1, - addDepress: "true", - }); + if (wait === true) { + this.#codesPayload.push({ + device: this.device_UFC, + code: characterCode, + delay: this.#delay100, + activate: 1, + addDepress: "fa18wait", + }); + } else { + this.#codesPayload.push({ + device: this.device_UFC, + code: characterCode, + delay: this.#delay100, + activate: 1, + addDepress: "true", + }); + } } - static generatePPMSNCommands(wpt, payload) { + static generatePPMSNCommands(wpt) { //select STEP - payload.push({ + this.#codesPayload.push({ device: this.device_MDILeft, code: this.#kuKeycodes["PB13"], delay: this.#delay500, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //select TGT UFC - payload.push({ + this.#codesPayload.push({ device: this.device_MDILeft, code: this.#kuKeycodes["PB14"], delay: this.#delay800, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //select UFC POSN - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCOpt3"], delay: this.#delay200, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //=============== Input Latitude =============== //select UFC LAT - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCOpt1"], delay: this.#delay200, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //Type hem if (wpt.latHem === "N") { - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCNorth"], delay: this.#delay100, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); } else { - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCSouth"], delay: this.#delay100, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); } //enter first lat digits const firstLat = wpt.lat.substring(0, wpt.lat.length - 5); - const format_last4lat = (Number(wpt.lat.substring(wpt.lat.length - 4)) * 60 / 10000.0).toFixed(2).toString(); - const first_lat_str = firstLat + format_last4lat.substring(0, format_last4lat.length - 3); - const second_lat_str = format_last4lat.substring(format_last4lat.length - 2); + const format_last4lat = ( + (Number(wpt.lat.substring(wpt.lat.length - 4)) * 60) / + 10000.0 + ) + .toFixed(2) + .toString(); + + let add_to_firstLat = format_last4lat.substring( + 0, + format_last4lat.length - 3, + ); + + // only one number left, add a '0' before it + if (add_to_firstLat.length < 2) { + add_to_firstLat = "0" + add_to_firstLat; + } + + const first_lat_str = firstLat + add_to_firstLat; + const second_lat_str = format_last4lat.substring( + format_last4lat.length - 2, + ); //Type lat for (let i = 0; i < first_lat_str.length; i++) { - this.#addKeyboardCode(payload, first_lat_str.charAt(i)); + this.#addKeyboardCode(first_lat_str.charAt(i), true); } //press enter - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCEnter"], delay: this.#delay1000, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //enter last 2 digits for (let i = 0; i < second_lat_str.length; i++) { - this.#addKeyboardCode(payload, second_lat_str.charAt(i)); + this.#addKeyboardCode(second_lat_str.charAt(i), true); } //press enter - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCEnter"], delay: this.#delay1000, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //=============== end of Input Latitude =============== - //=============== Input Longitude =============== //select UFC LON - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCOpt3"], delay: this.#delay200, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //Type hem if (wpt.longHem === "E") { - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCEast"], delay: this.#delay100, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); } else { - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCWest"], delay: this.#delay100, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); } //enter first long digits const firstLong = wpt.long.substring(0, wpt.long.length - 4); - const format_last4long = (Number(wpt.long.substring(wpt.long.length - 3)) * 60 / 10000.0).toFixed(2).toString(); - const first_long_str = firstLong + format_last4long.substring(0, format_last4long.length - 3); - const second_long_str = format_last4long.substring(format_last4long.length - 2); + const format_last4long = ( + (Number(wpt.long.substring(wpt.long.length - 4)) * 60) / + 10000.0 + ) + .toFixed(2) + .toString(); + + let add_to_firstLong = format_last4long.substring( + 0, + format_last4long.length - 3, + ); + + // only one number left, add a '0' before it + if (add_to_firstLong.length < 2) { + add_to_firstLong = "0" + add_to_firstLong; + } + + let first_long_str = firstLong + add_to_firstLong; + const second_long_str = format_last4long.substring( + format_last4long.length - 2, + ); + + // remove starting '0' in longitude, if it is 1xx°, then everything's fine + if (first_long_str.charAt(0) === "0") { + first_long_str = first_long_str.substring(1); + } + //Type long for (let i = 0; i < first_long_str.length; i++) { - this.#addKeyboardCode(payload, first_long_str.charAt(i)); + this.#addKeyboardCode(first_long_str.charAt(i), true); } //press enter - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCEnter"], delay: this.#delay1000, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //enter last 4 digits for (let i = 0; i < second_long_str.length; i++) { - this.#addKeyboardCode(payload, second_long_str.charAt(i)); + this.#addKeyboardCode(second_long_str.charAt(i), true); } //press enter - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCEnter"], delay: this.#delay1000, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //=============== end of Input Longitude =============== //select TGT UFC - payload.push({ + this.#codesPayload.push({ device: this.device_MDILeft, code: this.#kuKeycodes["PB14"], delay: this.#delay800, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //select TGT UFC - payload.push({ + this.#codesPayload.push({ device: this.device_MDILeft, code: this.#kuKeycodes["PB14"], delay: this.#delay800, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //=============== Input Elevation =============== //select UFC ELEV - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCOpt4"], delay: this.#delay200, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //press position 3 to select feet - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCOpt3"], delay: this.#delay200, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //Type elev for (let i = 0; i < wpt.elev.length; i++) { - this.#addKeyboardCode(payload, wpt.elev.charAt(i)); + this.#addKeyboardCode(wpt.elev.charAt(i), true); } //press enter - payload.push({ + this.#codesPayload.push({ device: this.device_UFC, code: this.#kuKeycodes["UFCEnter"], delay: this.#delay500, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); //=============== end of Input Elevation =============== //select TGT UFC - payload.push({ + this.#codesPayload.push({ device: this.device_MDILeft, code: this.#kuKeycodes["PB14"], delay: this.#delay800, activate: 1, - addDepress: "true", + addDepress: "fa18wait", }); } - static async createPPInputCommands(waypoints, payload) { - let stations; - await FourOptionsSimpleDialog({ - title: "How many STATIONs for each PP msn?", - op1: "1", - op2: "2", - op3: "3", - op4: "4", - }).then((sta) => (stations = Number(sta))); - - let inputNum = stations * 5; + static createPPInputCommands(waypoints) { + let inputNum = this.stations * 5; let ppmsn = 0; let sta = 0; - for (let i = 0; i < Object.keys(waypoints).length() && i < inputNum; i++) { - let wpt = waypoints[i]; - this.generatePPMSNCommands(wpt, payload); - sta += 1; - if (sta === stations) { + let count = 0; + for (const wpt of waypoints) { + if (sta === this.stations) { ppmsn += 1; sta = 0; //select next PP MSN - payload.push({ - device: this.device_MDILeft, - code: this.#kuKeycodes["PB6"] + ppmsn, - delay: this.#delay500, - activate: 1, - addDepress: "true", - }); + if (ppmsn < 5) { + this.#codesPayload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB6"] + ppmsn, + delay: this.#delay500, + activate: 1, + addDepress: "fa18wait", + }); + + for (let i = 0; i < this.stations - 1; i++) { + //select STEP + this.#codesPayload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB13"], + delay: this.#delay500, + activate: 1, + addDepress: "fa18wait", + }); + + //select next PP MSN + this.#codesPayload.push({ + device: this.device_MDILeft, + code: this.#kuKeycodes["PB6"] + ppmsn, + delay: this.#delay500, + activate: 1, + addDepress: "fa18wait", + }); + } + } + } + this.generatePPMSNCommands(wpt); + count++; + sta += 1; + if (count === inputNum) { + break; } } } static createButtonCommands(waypoints) { this.#codesPayload = []; - if (this.slotVariant === "FA-18C_hornetPP") { - this.createPPInputCommands(waypoints, this.#codesPayload); - } - else { + if ( + this.slotVariant === "FA-18C_hornetPP1" || + this.slotVariant === "FA-18C_hornetPP2" || + this.slotVariant === "FA-18C_hornetPP3" || + this.slotVariant === "FA-18C_hornetPP4" + ) { + if (this.slotVariant === "FA-18C_hornetPP1") { + this.stations = 1; + } else if (this.slotVariant === "FA-18C_hornetPP2") { + this.stations = 2; + } else if (this.slotVariant === "FA-18C_hornetPP3") { + this.stations = 3; + } else { + this.stations = 4; + } + this.createPPInputCommands(waypoints); + } else { //enter the SUPT menu this.#codesPayload.push({ device: this.device_AMPCD, @@ -395,7 +474,7 @@ class fa18 { const last4Lat = waypoint.lat.substring(waypoint.lat.length - 5); //Type lat for (let i = 0; i < firstLat.length; i++) { - this.#addKeyboardCode(this.#codesPayload, firstLat.charAt(i)); + this.#addKeyboardCode(firstLat.charAt(i), false); } //press enter this.#codesPayload.push({ @@ -407,7 +486,7 @@ class fa18 { }); //enter last 4 digits for (let i = 0; i < last4Lat.length; i++) { - this.#addKeyboardCode(this.#codesPayload, last4Lat.charAt(i)); + this.#addKeyboardCode(last4Lat.charAt(i), false); } //press enter this.#codesPayload.push({ @@ -441,7 +520,7 @@ class fa18 { const last4Long = waypoint.long.substring(waypoint.long.length - 4); //Type long for (let i = 0; i < firstLong.length; i++) { - this.#addKeyboardCode(this.#codesPayload, firstLong.charAt(i)); + this.#addKeyboardCode(firstLong.charAt(i), false); } //press enter this.#codesPayload.push({ @@ -453,7 +532,7 @@ class fa18 { }); //enter last 4 digits for (let i = 0; i < last4Long.length; i++) { - this.#addKeyboardCode(this.#codesPayload, last4Long.charAt(i)); + this.#addKeyboardCode(last4Long.charAt(i), false); } //press enter this.#codesPayload.push({ @@ -481,7 +560,7 @@ class fa18 { }); //Type elev for (let i = 0; i < waypoint.elev.length; i++) { - this.#addKeyboardCode(this.#codesPayload, waypoint.elev.charAt(i)); + this.#addKeyboardCode(waypoint.elev.charAt(i), false); } //press enter this.#codesPayload.push({