Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ONEXPLAYER X1 #4

Merged
merged 2 commits into from
Jun 4, 2024
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:

- uses: actions/checkout@v3

- name: submodules
run: |
git submodule update --init --recursive py_modules

- name: build plugin
run: |
npm i -g [email protected]
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "submodule/pyserial"]
path = submodule/pyserial
url = https://github.com/pyserial/pyserial.git
[submodule "py_modules/submodule/pyserial"]
path = py_modules/submodule/pyserial
url = https://github.com/pyserial/pyserial.git
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ deploy-steamdeck: ## Deploy plugin build to steamdeck
--exclude='.idea' . \
--exclude='.env' . \
--exclude='Makefile' . \
--exclude='./submodule' \
--exclude='./test' \
./ $(DECK_USER)@$(DECK_HOST):$(DECK_HOME)/homebrew/plugins/$(PLUGIN_FOLDER)/
@ssh $(DECK_USER)@$(DECK_HOST) -p $(DECK_PORT) -i $(DECK_KEY) \
'chmod -v 755 $(DECK_HOME)/homebrew/plugins/'
Expand Down
26 changes: 19 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def setRGB(self, r: int, g: int, b: int, brightness: int = 100):
logger.info(f"set_ledOn:{r},{g},{b}, brightness={brightness}")
LedControl.set_Color(Color(r, g, b), brightness=100)
except Exception as e:
logger.error(e)
logger.error(e, exc_info=True)
return False

async def setOff(self):
Expand All @@ -43,7 +43,7 @@ async def get_suspend_mode(self):
try:
return LedControl.get_suspend_mode()
except Exception as e:
logger.error(e)
logger.error(e, exc_info=True)
return ""

async def set_suspend_mode(self, mode: str):
Expand All @@ -54,7 +54,7 @@ async def set_suspend_mode(self, mode: str):
else:
return False
except Exception as e:
logger.error(e)
logger.error(e, exc_info=True)
return False

async def is_support_suspend_mode(self):
Expand All @@ -64,18 +64,30 @@ async def get_language(self):
try:
return sysInfoManager.get_language()
except Exception as e:
logger.error(e)
logger.error(e, exc_info=True)
return ""

async def update_latest(self):
logger.info("Updating latest")
return update.update_latest()
try:
return update.update_latest()
except Exception as e:
logger.error(e, exc_info=True)
return False

async def get_version(self):
return update.get_version()
try:
return update.get_version()
except Exception as e:
logger.error(e, exc_info=True)
return ""

async def get_latest_version(self):
return update.get_latest_version()
try:
return update.get_latest_version()
except Exception as e:
logger.error(e, exc_info=True)


# Function called first during the unload process, utilize this to handle your plugin being removed
async def _unload(self):
Expand Down
41 changes: 26 additions & 15 deletions py_modules/huesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
LED_SUSPEND_MODE_PATH,
)
from ec import EC
from hid_led.onex_led_device import OneXLEDDevice
from led.onex_led_device import OneXLEDDevice
from led.onex_led_device_serial import OneXLEDDeviceSerial
from utils import AyaJoystick, AyaLedPosition, Color, LEDLevel
from wincontrols.hardware import WinControls

Expand Down Expand Up @@ -60,22 +61,32 @@ def set_gpd_color(color: Color, brightness: int = 100):
except Exception as e:
logger.error(e, exc_info=True)

@staticmethod
def set_onex_color_hid(color: Color, brightness: int = 100):
ledDevice = OneXLEDDevice(0x1A2C, 0xB001)
# ledDevice = OneXLEDDevice(0x2f24, 0x135)
# _brightness: int = int(
# round((299 * color.R + 587 * color.G + 114 * color.B) / 1000 / 255.0 * 100)
# )
if ledDevice.is_ready():
logger.info(f"set_onex_color: color={color}, brightness={brightness}")
ledDevice.set_led_brightness(brightness)
ledDevice.set_led_color(color, color, LEDLevel.SolidColor)

@staticmethod
def set_onex_color_serial(color: Color, brightness: int = 100):
ledDevice = OneXLEDDeviceSerial()
if ledDevice.is_ready():
logger.info(f"set_onex_color_serial: color={color}")
ledDevice.set_led_brightness(brightness)
ledDevice.set_led_color(color, color, LEDLevel.SolidColor)

@staticmethod
def set_onex_color(color: Color, brightness: int = 100):
try:
ledDevice = OneXLEDDevice(0x1A2C, 0xB001)
# ledDevice = OneXLEDDevice(0x2f24, 0x135)
_brightness: int = int(
round(
(299 * color.R + 587 * color.G + 114 * color.B) / 1000 / 255.0 * 100
)
)
if ledDevice.is_ready():
logger.info(f"set_onex_color: color={color}, brightness={brightness}")
ledDevice.set_led_brightness(brightness)
ledDevice.set_led_color(color, color, LEDLevel.SolidColor)
except Exception as e:
logger.error(e, exc_info=True)
if "ONE-NETBOOK ONEXPLAYER X1" in PRODUCT_NAME:
LedControl.set_onex_color_serial(color, brightness)
else:
LedControl.set_onex_color_hid(color, brightness)

@staticmethod
def get_suspend_mode():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from math import sqrt
from itertools import repeat, chain
import hid as hid
import hid
from utils import Color, LEDLevel
from config import logger

Expand Down Expand Up @@ -41,7 +41,6 @@ def set_led_brightness(self, brightness: int) -> bool:

# Write the HID message to set the LED brightness.
self.hid_device.write(bytes(msg))
# self.hid_device.send_feature_report(bytes(msg))

return True

Expand All @@ -61,7 +60,6 @@ def set_led_color(
suffix = [0x00]

if level == LEDLevel.SolidColor:
# led_color = self.find_closest_color(main_color)
led_color = main_color
LEDOption = [0xFE]
rgbData = list(repeat([led_color.R, led_color.G, led_color.B], 20))
Expand All @@ -74,11 +72,11 @@ def set_led_color(
return False

msg = list(chain(prefix, LEDOption, chain(*rgbData), suffix))
logger.info(f"msg={msg}")
msg_hex = "".join([f"{x:02X}" for x in msg])
logger.info(f"msg={msg_hex}")
result: bytearray = bytearray(msg)

self.hid_device.write(bytes(result))
# self.hid_device.send_feature_report(bytes(result))

return True

Expand Down
105 changes: 105 additions & 0 deletions py_modules/led/onex_led_device_serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from itertools import repeat, chain
from utils import Color, LEDLevel
from config import logger
import serial
import time


class OneXLEDDeviceSerial:
def __init__(self):
self.ser = None

def is_ready(self) -> bool:
# ser = serial.Serial('/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0', baudrate = 115200, bytesize = serial.EIGHTBITS, parity = serial.PARITY_EVEN, stopbits = serial.STOPBITS_TWO)
ser = serial.Serial(
"/dev/ttyUSB0",
baudrate=115200,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_TWO,
)

if ser.isOpen():
self.ser = ser
return True
else:
try:
self.ser = ser
self.ser.open()
return True
except Exception as e:
logger.error(f"Error opening serial port: {e}")
return False

def set_led_brightness(self, brightness: int) -> bool:

if not self.is_ready():
return False

prefix = [0xFD, 0x3F, 0x00]
dataPrefix = [0x03, 0x00]
data = [0x01, 0x05, 0x04]
suffix = [0x3F, 0xFD]

fillData = list(repeat([0x00], 54))

brightness_data = list(chain(prefix, dataPrefix, data, fillData, suffix))
bytes_data = bytes(bytearray(brightness_data))

hex_data = " ".join([f"{x:02X}" for x in brightness_data])
logger.info(f"hex_data={hex_data}")

self.ser.write(bytes_data)
return True

def set_led_color(
self,
main_color: Color,
level: LEDLevel,
speed: int = 100,
) -> bool:
if not self.is_ready():
return False

prefix = [0xFD, 0x3F]

leftLed = [0x03]
rightLed = [0x04]

LEDOption = [0xFE]
dataPrefix = [0x00, 0x00]
rgbData = [0x00]

suffix = [0x3F, 0xFD]

if level == LEDLevel.SolidColor:
led_color = main_color
LEDOption = [0xFE]
rgbData = list(repeat([led_color.R, led_color.G, led_color.B], 18))

elif level == LEDLevel.Rainbow:
LEDOption = [0x03]
rgbData = list(repeat(0x00, 54))

else:
return False

left_msg = list(chain(prefix, leftLed, LEDOption, dataPrefix, rgbData, suffix))
right_msg = list(
chain(prefix, rightLed, LEDOption, dataPrefix, rgbData, suffix)
)

left_msg_hex = " ".join([f"{x:02X}" for x in left_msg])
right_msg_hex = " ".join([f"{x:02X}" for x in right_msg])

logger.info(f"left_msg hex_data={left_msg_hex}")
logger.info(f"right_msg hex_data={right_msg_hex}")

l_bytes = bytes(bytearray(left_msg))
r_bytes = bytes(bytearray(right_msg))

self.ser.write(l_bytes)
time.sleep(0.2)
self.ser.write(r_bytes)

return True
1 change: 1 addition & 0 deletions py_modules/serial
1 change: 1 addition & 0 deletions py_modules/submodule/pyserial
Submodule pyserial added at 7aeea3