Skip to content

Commit c1e669b

Browse files
authored
Merge pull request #500 from mfncooper/dev
Add support for the use of CM108 for PTT on Mac
2 parents aeb5153 + 997894c commit c1e669b

File tree

7 files changed

+129
-32
lines changed

7 files changed

+129
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
elif [ "$RUNNER_OS" == "macOS" ]; then
9797
# just to simplify I use homebrew but
9898
# we can use macports (latest direwolf is already available as port)
99-
brew install portaudio hamlib gpsd
99+
brew install portaudio hamlib gpsd hidapi
100100
elif [ "$RUNNER_OS" == "Windows" ]; then
101101
# add the folder to PATH
102102
echo "C:\msys64\mingw32\bin" >> $GITHUB_PATH

CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ elseif (HAVE_SNDIO)
351351
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SNDIO")
352352
endif()
353353

354+
elseif (APPLE)
355+
find_package(Portaudio REQUIRED)
356+
if(PORTAUDIO_FOUND)
357+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_PORTAUDIO")
358+
endif()
359+
360+
find_package(hidapi REQUIRED)
361+
if(HIDAPI_FOUND)
362+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CM108")
363+
endif()
364+
354365
elseif (NOT WIN32 AND NOT CYGWIN)
355366
find_package(Portaudio REQUIRED)
356367
if(PORTAUDIO_FOUND)
@@ -376,7 +387,10 @@ add_subdirectory(data)
376387
# external libraries
377388
add_subdirectory(${CUSTOM_GEOTRANZ_DIR})
378389
add_subdirectory(${CUSTOM_REGEX_DIR})
379-
add_subdirectory(${CUSTOM_HIDAPI_DIR})
390+
if(NOT APPLE)
391+
# Mac builds use the hidapi library, not custom local files
392+
add_subdirectory(${CUSTOM_HIDAPI_DIR})
393+
endif()
380394
add_subdirectory(${CUSTOM_MISC_DIR})
381395

382396
# direwolf source code and utilities

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,43 @@ Results will vary depending on your hardware platform and operating system versi
208208
sudo yum install direwolf
209209

210210

211-
### Macintosh OS X ###
211+
### Macintosh macOS - Using Homebrew ###
212212

213-
Read the **User Guide** in the [**doc** directory](https://github.com/wb2osz/direwolf/tree/master/doc). It is more complicated than Linux.
213+
The following instructions have been verified on macOS Ventura 13.6 (M2) and macOS High Sierra 10.13.6 (Intel).
214+
215+
First make sure that you have the following tools installed on your Mac:
216+
217+
- [Xcode or Xcode Command Line Tools](https://developer.apple.com/xcode/resources/)
218+
- [Homebrew](https://brew.sh/)
219+
220+
You will need to install the following packages using Homebrew:
221+
222+
brew install cmake
223+
brew install portaudio
224+
brew install hidapi
225+
226+
Then follow the same instructions as above for the Linux `git clone` build:
227+
228+
cd ~
229+
git clone https://www.github.com/wb2osz/direwolf
230+
cd direwolf
231+
git checkout dev
232+
mkdir build && cd build
233+
cmake ..
234+
make -j4
235+
sudo make install
236+
make install-conf
237+
238+
This gives you the latest development version. Leave out the "git checkout dev" to get the most recent stable release.
239+
240+
For more information, see the ***User Guide*** in the [**doc** directory](https://github.com/wb2osz/direwolf/tree/master/doc).
214241

215242
If you have problems, post them to the [Dire Wolf packet TNC](https://groups.io/g/direwolf) discussion group.
216243

217-
You can also install a pre-built version from Mac Ports. Keeping this up to date depends on volunteers who perform the packaging. This version could lag behind development.
244+
245+
### Macintosh macOS - Prebuilt version ###
246+
247+
You can also install a pre-built version from MacPorts. Keeping this up to date depends on volunteers who perform the packaging. This version could lag behind development.
218248

219249
sudo port install direwolf
220250

cmake/modules/Findhidapi.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# - Try to find hidapi
2+
#
3+
# HIDAPI_FOUND - system has hidapi
4+
# HIDAPI_LIBRARIES - location of the library for hidapi
5+
# HIDAPI_INCLUDE_DIRS - location of the include files for hidapi
6+
7+
set(HIDAPI_ROOT_DIR
8+
"${HIDAPI_ROOT_DIR}"
9+
CACHE
10+
PATH
11+
"Directory to search for hidapi")
12+
13+
# no need to check pkg-config
14+
15+
find_path(HIDAPI_INCLUDE_DIRS
16+
NAMES
17+
hidapi.h
18+
PATHS
19+
/usr/local/include
20+
/usr/include
21+
/opt/local/include
22+
HINTS
23+
${HIDAPI_ROOT_DIR}
24+
PATH_SUFFIXES
25+
hidapi
26+
)
27+
28+
find_library(HIDAPI_LIBRARIES
29+
NAMES
30+
hidapi
31+
PATHS
32+
/usr/local/lib
33+
/usr/lib
34+
/usr/lib64
35+
/opt/local/lib
36+
HINTS
37+
${HIDAPI_ROOT_DIR}
38+
)
39+
40+
41+
include(FindPackageHandleStandardArgs)
42+
find_package_handle_standard_args(HIDAPI DEFAULT_MSG HIDAPI_INCLUDE_DIRS HIDAPI_LIBRARIES)
43+
44+
mark_as_advanced(HIDAPI_INCLUDE_DIRS HIDAPI_LIBRARIES)

conf/generic.conf

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,13 @@
226226
%C%# https://github.com/wb2osz/direwolf-doc/blob/main/Radio-Interface-Guide.pdf
227227
%C%# goes into detail about the various options.
228228
%C%
229-
%L%# If using a C-Media CM108/CM119 or similar USB Audio Adapter,
230-
%L%# you can use a GPIO pin for PTT control. This is very convenient
231-
%L%# because a single USB connection is used for both audio and PTT.
232-
%L%# Example:
233-
%L%
234-
%L%#PTT CM108
235-
%L%
236-
%W%# If using a C-Media CM108/CM119 or similar USB Audio Adapter,
237-
%W%# you can use a GPIO pin for PTT control. This is very convenient
238-
%W%# because a single USB connection is used for both audio and PTT.
239-
%W%# Example:
240-
%W%
241-
%W%#PTT CM108
242-
%W%%C%#
229+
%C%# If using a C-Media CM108/CM119 or similar USB Audio Adapter,
230+
%C%# you can use a GPIO pin for PTT control. This is very convenient
231+
%C%# because a single USB connection is used for both audio and PTT.
232+
%C%# Example:
233+
%C%
234+
%C%#PTT CM108
235+
%C%
243236
%C%
244237
%C%# There are other possibilities such as serial port RTS, Raspberry Pi GPIO pins,
245238
%C%# and hamlib for CAT control. For more details see:

src/CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,21 @@ include_directories(
1111
${SNDIO_INCLUDE_DIRS}
1212
${CUSTOM_GEOTRANZ_DIR}
1313
${GPIOD_INCLUDE_DIRS}
14-
${CUSTOM_HIDAPI_DIR}
1514
)
1615

1716
if(WIN32 OR CYGWIN)
1817
include_directories(
18+
${CUSTOM_HIDAPI_DIR}
1919
${CUSTOM_REGEX_DIR}
2020
)
2121
endif()
2222

23+
if(APPLE)
24+
include_directories(
25+
${HIDAPI_INCLUDE_DIRS}
26+
)
27+
endif()
28+
2329

2430
# direwolf
2531
list(APPEND direwolf_SOURCES
@@ -134,6 +140,7 @@ if(LINUX)
134140
else() # macOS freebsd
135141
list(APPEND direwolf_SOURCES
136142
audio_portaudio.c
143+
cm108.c
137144
)
138145
if(USE_MACOS_DNSSD)
139146
list(APPEND direwolf_SOURCES
@@ -475,10 +482,11 @@ endif()
475482

476483
# List USB audio adapters than can use GPIO for PTT.
477484
# Originally for Linux only (using udev).
478-
# Version 1.7 adds it for Windows. Needs hidapi library.
485+
# Version 1.7 adds it for Windows. Uses local hidapi code.
486+
# Post-1.7 adds it for Mac. Uses hidapi library.
479487

480488
# cm108
481-
if(UDEV_FOUND OR WIN32 OR CYGWIN)
489+
if(UDEV_FOUND OR WIN32 OR CYGWIN OR HIDAPI_FOUND)
482490
list(APPEND cm108_SOURCES
483491
cm108.c
484492
textcolor.c
@@ -502,6 +510,12 @@ if(UDEV_FOUND OR WIN32 OR CYGWIN)
502510
)
503511
endif()
504512

513+
if (APPLE)
514+
target_link_libraries(cm108
515+
${HIDAPI_LIBRARIES}
516+
)
517+
endif()
518+
505519
if (WIN32 OR CYGWIN)
506520
target_link_libraries(cm108
507521
${HIDAPI_LIBRARIES}
@@ -574,6 +588,6 @@ install(TARGETS ttcalc DESTINATION ${INSTALL_BIN_DIR})
574588
install(TARGETS kissutil DESTINATION ${INSTALL_BIN_DIR})
575589
install(TARGETS tnctest DESTINATION ${INSTALL_BIN_DIR})
576590
install(TARGETS appserver DESTINATION ${INSTALL_BIN_DIR})
577-
if(UDEV_FOUND OR WIN32 OR CYGWIN)
591+
if(UDEV_FOUND OR WIN32 OR CYGWIN OR HIDAPI_FOUND)
578592
install(TARGETS cm108 DESTINATION ${INSTALL_BIN_DIR})
579593
endif()

src/cm108.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ int main (void)
138138
#if __WIN32__
139139
#include <wchar.h>
140140
#include "hidapi.h"
141+
#elif __APPLE__
142+
#include "hidapi.h"
141143
#else
142144
#include <libudev.h>
143145
#include <sys/types.h>
@@ -240,7 +242,7 @@ static int cm108_write (char *name, int iomask, int iodata);
240242

241243
// Used to process regular expression matching results.
242244

243-
#ifndef __WIN32__
245+
#if !defined(__WIN32__) && !defined(__APPLE__)
244246

245247
static void substr_se (char *dest, const char *src, int start, int endp1)
246248
{
@@ -318,7 +320,7 @@ static void usage(void)
318320
dw_printf ("Usage: cm108 [ device-path [ gpio-num ] ]\n");
319321
dw_printf ("\n");
320322
dw_printf ("With no command line arguments, this will produce a list of\n");
321-
#if __WIN32__
323+
#if __WIN32__ || __APPLE__
322324
dw_printf ("Human Interface Devices (HID) and indicate which ones can be\n");
323325
dw_printf ("used for GPIO PTT.\n");
324326
#else
@@ -376,11 +378,11 @@ int main (int argc, char **argv)
376378

377379
num_things = cm108_inventory (things, MAXX_THINGS);
378380

379-
#if __WIN32__
381+
#if __WIN32__ || __APPLE__
380382

381-
/////////////////////////////////////////////////////
382-
// Windows - Remove the sound related columns for now.
383-
/////////////////////////////////////////////////////
383+
////////////////////////////////////////////////////////////
384+
// Windows & Mac - Remove the sound related columns for now.
385+
////////////////////////////////////////////////////////////
384386

385387
dw_printf (" VID PID %-*s %-*s"
386388
"\n", (int)sizeof(things[0].product), "Product",
@@ -540,7 +542,7 @@ int cm108_inventory (struct thing_s *things, int max_things)
540542
int num_things = 0;
541543
memset (things, 0, sizeof(struct thing_s) * max_things);
542544

543-
#if __WIN32__
545+
#if __WIN32__ || __APPLE__
544546

545547
struct hid_device_info *devs, *cur_dev;
546548

@@ -780,7 +782,7 @@ void cm108_find_ptt (char *output_audio_device, char *ptt_device, int ptt_devic
780782
// Possible improvement: Skip if inventory already taken.
781783
num_things = cm108_inventory (things, MAXX_THINGS);
782784

783-
#if __WIN32__
785+
#if __WIN32__ || __APPLE__
784786
// FIXME - This is just a half baked implementation.
785787
// I have not been able to figure out how to find the connection
786788
// between the audio device and HID in the same package.
@@ -935,7 +937,7 @@ int cm108_set_gpio_pin (char *name, int num, int state)
935937
static int cm108_write (char *name, int iomask, int iodata)
936938
{
937939

938-
#if __WIN32__
940+
#if __WIN32__ || __APPLE__
939941

940942
//text_color_set(DW_COLOR_DEBUG);
941943
//dw_printf ("TEMP DEBUG cm108_write: %s %d %d\n", name, iomask, iodata);

0 commit comments

Comments
 (0)