Skip to content

Commit

Permalink
More work on replacement of ptt system
Browse files Browse the repository at this point in the history
  • Loading branch information
pierr3 committed May 8, 2024
1 parent 797d0cb commit b7b7c62
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 92 deletions.
1 change: 1 addition & 0 deletions backend/js/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ exports.AfvEventTypes = {
VuMeter: "VuMeter",
NetworkConnected: "network-connected",
NetworkDisconnected: "network-disconnected",
PttKeySet: "UpdatePttKeyName",
};
30 changes: 16 additions & 14 deletions backend/src/InputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ void InputHandler::updatePttKey(int key, bool isJoystickButton, int joystickId)
UserSettings::isJoystickButton = isJoystickButton;
UserSettings::JoystickId = joystickId;

forwardPttKeyName();
InputHandler::forwardPttKeyName();
}

// NOLINTNEXTLINE
void InputHandler::onTimer(Poco::Timer& /*timer*/)
{
sf::Joystick::update();

std::lock_guard<std::mutex> lock(m);
if (isPttSetupRunning) {

Expand All @@ -52,7 +52,7 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/)
updatePttKey(i, false);

isPttSetupRunning = false;
break;
return;
}
}

Expand All @@ -65,13 +65,9 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/)
updatePttKey(j, true, i);

isPttSetupRunning = false;
break;
return;
}
}

if (!isPttSetupRunning) {
break;
}
}
}

Expand Down Expand Up @@ -108,13 +104,19 @@ void InputHandler::onTimer(Poco::Timer& /*timer*/)

void InputHandler::forwardPttKeyName()
{
if (callbackAvailable) {
auto pttKeyName = getPttKeyName();
callbackRef.NonBlockingCall([pttKeyName](Napi::Env env, Napi::Function jsCallback) {
jsCallback.Call({ Napi::String::New(env, "UpdatePttKeyName"),
Napi::String::New(env, pttKeyName), Napi::String::New(env, "") });
});
TRACK_LOG_INFO("Forwarding Ptt Key Nam 1e");

if (!callbackAvailable) {
return;
}

TRACK_LOG_INFO("Forwarding Ptt Key Name {}", getPttKeyName());

auto pttKeyName = getPttKeyName();
callbackRef.NonBlockingCall([pttKeyName](Napi::Env env, Napi::Function jsCallback) {
jsCallback.Call({ Napi::String::New(env, "UpdatePttKeyName"),
Napi::String::New(env, pttKeyName), Napi::String::New(env, "") });
});
}

std::string InputHandler::getPttKeyName()
Expand Down
14 changes: 14 additions & 0 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ void StopAudio(const Napi::CallbackInfo& /*info*/)
mClient->StopAudio();
}

void SetupPttBegin(const Napi::CallbackInfo& /*info*/)
{
mainStaticData::inputHandler->startPttSetup();
}

void SetupPttEnd(const Napi::CallbackInfo& /*info*/)
{
mainStaticData::inputHandler->stopPttSetup();
}

static void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* data2)
{
if (!callbackAvailable) {
Expand Down Expand Up @@ -853,6 +863,10 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)

exports.Set(Napi::String::New(env, "StopAudio"), Napi::Function::New(env, StopAudio));

exports.Set(Napi::String::New(env, "SetupPttBegin"), Napi::Function::New(env, SetupPttBegin));

exports.Set(Napi::String::New(env, "SetupPttEnd"), Napi::Function::New(env, SetupPttEnd));

exports.Set(Napi::String::New(env, "Exit"), Napi::Function::New(env, Exit));

return exports;
Expand Down
10 changes: 9 additions & 1 deletion backend/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export declare const AfvEventTypes: {
NetworkConnected: string;
NetworkDisconnected: string;
VuMeter: string;
PttKeySet: string;
};

declare namespace TrackAudioAfv {
Expand Down Expand Up @@ -84,7 +85,14 @@ declare namespace TrackAudioAfv {
func: (arg: string, arg2: string, arg3: string) => void
): void;

export function SetupPttBegin(): void;
export function SetupPttEnd(): void;

export function IsConnected(): boolean;
export function Bootstrap(resourcePath: string): {canRun: boolean, needUpdate: boolean, version: string};
export function Bootstrap(resourcePath: string): {
canRun: boolean;
needUpdate: boolean;
version: string;
};
export function Exit(): void;
}
25 changes: 11 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@sentry/react": "7.113.0",
"bootstrap": "^5.3.3",
"bootstrap-scss": "^5.3.3",
"build-backend": "^1.0.2",
"clsx": "^2.1.0",
"electron-store": "^8.2.0",
"i": "^0.3.7",
Expand All @@ -73,7 +74,6 @@
"sass": "^1.74.1",
"styled-components": "^5.3.11",
"trackaudio-afv": "file:backend/trackaudio-afv-1.0.0.tgz",
"uiohook-napi": "1.5.2",
"use-debounce": "^10.0.0",
"zustand": "^4.5.2"
},
Expand Down
13 changes: 7 additions & 6 deletions src/app/components/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Bootsrap: React.FC = () => {
useRadioState
.getState()
.setTransceiverCountForStationCallsign(station, parseInt(count));
},
}
);

window.api.on(
Expand All @@ -39,16 +39,16 @@ const Bootsrap: React.FC = () => {
.addRadio(
freq,
station,
useSessionStore.getState().getStationCallsign(),
useSessionStore.getState().getStationCallsign()
);
void window.api.SetRadioGain(
useSessionStore.getState().radioGain / 100,
useSessionStore.getState().radioGain / 100
);
})
.catch((err: unknown) => {
console.error(err);
});
},
}
);

window.api.on("FrequencyRxBegin", (frequency: string) => {
Expand Down Expand Up @@ -98,7 +98,7 @@ const Bootsrap: React.FC = () => {
const frequency = parseInt(dataArr[1]);
useSessionStore.getState().setIsAtc(isAtc);
useSessionStore.getState().setFrequency(frequency);
},
}
);

window.api.on("network-disconnected", () => {
Expand All @@ -109,7 +109,8 @@ const Bootsrap: React.FC = () => {
});

window.api.on("ptt-key-set", (key: string) => {
useSessionStore.getState().setPttKeyName(key);
console.log("Ptt key set to", key);
useUtilStore.getState().setPttKeyName(key);
});

window.api
Expand Down
19 changes: 7 additions & 12 deletions src/app/components/settings-modal/settings-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import AudioInput from "./audio-input";
import AudioOutputs from "./audio-outputs";
import useUtilStore from "../../store/utilStore";
import clsx from "clsx";
import useSessionStore from "../../store/sessionStore";
import { useDebouncedCallback } from "use-debounce";
import { Configuration } from "../../../config.d";
import { AudioApi, AudioDevice } from "trackaudio-afv";
Expand All @@ -23,28 +22,25 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
const [changesSaved, setChangesSaved] = useState(SaveStatus.NoChanges);
const [audioApis, setAudioApis] = useState(Array<AudioApi>);
const [audioOutputDevices, setAudioOutputDevices] = useState(
Array<AudioDevice>,
Array<AudioDevice>
);
const [audioInputDevices, setAudioInputDevices] = useState(
Array<AudioDevice>,
Array<AudioDevice>
);
const [hardwareType, setHardwareType] = useState(0);
const [config, setConfig] = useState({} as Configuration);
const [alwaysOnTop, setAlwaysOnTop] = useState(0);

const [isSettingPtt, setIsSettingPtt] = useState(false);
const [pttKeyName, setPttKeyName] = useSessionStore((state) => [
state.pttKeyName,
state.setPttKeyName,
]);

const [cid, setCid] = useState("");
const [password, setPassword] = useState("");

const [vu, vuPeak, updateVu] = useUtilStore((state) => [
const [vu, vuPeak, updateVu, pttKeyName] = useUtilStore((state) => [
state.vu,
state.peakVu,
state.updateVu,
state.pttKeyName,
]);
const [isMicTesting, setIsMicTesting] = useState(false);

Expand All @@ -56,7 +52,6 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
setCid(config.cid || "");
setPassword(config.password || "");
setHardwareType(config.hardwareType || 0);
setPttKeyName(config.pttKeyName || "None");
setAlwaysOnTop(config.alwaysOnTop ? 1 : 0);
})
.catch((err: unknown) => {
Expand Down Expand Up @@ -89,7 +84,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
.catch((err: unknown) => {
console.error(err);
});
}, [config.audioApi, setPttKeyName]);
}, [config.audioApi]);

const debouncedCid = useDebouncedCallback((cid: string) => {
setChangesSaved(SaveStatus.Saving);
Expand Down Expand Up @@ -183,7 +178,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
};

const handleHardwareTypeChange = (
e: React.ChangeEvent<HTMLSelectElement>,
e: React.ChangeEvent<HTMLSelectElement>
) => {
setChangesSaved(SaveStatus.Saving);
const hardwareType = parseInt(e.target.value);
Expand Down Expand Up @@ -324,7 +319,7 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ closeModal }) => {
className={clsx(
"btn mt-3 w-100",
!isMicTesting && "btn-info",
isMicTesting && "btn-warning",
isMicTesting && "btn-warning"
)}
onClick={handleMicTest}
disabled={
Expand Down
5 changes: 0 additions & 5 deletions src/app/store/sessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ interface sessionStore {
isConnecting: boolean;
version: string;
frequency: number;
pttKeyName: string;
radioGain: number;
stationCallsign: string;
setCallsign: (callsign: string) => void;
Expand All @@ -18,7 +17,6 @@ interface sessionStore {
setVersion: (version: string) => void;
setNetworkConnected: (isConnected: boolean) => void;
setFrequency: (frequency: number) => void;
setPttKeyName: (pttKeyName: string) => void;
setRadioGain: (radioGain: number) => void;
setStationCallsign: (stationCallsign: string) => void;
getStationCallsign: () => string;
Expand Down Expand Up @@ -57,9 +55,6 @@ const useSessionStore = create<sessionStore>((set) => ({
setFrequency: (frequency) => {
set({ frequency });
},
setPttKeyName: (pttKeyName) => {
set({ pttKeyName });
},
setRadioGain: (radioGain) => {
set({ radioGain });
},
Expand Down
6 changes: 6 additions & 0 deletions src/app/store/utilStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ interface UtilStore {
vu: number;
peakVu: number;
platform: string;
pttKeyName: string;
setPttKeyName: (pttKeyName: string) => void;
updateVu: (vu: number, peakVu: number) => void;
updatePlatform: (platform: string) => void;
}
Expand All @@ -12,6 +14,10 @@ const useUtilStore = create<UtilStore>((set) => ({
vu: 0,
peakVu: 0,
platform: "",
pttKeyName: "",
setPttKeyName: (pttKeyName: string) => {
set({ pttKeyName });
},
updateVu: (vu: number, peakVu: number) => {
set({ vu, peakVu });
},
Expand Down
3 changes: 0 additions & 3 deletions src/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ export interface Configuration {
password: string;
callsign: string;

pttKey: number;
pttKeyName: string;
hardwareType: number;
radioGain: number;

alwaysOnTop: boolean;

consentedToTelemetry: boolean | undefined;
}
Loading

0 comments on commit b7b7c62

Please sign in to comment.