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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*~
numberpad_dev
*.code-workspace
18 changes: 10 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ LOGS_INSTALL_LOG_FILE_PATH="$LOGS_DIR_PATH/$LOGS_INSTALL_LOG_FILE_NAME"
echo "Not detected package manager. Driver may not work properly because required packages have not been installed. Please create an issue (https://github.com/asus-linux-drivers/asus-numberpad-driver/issues)."
fi

# https://github.com/asus-linux-drivers/asus-numberpad-driver/pull/255
[ "$DESKTOP_SESSION" == "plasma" ] && ! command -v qdbus >/dev/null 2>&1 && {
echo
echo "You are using plasma desktop environment. It is recommended to install manually 'qt6-tools' (Plasma 6), 'qt5-tools' (Plasma 5) or similar package adequate for your plasma desktop environment version to have 'qdbus' command available for proper work of the driver." >&2
read -n1 -r -p "Press any key to continue..."
echo
}

if [[ $? != 0 ]]; then
echo "Something went wrong when installing packages"
source install_begin_send_anonymous_report.sh
Expand All @@ -112,6 +104,16 @@ LOGS_INSTALL_LOG_FILE_PATH="$LOGS_DIR_PATH/$LOGS_INSTALL_LOG_FILE_NAME"
source install_begin_send_anonymous_report.sh
fi

# https://github.com/asus-linux-drivers/asus-numberpad-driver/pull/255
[ "$DESKTOP_SESSION" == "plasma" ] && ! command -v qdbus >/dev/null 2>&1 && {
echo
echo "You are using plasma desktop environment. It is recommended to install manually 'qt6-tools' (Plasma 6), 'qt5-tools' (Plasma 5) or similar package adequate for your plasma desktop environment version to have 'qdbus' command available for proper work of the driver." >&2
read -n1 -r -p "Press any key to continue..."
echo
}
# resets for sure eventual return code 1 from statement above (! command -v qdbus >/dev/null)
true

echo

source install_user_groups.sh
Expand Down
2 changes: 2 additions & 0 deletions install_external_keyboard_toggle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])

echo

sudo mkdir -p $INSTALL_UDEV_DIR_PATH/rules.d

cat "udev/90-numberpad-external-keyboard.rules" | INSTALL_DIR_PATH=$INSTALL_DIR_PATH envsubst '$INSTALL_DIR_PATH' | sudo tee "$INSTALL_UDEV_DIR_PATH/rules.d/90-numberpad-external-keyboard.rules" >/dev/null

if [[ $? != 0 ]]; then
Expand Down
2 changes: 2 additions & 0 deletions install_power_supply_saver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ case "$RESPONSE" in [yY][eE][sS]|[yY])

echo

sudo mkdir -p $INSTALL_UDEV_DIR_PATH/rules.d

cat "udev/80-numberpad-power-supply.rules" | INSTALL_DIR_PATH=$INSTALL_DIR_PATH envsubst '$INSTALL_DIR_PATH' | sudo tee "$INSTALL_UDEV_DIR_PATH/rules.d/80-numberpad-power-supply.rules" >/dev/null

if [[ $? != 0 ]]; then
Expand Down
5 changes: 3 additions & 2 deletions install_user_groups.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ fi

# https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/231
sudo mkdir -p /etc/modules-load.d
sudo mkdir -p $INSTALL_UDEV_DIR_PATH/rules.d

echo 'KERNEL=="uinput", GROUP="uinput", MODE="0660"' | sudo tee $INSTALL_UDEV_DIR_PATH/rules.d/99-asus-numberpad-driver-uinput.rules >/dev/null
echo 'KERNEL=="uinput", GROUP="uinput", MODE="0660"' | sudo tee $INSTALL_UDEV_DIR_PATH/rules.d/55-asus-numberpad-driver-uinput.rules >/dev/null
echo 'uinput' | sudo tee /etc/modules-load.d/uinput-asus-numberpad-driver.conf >/dev/null
echo 'SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660"' | sudo tee $INSTALL_UDEV_DIR_PATH/rules.d/99-asus-numberpad-driver-i2c-dev.rules >/dev/null
echo 'SUBSYSTEM=="i2c-dev", KERNEL=="i2c-[0-9]*", GROUP="i2c", MODE="0660"' | sudo tee $INSTALL_UDEV_DIR_PATH/rules.d/55-asus-numberpad-driver-i2c-dev.rules >/dev/null
echo "i2c-dev" | sudo tee /etc/modules-load.d/i2c-dev-asus-numberpad-driver.conf >/dev/null

if [[ $? != 0 ]]; then
Expand Down
43 changes: 31 additions & 12 deletions numberpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pywayland.client import Display
from pywayland.protocol.wayland import WlSeat
import mmap
from smbus2 import SMBus, i2c_msg
from periphery import I2C
import signal
import math
import glob
Expand Down Expand Up @@ -732,12 +732,16 @@ def send_value_to_touchpad_via_i2c(value):
global device_id, device_addr

try:
with SMBus(int(device_id)) as bus:
data = [0x05, 0x00, 0x3d, 0x03, 0x06, 0x00, 0x07, 0x00, 0x0d, 0x14, 0x03, int(value, 16), 0xad]
msg = i2c_msg.write(device_addr, data)
bus.i2c_rdwr(msg)
path = f"/dev/i2c-{device_id}"
with I2C(path) as i2c:
data = [0x05, 0x00, 0x3d, 0x03, 0x06, 0x00, 0x07, 0x00,
0x0d, 0x14, 0x03, int(value, 16), 0xad]
msg = I2C.Message(data)
i2c.transfer(device_addr, [msg])
except PermissionError:
log.error('Permission denied during I2C communication. Please ensure you are in the "i2c" group.')
except Exception as e:
log.error('Error during sending via i2c: \"%s\"', e)
log.error('Error during sending via i2c: "%s"', e)


def parse_value_from_config(value):
Expand Down Expand Up @@ -1064,13 +1068,15 @@ def get_compose_key_start_events_for_unicode_string(reset_udev = True):

# Open a handle to "/dev/i2c-x", representing the I2C bus
try:
bus = SMBus()
bus.open(int(device_id))
bus.close()
except:
log.error("Can't open the I2C bus connection (id: %s)", device_id)
path = f"/dev/i2c-{device_id}"
i2c = I2C(path)
i2c.close()
except PermissionError:
log.error("Permission denied when opening I2C bus (id: %s). Please ensure you are in the 'i2c' group and that udev rules are applied. Try logging out and back in, or reboot.", device_id)
sys.exit(1)
except Exception as e:
log.error("Can't open the I2C bus connection (id: %s): %s", device_id, e)
sys.exit(1)


# Start monitoring the touchpad
fd_t = open('/dev/input/event' + str(touchpad), 'rb')
Expand Down Expand Up @@ -1884,6 +1890,19 @@ def unpressed_numpad_key(replaced_by_key=None):
except OSError as e:
log.warning("Cannot send press event, %s", e)

if replaced_by_key:
abs_mt_slot_numpad_key[abs_mt_slot_value] = replaced_by_key
else:
set_none_to_current_mt_slot()

if enabled_touchpad_pointer == 1:
ungrab
if events:
try:
udev.send_events(events)
except OSError as e:
log.warning("Cannot send press event, %s", e)

if replaced_by_key:
abs_mt_slot_numpad_key[abs_mt_slot_value] = replaced_by_key
else:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ libevdev
numpy
pyinotify
python-xlib
smbus2
python-periphery
pyasyncore
pywayland
xkbcommon<1.1
Expand Down
4 changes: 2 additions & 2 deletions uninstall_user_groups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ source non_sudo_check.sh

echo $INSTALL_UDEV_DIR_PATH

sudo rm -f $INSTALL_UDEV_DIR_PATH/rules.d/99-asus-numberpad-driver-uinput.rules
sudo rm -f $INSTALL_UDEV_DIR_PATH/rules.d/55-asus-numberpad-driver-uinput.rules

if [[ $? != 0 ]]; then
echo "Something went wrong when removing the uinput udev rule"
fi

sudo rm -f $INSTALL_UDEV_DIR_PATH/rules.d/99-asus-numberpad-driver-i2c-dev.rules
sudo rm -f $INSTALL_UDEV_DIR_PATH/rules.d/55-asus-numberpad-driver-i2c-dev.rules
if [[ $? != 0 ]]; then
echo "Something went wrong when removing the i2c-dev udev rule"
fi
Expand Down