From 63579b2301ac97583c9376bb8f4c31ae5c36c54f Mon Sep 17 00:00:00 2001 From: Ken Chen Date: Sat, 29 May 2021 13:03:50 +1000 Subject: sample CLI implementation --- .gitignore | 2 +- Makefile | 28 ++++++++++++++++------------ src/cli.c | 17 ----------------- src/sample_cli.c | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 30 deletions(-) delete mode 100644 src/cli.c create mode 100644 src/sample_cli.c diff --git a/.gitignore b/.gitignore index 3965cbd..838b908 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ obj *.so -cli +sample_cli diff --git a/Makefile b/Makefile index 2544624..e2a0620 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: all clean re + NAME=razermacos LIB_TARGET_NAME=lib$(NAME).so SRC=src @@ -5,8 +7,11 @@ LIB=lib OBJ=obj INCLUDE=include -LIBRARY_SOURCES=$(wildcard $(SRC)/$(LIB)/*.c) -OBJECTS=$(patsubst $(SRC)/$(LIB)/%.c, $(OBJ)/%.o, $(LIBRARY_SOURCES)) +LIB_SOURCES=$(wildcard $(SRC)/$(LIB)/*.c) +LIB_OBJECTS=$(patsubst $(SRC)/$(LIB)/%.c, $(OBJ)/%.o, $(LIB_SOURCES)) + +CLI_SOURCES=$(wildcard $(SRC)/*.c) +CLI_OBJECTS=$(patsubst $(SRC)//%.c, $(OBJ)/%.o, $(CLI_SOURCES)) GREEN=\033[0;32m BLUE=\033[0;34m @@ -18,24 +23,23 @@ CC=gcc CFLAGS=-Wall -framework CoreFoundation -framework IOKit -# all: $(LIB_TARGET_NAME) -all: cli +all: sample_cli clean: - @rm -f $(OBJECTS) $(LIB_TARGET_NAME) + @rm -f $(LIB_OBJECTS) $(LIB_TARGET_NAME) @printf "$(BLUE) ✗ Deletion of object files\n"; - @printf "$(RED) ✗ Deletion of $(NAME)\n"; - + @printf "$(RED) ✗ Deletion of $(LIB_TARGET_NAME)\n"; + @printf "$(RED) ✗ Deletion of sample_cli\n"; # Remake re: clean all -cli: $(LIB_TARGET_NAME) - @$(CC) $(CFLAGS) -L. -I$(SRC)/$(INCLUDE) -o cli $(SRC)/cli.c -l$(NAME) - @printf "$(GREEN) ✓ Building cli\n" - +sample_cli: $(LIB_TARGET_NAME) $(CLI_OBJECTS) + @$(CC) $(CFLAGS) -L. -I$(SRC)/$(INCLUDE) -o sample_cli $(SRC)/sample_cli.c -l$(NAME) + @printf "$(GREEN) ✓ Building sample_cli\n" + -$(LIB_TARGET_NAME): $(OBJECTS) +$(LIB_TARGET_NAME): $(LIB_OBJECTS) @$(CC) $(CFLAGS) -fPIC -o $@ $^ -shared @printf "$(GREEN) ✓ Building $(LIB_TARGET_NAME)\n" diff --git a/src/cli.c b/src/cli.c deleted file mode 100644 index 138410f..0000000 --- a/src/cli.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "razerdevice.h" -#include "razerkbd_driver.h" - -int main(int argc, const char * argv[]) { - - IOUSBDeviceInterface **dev = getRazerUSBDeviceInterface(0); - printf("Getting Razer usb device\n"); - - if (dev == NULL) { - printf("No device found\n"); - return -1; // Assume appropriate error message displayed during the lookup - } - - return 0; - -} diff --git a/src/sample_cli.c b/src/sample_cli.c new file mode 100644 index 0000000..5236c23 --- /dev/null +++ b/src/sample_cli.c @@ -0,0 +1,19 @@ +#include +#include "razerdevice.h" +#include "razerkbd_driver.h" + +int main(int argc, const char * argv[]) { + RazerDevices allDevices = getAllRazerDevices(); + RazerDevice *razerDevices = allDevices.devices; + + printf("%d Razer device(s) found:\n", allDevices.size); + + for (int i = 0; i < allDevices.size; i++) { + RazerDevice device = razerDevices[i]; + printf("%#06x\n", device.productId); + } + + closeAllRazerDevices(allDevices); + return 0; + +} -- cgit v1.2.3