Skip to content

Commit

Permalink
Merge pull request #313 from emcek/f4_draft
Browse files Browse the repository at this point in the history
F-4E Phantom II
  • Loading branch information
emcek authored May 26, 2024
2 parents 236417a + 2214c26 commit aa0d7a4
Show file tree
Hide file tree
Showing 27 changed files with 5,932 additions and 45 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## 3.5.0
* Basic support for **F-4E Phantom II** (@emcek)
* Add button to repair DCS-BIOS installation (@emcek)
* Can't start DCSpy after stopping #314 (@emcek)

## 3.4.3
* Add button to repair DCS-BIOS installation

## 3.4.2
* Fix update process when downloaded new release can not be saved in filesystem

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![image](https://img.shields.io/badge/pypi-v3.4.2-blue.svg)](https://pypi.org/project/dcspy/)
[![image](https://img.shields.io/badge/pypi-v3.5.0-blue.svg)](https://pypi.org/project/dcspy/)
[![Python CI](https://github.com/emcek/dcspy/actions/workflows/python-ci.yml/badge.svg?branch=master)](https://github.com/emcek/dcspy/actions/workflows/python-ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/emcek/dcspy/badge.svg?branch=master)](https://coveralls.io/github/emcek/dcspy?branch=master)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/5270a4fc2ba24261a3bfa7361150e8ff)](https://app.codacy.com/gh/emcek/dcspy/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
Expand Down Expand Up @@ -49,6 +49,7 @@ Why such way? Basically advanced support is for aircraft that I own and therefor
* AV-8B Night Attack Harrier - Up Front Controller and Option Display Unit
* AH-64D Apache - Enhanced Up Front Display
* F-15E Eagle - Upfront Control Panel
* F-4 Phantom II - UHF (ARC 164) Radio
* more to come...

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion dcs_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
pass

__version__ = '3.4.2'
__version__ = '3.5.0'


def start_dcspy(cli_args: Namespace) -> None:
Expand Down
10 changes: 10 additions & 0 deletions dcspy/F-4E-45MC.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DOWN: PLT_ARC_164_COMM_CHANNEL DEC
FOUR: PLT_ARC_164_AUX_CHANNEL CYCLE 1 19
LEFT: PLT_ARC_164_AUX_CHANNEL DEC
MENU: PLT_ARC_164_MODE CYCLE 1 5
OK: PLT_ARC_164_FREQ_MODE CYCLE 1 1
ONE: PLT_ARC_164_MODE CYCLE 1 5
RIGHT: PLT_ARC_164_AUX_CHANNEL INC
THREE: PLT_ARC_164_COMM_CHANNEL CYCLE 1 17
TWO: PLT_ARC_164_FREQ_MODE CYCLE 1 1
UP: PLT_ARC_164_COMM_CHANNEL INC
2 changes: 1 addition & 1 deletion dcspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dcspy.utils import check_dcs_ver, get_default_yaml, load_yaml, save_yaml

LOG = getLogger(__name__)
__version__ = '3.4.2'
__version__ = '3.5.0'

default_yaml = get_default_yaml(local_appdata=LOCAL_APPDATA)
_start_cfg = load_yaml(full_path=default_yaml)
Expand Down
61 changes: 59 additions & 2 deletions dcspy/aircraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from tempfile import gettempdir

try:
from typing import Union, Unpack
from typing import ClassVar, Union, Unpack
except ImportError:
from typing_extensions import Unpack

from typing import Union
from typing import ClassVar, Union

from PIL import Image, ImageDraw, ImageFont

Expand Down Expand Up @@ -346,6 +346,63 @@ def _replace_symbols_for_color_lcd(self, value: str) -> str:
return value


class F4E45MC(AdvancedAircraft):
"""F-4E Phantom II."""
bios_name: str = 'F-4E-45MC'
uhf_mode: ClassVar[dict[int, str]] = {
0: 'OFF',
1: 'T/R ADF',
2: 'T/R+G ADF',
3: 'ADF+G CMD',
4: 'ADF+G',
5: 'Guard ADF',
}

def __init__(self, lcd_type: LcdInfo, **kwargs: Unpack[AircraftKwargs]) -> None:
"""
Create F-4E Phantom II.
:param lcd_type: LCD type
"""
kwargs['bios_data'] = {
'PLT_ARC_164_FREQ_MODE': 0,
'PLT_ARC_164_MODE': 2,
'PLT_ARC_164_AUX_CHANNEL': 0,
'PLT_ARC_164_FREQ': '',
'PLT_ARC_164_COMM_CHANNEL': 0,
}
super().__init__(lcd_type=lcd_type, **kwargs)

def _draw_common_data(self, draw: ImageDraw.ImageDraw, separation: int) -> None:
"""
Draw common part for Mono and Color LCD.
:param draw: ImageDraw instance
:param separation: between lines in pixels
"""
if int(self.get_bios('PLT_ARC_164_FREQ_MODE')):
freq = f'{self.get_bios("PLT_ARC_164_FREQ")} *'
comm_ch = str(int(self.get_bios('PLT_ARC_164_COMM_CHANNEL')) + 1)
else:
freq = str(self.get_bios('PLT_ARC_164_FREQ'))
comm_ch = f'{int(self.get_bios("PLT_ARC_164_COMM_CHANNEL")) + 1} *'
aux_ch = int(self.get_bios('PLT_ARC_164_AUX_CHANNEL')) + 1
mode = int(self.get_bios('PLT_ARC_164_MODE'))

draw.text(xy=(0, 0), fill=self.lcd.foreground, font=self.lcd.font_s, text=f'Freq: {freq}')
draw.text(xy=(0, separation), fill=self.lcd.foreground, font=self.lcd.font_s, text=f'Comm Ch: {comm_ch}')
draw.text(xy=(0, separation * 2), fill=self.lcd.foreground, font=self.lcd.font_s, text=f'Aux Ch: {aux_ch}')
draw.text(xy=(0, separation * 3), fill=self.lcd.foreground, font=self.lcd.font_s, text=f'Mode: {self.uhf_mode[mode]}')

def draw_for_lcd_mono(self, img: Image.Image) -> None:
"""Prepare image for F-4E Phantom II Mono LCD."""
self._draw_common_data(draw=ImageDraw.Draw(img), separation=10)

def draw_for_lcd_color(self, img: Image.Image) -> None:
"""Prepare image for F-4E Phantom II Color LCD."""
self._draw_common_data(draw=ImageDraw.Draw(img), separation=24)


class F15ESE(AdvancedAircraft):
"""F-15ESE Eagle."""
bios_name: str = 'F-15ESE'
Expand Down
2 changes: 1 addition & 1 deletion dcspy/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api_ver: 3.4.2
api_ver: 3.5.0
autostart: false
check_bios: true
check_ver: true
Expand Down
13 changes: 12 additions & 1 deletion dcspy/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dcspy.utils import DEFAULT_YAML_FILE, defaults_cfg, get_config_yaml_location

LOG = getLogger(__name__)
__version__ = '3.4.2'
__version__ = '3.5.0'


def migrate(cfg: DcspyConfigYaml) -> DcspyConfigYaml:
Expand Down Expand Up @@ -56,6 +56,17 @@ def _filter_api_ver_func(cfg_ver: str) -> Iterator[Callable[[DcspyConfigYaml], N
yield globals()['_api_ver_{}'.format(api_ver.replace('.', '_'))]


def _api_ver_3_5_0(cfg: DcspyConfigYaml) -> None:
"""
Migrate to version 3.5.0.
:param cfg: Configuration dictionary
"""
user_appdata = get_config_yaml_location()
makedirs(name=user_appdata, exist_ok=True)
_copy_file(filename='F-4E-45MC.yaml', to_path=user_appdata, force=True)


def _api_ver_3_4_0(cfg: DcspyConfigYaml) -> None:
"""
Migrate to version 3.4.0.
Expand Down
1 change: 1 addition & 0 deletions dcspy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'F14A135GR': {'name': 'F-14A Tomcat', 'bios': 'F-14A-135-GR'},
'F14B': {'name': 'F-14B Tomcat', 'bios': 'F-14B'},
'AV8BNA': {'name': 'AV-8B N/A Harrier', 'bios': 'AV8BNA'},
'F4E45MC': {'name': 'F-4E Phantom II', 'bios': 'F-4E-45MC'},
}


Expand Down
2 changes: 1 addition & 1 deletion dcspy/qt_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
run_command, run_pip_command, save_yaml)

_ = qtgui_rc # prevent to remove import statement accidentally
__version__ = '3.4.2'
__version__ = '3.5.0'
LOG = getLogger(__name__)
NO_MSG_BOX = os.environ.get('DCSPY_NO_MSG_BOXES', 0)
LOGI_DEV_RADIO_BUTTON = {'rb_g19': 0, 'rb_g13': 0, 'rb_g15v1': 0, 'rb_g15v2': 0, 'rb_g510': 0,
Expand Down
2 changes: 1 addition & 1 deletion dcspy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dcspy.qt_gui import DcsPyQtGui

LOG = getLogger(__name__)
__version__ = '3.4.2'
__version__ = '3.5.0'


def run(cli_args: Namespace = Namespace()) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dcspy/starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

LOG = getLogger(__name__)
LOOP_FLAG = True
__version__ = '3.4.2'
__version__ = '3.5.0'


def _handle_connection(logi_device: LogitechDevice, parser: ProtocolParser, sock: socket.socket, ver_string: str, event: Event) -> None:
Expand Down
2 changes: 1 addition & 1 deletion dcspy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
pass

LOG = getLogger(__name__)
__version__ = '3.4.2'
__version__ = '3.5.0'
CONFIG_YAML = 'config.yaml'
DEFAULT_YAML_FILE = Path(__file__).resolve().with_name(CONFIG_YAML)

Expand Down
2 changes: 1 addition & 1 deletion generate_ver_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def generate_ver_info(major: int, minor: int, patch: int, build: int, git_sha: s
return ver_info


def save_ver_file(ver=environ.get('GITHUB_REF_NAME', '3.4.2'), bld=environ.get('GITHUB_RUN_NUMBER', '1'),
def save_ver_file(ver=environ.get('GITHUB_REF_NAME', '3.5.0'), bld=environ.get('GITHUB_RUN_NUMBER', '1'),
sha=environ.get('GITHUB_SHA', 'deadbeef'), ver_f='file_version_info.txt') -> Sequence[str]:
"""
Save generated version file based on list of strings.
Expand Down
22 changes: 20 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def _fixture(sock):
return _fixture


for plane_model in ['AdvancedAircraft', 'FA18Chornet', 'F16C50', 'F15ESE', 'Ka50', 'Ka503', 'Mi8MT',
'Mi24P', 'AH64DBLKII', 'A10C', 'A10C2', 'F14B', 'F14A135GR', 'AV8BNA']:
for plane_model in ['AdvancedAircraft', 'FA18Chornet', 'F16C50', 'F4E45MC', 'F15ESE', 'Ka50', 'Ka503',
'Mi8MT', 'Mi24P', 'AH64DBLKII', 'A10C', 'A10C2', 'F14B', 'F14A135GR', 'AV8BNA']:
for lcd in [models.LcdMono, models.LcdColor]:
airplane = getattr(aircraft, plane_model)
if lcd.type == models.LcdType.COLOR:
Expand Down Expand Up @@ -425,6 +425,24 @@ def f15ese_mono_bios():
]


@fixture()
def f4e45mc_mono_bios():
"""Bios values for F-4E Phantom II for Logitech mono LCD."""
return [
('PLT_ARC_164_FREQ_MODE', 1),
('PLT_ARC_164_MODE', 3),
('PLT_ARC_164_AUX_CHANNEL', 11),
('PLT_ARC_164_FREQ', '251.225'),
('PLT_ARC_164_COMM_CHANNEL', 8),
]


@fixture()
def f4e45mc_color_bios(f4e45mc_mono_bios):
"""Bios values for F-4E Phantom II for Logitech color LCD."""
return f4e45mc_mono_bios


@fixture()
def f15ese_color_bios(f15ese_mono_bios):
"""Bios values for F-15ESE Eagle for Logitech color LCD."""
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dcspy.sdk.lcd_sdk import LcdSdkManager
from dcspy.utils import load_json

all_plane_list = ['fa18chornet', 'f16c50', 'f15ese', 'ka50', 'ka503', 'mi8mt', 'mi24p', 'ah64dblkii', 'a10c', 'a10c2', 'f14a135gr', 'f14b', 'av8bna']
all_plane_list = ['fa18chornet', 'f16c50', 'f4e45mc', 'f15ese', 'ka50', 'ka503', 'mi8mt', 'mi24p', 'ah64dblkii', 'a10c', 'a10c2', 'f14a135gr', 'f14b', 'av8bna']


def set_bios_during_test(aircraft_model: BasicAircraft, bios_pairs: Sequence[tuple[str, Union[str, int]]]) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"F-14B": [ "CommonData", "F-14", "NS430" ],
"F-15ESE": [ "CommonData", "F-15E" ],
"F-16C_50": [ "CommonData", "F-16C_50" ],
"F-4E-45MC": [ "CommonData", "F-4E" ],
"FA-18C_hornet": [ "CommonData", "FA-18C_hornet" ],
"Ka-50": [ "CommonData", "Ka-50" ],
"Ka-50_3": [ "CommonData", "Ka-50" ],
Expand Down
Loading

0 comments on commit aa0d7a4

Please sign in to comment.