aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Chen <[email protected]>2021-05-29 13:03:50 +1000
committerKen Chen <[email protected]>2021-05-29 13:03:50 +1000
commit63579b2301ac97583c9376bb8f4c31ae5c36c54f (patch)
tree4dff332e185978bc288b236ce83d8233fd0e59cd
parent2ca85a2bcdbf5e4b3938b95754d06b96de382bd9 (diff)
downloadlibrazermacos-63579b2301ac97583c9376bb8f4c31ae5c36c54f.tar.xz
librazermacos-63579b2301ac97583c9376bb8f4c31ae5c36c54f.zip
sample CLI implementation
-rw-r--r--.gitignore2
-rw-r--r--Makefile28
-rw-r--r--src/cli.c17
-rw-r--r--src/sample_cli.c19
4 files changed, 36 insertions, 30 deletions
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<stdio.h>
-#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<stdio.h>
+#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;
+
+}