Skip to content

Commit

Permalink
Squashed commit from dev branch.
Browse files Browse the repository at this point in the history
This commit version has been tested to work. Changes:

* Added PC hidapi based console software to issue commands to device.
* Hidapi moved to software/lib.
* Added argp-standalone submodule.
* Changed USB Device Name & Vendor Name. Added name to dlusb_packet struct.
* Firmware version in USB release descriptor upped to 1.02.
* Added auto software version take from git.
* Added small README file to extra dir.
  • Loading branch information
N-Storm committed Apr 17, 2024
1 parent 608518d commit 78a3096
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
path = extra/v-usb
url = https://github.com/obdev/v-usb.git
[submodule "lib/hidapi"]
path = extra/hidapi
path = software/lib/hidapi
url = https://github.com/libusb/hidapi.git
[submodule "software/lib/argp-standalone"]
path = software/lib/argp-standalone
url = https://github.com/tom42/argp-standalone.git
11 changes: 9 additions & 2 deletions DigiLivolo.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
{
"path": "firmware"
},
{
"path": "software"
},
{
"path": "."
}
],
"settings": {}
}
"settings": {
"files.associations": {
"git_version.h": "c"
}
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Example usage:

This should send Livolo command as remote ID 0x214d (77,33) and key code 0x10 (16).

## Building
## Building firmware

### With PlatformIO

Expand All @@ -84,11 +84,12 @@ it from there. Requires PlatformIO plugin installed.
* Copy `DLUSB` and `Livolo` libraries from `firmware/lib` to your Arduino libraries directory.
* Open `DigiLivolo.ino` with Arduino IDE, set board to DigiSpark and compile/upload.

## Software used
## Software & libraries used

* [PlatformIO](https://platformio.org/)
* [DigistumpArduino](https://github.com/ArminJo/DigistumpArduino)
* [V-USB](https://www.obdev.at/products/vusb/index.html)
* [Livolo Arduino library](https://forum.arduino.cc/t/control-livolo-switches-livolo-switch-library/149850)
* [hidapi](https://github.com/libusb/hidapi)
* [hidapitester](https://github.com/todbot/hidapitester)
* [argp-standalone](https://github.com/tom42/argp-standalone)
1 change: 1 addition & 0 deletions extra/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This dir contains related software projects. Currently unused, just for the reference.
2 changes: 0 additions & 2 deletions firmware/lib/DLUSB/DLUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,3 @@ extern "C" {
#endif

DLUSBDevice DLUSB = DLUSBDevice(&rx_buffer, &tx_buffer);


2 changes: 1 addition & 1 deletion firmware/lib/DLUSB/DLUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define CMD_RDY 0x10 // OUT, device ready command
#define CMD_FAIL_BIT (uint8_t)(1 << 7) // Not used

typedef struct {
typedef struct dlusb_packet {
uint8_t report_id;
uint8_t cmd_id;
uint16_t remote_id;
Expand Down
10 changes: 5 additions & 5 deletions firmware/lib/DLUSB/usbconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ section at the end of this file).
* with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand
* the implications!
*/
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
#define USB_CFG_DEVICE_VERSION 0x02, 0x01
/* Version number of the device: Minor number first, then major number.
*/
#define USB_CFG_VENDOR_NAME 'd','i','g','i','s','t','u','m','p','.','c','o','m'
#define USB_CFG_VENDOR_NAME_LEN 13
#define USB_CFG_VENDOR_NAME 'd','i','g','i','l','i','v','o','l','o','@','y','a','n','d','e','x','.','c','o','m'
#define USB_CFG_VENDOR_NAME_LEN 21
/* These two values define the vendor name returned by the USB device. The name
* must be given as a list of characters under single quotes. The characters
* are interpreted as Unicode (UTF-16) entities.
Expand All @@ -215,8 +215,8 @@ section at the end of this file).
*/
#ifndef USB_CFG_DEVICE_NAME

#define USB_CFG_DEVICE_NAME 'D','i','g','i','U','S','B'
#define USB_CFG_DEVICE_NAME_LEN 7
#define USB_CFG_DEVICE_NAME 'D','i','g','i','L','i','v','o','l','o'
#define USB_CFG_DEVICE_NAME_LEN 10

#endif
/* Same as above for the device name. If you don't want a device name, undefine
Expand Down
7 changes: 7 additions & 0 deletions software/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build
build.old

.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
5 changes: 5 additions & 0 deletions software/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode.cmake-tools"
]
}
6 changes: 6 additions & 0 deletions software/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cmake.generator": "Ninja",
"cmake.configureArgs": [
"-Wno-dev"
]
}
50 changes: 50 additions & 0 deletions software/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(PROJECT_NAME "digilivolo")
project(${PROJECT_NAME} C)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=gnu11 -flto -ffunction-sections -fdata-sections -Wall -Wl,--warn-common -Wl,--gc-sections -Wl,-lm")
set(HIDAPI_WITH_LIBUSB FALSE)
set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms

if(POLICY CMP0074)
# allow using hidapi_ROOT if CMake supports it
cmake_policy(SET CMP0074 NEW)
endif()

if(POLICY CMP0115)
cmake_policy(SET CMP0115 NEW)
endif()

# Get version from git
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(STATUS "Project: ${PROJECT_NAME} ${GIT_VERSION}")

if(NOT USE_SYSTEM_HIDAPI)
add_subdirectory(lib/hidapi)
message(STATUS "hidapi will be built from sources")
else()
message(STATUS "Finding library hidapi")
find_package(hidapi 0.12 REQUIRED)
endif()

message(STATUS "Using HIDAPI: ${hidapi_VERSION}")

add_subdirectory(lib/argp-standalone)

configure_file(src/git_version.h.in src/git_version.h @ONLY)
add_executable(${PROJECT_NAME} src/digilivolo.c)
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/src")
target_link_libraries(${PROJECT_NAME} hidapi::hidapi argp-standalone)

# Strip binary for release builds
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${PROJECT_NAME}>
VERBATIM
)
24 changes: 24 additions & 0 deletions software/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Builds project with cmake.
# If called with any argument, does a full rebuild by moving a build dir to
# build.old (deleting build.old if exits).

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

echo "Working dir: ${SCRIPT_DIR}"

if [[ ! -z "$1" ]]; then
rm -rf ${SCRIPT_DIR}/build.old
mv ${SCRIPT_DIR}/build ${SCRIPT_DIR}/build.old
fi

mkdir ${SCRIPT_DIR}/build 2>/dev/null
pushd .
cd ${SCRIPT_DIR}/build

# cmake -DUSE_SYSTEM_HIDAPI=false -G 'Unix Makefiles' ..
cmake -DUSE_SYSTEM_HIDAPI=false -G 'Ninja' -Wno-dev ..
cmake --build .

popd
1 change: 1 addition & 0 deletions software/lib/argp-standalone
Submodule argp-standalone added at 1684ac
Loading

0 comments on commit 78a3096

Please sign in to comment.