diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..917db4a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + ubuntu-build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Dependencies + run: | + sudo apt update + sudo apt install libhidapi-dev + - name: Build + run: make + + osx-build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Dependencies + run: | + brew update + brew install hidapi + - name: Build + run: make diff --git a/.gitignore b/.gitignore index 783cd5b..2ee2b7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.swp - +# binaries +scythe +footswitch diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 07ca13e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: c - -cache: apt - -dist: trusty - -sudo: false - -os: - - linux - - osx - -compiler: - - gcc - -before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install hidapi; fi - -script: - - make - -addons: - apt: - packages: - - libhidapi-dev diff --git a/19-footswitch.rules b/19-footswitch.rules index b1f3409..352f726 100644 --- a/19-footswitch.rules +++ b/19-footswitch.rules @@ -1,5 +1,9 @@ -ATTR{product}=="FootSwitch*"\ -MODE:="0666"\ -GROUP="hid"\ -RUN+="keymap $name 0x70066 screenlock"\ -SYMLINK+="footswitch" +# PCsensor +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7403", TAG+="uaccess" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7404", TAG+="uaccess" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="413d", ATTRS{idProduct}=="2107", TAG+="uaccess" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="e026", TAG+="uaccess" +# Scythe +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0426", ATTRS{idProduct}=="3011", TAG+="uaccess" +# Scythe2 +SUBSYSTEMS=="usb", ATTRS{idVendor}=="055a", ATTRS{idProduct}=="0998", TAG+="uaccess" diff --git a/HomebrewFormula/footswitch.rb b/HomebrewFormula/footswitch.rb new file mode 100644 index 0000000..2897d50 --- /dev/null +++ b/HomebrewFormula/footswitch.rb @@ -0,0 +1,13 @@ +class Footswitch < Formula + desc "Command-line utility for PCsensor foot switch" + homepage "https://github.com/rgerganov/footswitch" + license "MIT" + head "https://github.com/rgerganov/footswitch.git" + + depends_on "hidapi" + + def install + system "mkdir", "#{prefix}/bin" + system "make", "install", "PREFIX=#{prefix}" + end +end diff --git a/Makefile b/Makefile index 159193b..3b6442f 100644 --- a/Makefile +++ b/Makefile @@ -15,25 +15,30 @@ else endif endif -all: footswitch scythe +all: footswitch scythe scythe2 footswitch: footswitch.c common.c debug.c scythe: scythe.c common.c debug.c +scythe2: scythe2.c common.c debug.c install: all - $(INSTALL) footswitch $(PREFIX)/bin - $(INSTALL) scythe $(PREFIX)/bin + $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin + $(INSTALL) footswitch $(DESTDIR)$(PREFIX)/bin + $(INSTALL) scythe $(DESTDIR)$(PREFIX)/bin ifeq ($(UNAME), Linux) - $(INSTALLDATA) 19-footswitch.rules /etc/udev/rules.d + $(INSTALL) -d $(DESTDIR)$(UDEVPREFIX)/rules.d + $(INSTALLDATA) 19-footswitch.rules $(DESTDIR)$(UDEVPREFIX)/rules.d endif uninstall: - rm -f $(PREFIX)/bin/footswitch - rm -f $(PREFIX)/bin/scythe + + rm -f $(DESTDIR)$(PREFIX)/bin/footswitch + rm -f $(DESTDIR)$(PREFIX)/bin/scythe ifeq ($(UNAME), Linux) - rm -f /etc/udev/rules.d/19-footswitch.rules + rm -f $(DESTDIR)$(UDEVPREFIX)/rules.d/19-footswitch.rules endif -clean: - rm -f scythe footswitch *.o +clean: + rm -f scythe scythe2 footswitch *.o + rm -f scythe footswitch *.o diff --git a/Makefile.orig b/Makefile.orig new file mode 100644 index 0000000..c9635dd --- /dev/null +++ b/Makefile.orig @@ -0,0 +1,53 @@ +PREFIX = /usr/local +UDEVPREFIX = /etc/udev + +INSTALL = /usr/bin/install -c +INSTALLDATA = /usr/bin/install -c -m 644 +CFLAGS = -Wall +UNAME := $(shell uname) +ifeq ($(UNAME), Darwin) + CFLAGS += -DOSX $(shell pkg-config --cflags hidapi) + LDLIBS = $(shell pkg-config --libs hidapi) +else + ifeq ($(UNAME), Linux) + CFLAGS += $(shell pkg-config --cflags hidapi-libusb) + LDLIBS = $(shell pkg-config --libs hidapi-libusb) + else + LDLIBS = -lhidapi + endif +endif + +all: footswitch scythe scythe2 + +footswitch: footswitch.c common.c debug.c +scythe: scythe.c common.c debug.c +scythe2: scythe2.c common.c debug.c + +install: all + $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin + $(INSTALL) footswitch $(DESTDIR)$(PREFIX)/bin + $(INSTALL) scythe $(DESTDIR)$(PREFIX)/bin +ifeq ($(UNAME), Linux) + $(INSTALL) -d $(DESTDIR)$(UDEVPREFIX)/rules.d + $(INSTALLDATA) 19-footswitch.rules $(DESTDIR)$(UDEVPREFIX)/rules.d +endif + +<<<<<<< HEAD +uninstall: +======= +uninstall: +>>>>>>> 87f1a4f ( Changes to be committed:) + rm -f $(DESTDIR)$(PREFIX)/bin/footswitch + rm -f $(DESTDIR)$(PREFIX)/bin/scythe +ifeq ($(UNAME), Linux) + rm -f $(DESTDIR)$(UDEVPREFIX)/rules.d/19-footswitch.rules +endif + + +clean: +<<<<<<< HEAD + rm -f scythe scythe2 footswitch *.o + +======= + rm -f scythe footswitch *.o +>>>>>>> 87f1a4f ( Changes to be committed:) diff --git a/README.md b/README.md index 905ed02..e0bf216 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,23 @@ -[![Build Status](https://travis-ci.org/rgerganov/footswitch.svg?branch=master)](https://travis-ci.org/rgerganov/footswitch) +[![Build Status](https://github.com/rgerganov/footswitch/workflows/CI/badge.svg)](https://github.com/rgerganov/footswitch/actions) Footswitch ---------- -Command line utlities for programming [PCsensor][1] and Scythe foot switches. There is support for both single pedal devices and three pedal devices. Use the `footswitch` binary for the following combinations of `vendorId:productId`: +Command line utlities for programming [PCsensor][1] and [Scythe](https://www.scythe-eu.com/en/products/pc-accessory/usb-foot-switch-ii.html) foot switches. - * `0c45:7403` - * `0c45:7404` - * `413d:2107` +The following list of devices are supported: -Scythe switches with `vendorId:productId`=`0426:3011` can be programmed with the `scythe` binary. You can find the `vendorId` and `productId` of your device using the `lsusb` command on Linux. +| vendorId | productId | Program | +| ---------|----------| ------------ | +| 0c45 | 7403 | `footswitch` | +| 0c45 | 7404 | `footswitch` | +| 413d | 2107 | `footswitch` | +| 1a86 | e026 | `footswitch` | +| 1a86 | e02d | `footswitch` | +| 0426 | 3011 | `scythe` | +| 055a | 0998 | `scythe2` | + +You can find the `vendorId` and `productId` of your device using the `lsusb` command on Linux. The same kind of foot switches are used for building the popular [VIM Clutch][2]. @@ -24,13 +32,13 @@ The programs are using the [hidapi][3] library and should work on Linux and OSX. make sudo make install +The `install` target installs udev rules on Linux which allow running the programs without root. +You may need to use `sudo` otherwise. + To build on OSX: - brew install hidapi - git clone https://github.com/rgerganov/footswitch.git - cd footswitch - make - sudo make install + brew tap rgerganov/footswitch https://github.com/rgerganov/footswitch.git + brew install --HEAD footswitch Usage ----- diff --git a/common.c b/common.c index 0043721..a685a97 100644 --- a/common.c +++ b/common.c @@ -184,7 +184,9 @@ static const keymap_entry keymap[] = {"XF86AudioRaiseVolume", 0x80}, {"XF86AudioLowerVolume", 0x81}, {"<82>", 0x82}, + {"Hangul", 0x82}, {"<83>", 0x83}, + {"Hangul_Hanja",0x83}, {"A", 0x84}, {"B", 0x85}, {"C", 0x86}, diff --git a/common.h b/common.h index f399be3..9d0c155 100644 --- a/common.h +++ b/common.h @@ -21,12 +21,17 @@ THE SOFTWARE. */ #ifndef __COMMON_H__ #define __COMMON_H__ +#include enum modifier { CTRL = 1, SHIFT = 2, ALT = 4, WIN = 8, + R_CTRL = 16, + R_SHIFT = 32, + R_ALT = 64, + R_WIN = 128, }; enum mouse_button { @@ -36,14 +41,12 @@ enum mouse_button { MOUSE_DOUBLE = 8, }; -typedef unsigned char Bool; +bool parse_modifier(const char *arg, enum modifier *mod); +bool parse_mouse_button(const char *arg, enum mouse_button *btn); -Bool parse_modifier(const char *arg, enum modifier *mod); -Bool parse_mouse_button(const char *arg, enum mouse_button *btn); - -Bool encode_string(const char *str, unsigned char *arr); - -Bool encode_key(const char *key, unsigned char *b); +bool encode_string(const char *str, unsigned char *arr); +bool encode_char(const char ch, unsigned char *b); +bool encode_key(const char *key, unsigned char *b); const char* decode_byte(unsigned char b); diff --git a/debug.c b/debug.c index 68c039a..10694b7 100644 --- a/debug.c +++ b/debug.c @@ -23,8 +23,10 @@ THE SOFTWARE. #include "debug.h" void debug_arr(unsigned char data[], int length) { - int i; - for (i = 0 ; i < length ; i++) { + for (int i = 0 ; i < length ; i++) { + if (i > 0 && i % 16 == 0) { + printf("\n"); + } printf("%02x ", data[i]); } printf("\n"); diff --git a/footswitch b/footswitch new file mode 100755 index 0000000..df83df8 Binary files /dev/null and b/footswitch differ diff --git a/footswitch.c b/footswitch.c index e6ecd1f..67e2758 100644 --- a/footswitch.c +++ b/footswitch.c @@ -54,7 +54,8 @@ pedal_data *curr_pedal = &pd.pedals[1]; // start at the second pedal #define STRING_TYPE 4 void usage() { - fprintf(stderr, "Usage: footswitch [-123456] [-r] [-s ] [-S ] [-ak ] [-m ] [-b