Skip to content

Commit

Permalink
Merge pull request #1 from N-Storm/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
N-Storm authored May 1, 2024
2 parents 7bb6d88 + daa5c04 commit 9b41be7
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 118 deletions.
18 changes: 12 additions & 6 deletions software/src/digilivolo.h → common/defs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Part of the DigiLivolo control software.
/* Part of the DigiLivolo project.
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
Expand All @@ -18,10 +18,8 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef __digilivolo_h__
#define __digilivolo_h__

#include <wchar.h>
#ifndef __defs_h__
#define __defs_h__

#define DIGILIVOLO_VID 0x16c0
#define DIGILIVOLO_PID 0x05df
Expand All @@ -32,5 +30,13 @@

#define CMD_SWITCH 0x01 // IN,OUT send Livolo keycode command or send ACK to the host
#define CMD_RDY 0x10 // OUT, device ready command
#define CMD_FAIL_BIT (uint8_t)(1 << 7) // Not used

typedef struct dlusb_packet {
uint8_t report_id;
uint8_t cmd_id;
uint16_t remote_id;
uint8_t btn_id;
} dlusb_packet_t;

#endif // __digilivolo_h__
#endif // __defs_h__
14 changes: 1 addition & 13 deletions firmware/lib/DLUSB/DLUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,14 @@
#include <string.h>
#include <stdint.h>
#include "usbdrv.h"
#include "defs.h"

#include <util/delay.h> /* for _delay_ms() */

/* Buffer size for USB TX & RX buffers. This is not the bytes, it's a count of dlusb_packet_t
* structures it holds. I.e. how many packets it can store before processing. */
#define RING_BUFFER_SIZE 16

#define REPORT_ID 0x4c

#define CMD_SWITCH 0x01 // IN,OUT send Livolo keycode command or send ACK to the host
#define CMD_RDY 0x10 // OUT, device ready command
#define CMD_FAIL_BIT (uint8_t)(1 << 7) // Not used

typedef struct dlusb_packet {
uint8_t report_id;
uint8_t cmd_id;
uint16_t remote_id;
uint8_t btn_id;
} dlusb_packet_t;

struct ring_buffer {
dlusb_packet_t buffer[RING_BUFFER_SIZE];
int head;
Expand Down
1 change: 1 addition & 0 deletions firmware/lib/DLUSB/defs.h
18 changes: 6 additions & 12 deletions software/src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,34 @@
#include <stdbool.h>
#include <stdint.h>

#include "digilivolo.h"
#include "defs.h"

#include <hidapi.h>
#include "usb_func.h"

#include "git_version.h"
#include "args.h"

// [argp] Program documentation.
// const char* argp_program_version = GIT_VERSION;
const char prognamever[] = "digilivolo " GIT_VERSION "\n";
const char* argp_program_version = GIT_VERSION;
const char doc[] = "\nSoftware to control DigiLivolo devices.\n";

const char* argp_program_bug_address = "https://github.com/N-Storm/DigiLivolo/\n\
Copyright (c) 2024 GitHub user N-Storm.\n\
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>";

// [argp] A description of the arguments we accept.
char args_doc[] = "REMOTE_ID KEY_ID";
char args_doc[] = "REMOTE_ID KEY_CODE";

// [argp] The options we understand.
struct argp_option options[] = {
{0, 0, 0, 0, "Positional arguments:" },
{"REMOTE_ID", 0, 0, OPTION_DOC | OPTION_NO_USAGE, "Livilo Remote ID (1-65535)" },
{"KEY_ID", 0, 0, OPTION_DOC | OPTION_NO_USAGE, "Livilo Key ID (1-255)" },
{"KEY_CODE", 0, 0, OPTION_DOC | OPTION_NO_USAGE, "Livilo Key ID (1-255)" },
{0, 0, 0, 0, "Options:" },
{"verbose", 'v', 0, 0, "Produce verbose output" },
{ 0 }
};

// [argp] Command-line arguments.
arguments_t arguments;

// [argp] Parse a single option.
error_t parse_opt(int key, char* arg, struct argp_state* state)
{
/* Get the input argument from argp_parse, which we
Expand Down Expand Up @@ -93,15 +87,15 @@ error_t parse_opt(int key, char* arg, struct argp_state* state)
if (value > 255 || value <= 0)
argp_usage(state);
else
arguments->key_id = (uint8_t)value;
arguments->btn_id = (uint8_t)value;
break;

default:
return ARGP_ERR_UNKNOWN;
}
}
else
// REMOTE_ID or KEY_ID not an unsigned integer
// REMOTE_ID or KEY_CODE not an unsigned integer
argp_usage(state);

break;
Expand Down
41 changes: 22 additions & 19 deletions software/src/args.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* Part of the DigiLivolo control software.
* https://github.com/N-Storm/DigiLivolo/
* https://github.com/N-Storm/DigiLivolo/
* Copyright (c) 2024 GitHub user N-Storm.
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
Expand All @@ -21,36 +21,39 @@
#ifndef __args_h__
#define __args_h__

#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#include "digilivolo.h"

#include "git_version.h"
#include <argp.h>

// [argp] A description of the arguments we accept.
/// @brief String definition with program name & version number
#define PROG_NAME_VERSION "digilivolo " GIT_VERSION "\n"

/// @brief [argp] A description of the command line arguments we accept.
extern char args_doc[];

// [argp] The options we understand.
/// @brief [argp] Command line options we understand.
extern struct argp_option options[];

// [argp] Program documentation.
// const char* argp_program_version = GIT_VERSION;
extern const char prognamever[];
/// @brief [argp] Program documentation.
extern const char doc[];

/// @brief [argp] This string are printed in the footer of the help text.
extern const char* argp_program_bug_address;

// [argp] Command-line arguments.
/// @brief [argp] Command-line arguments.
typedef struct arguments {
uint16_t remote_id;
uint8_t key_id;
uint8_t btn_id;
bool verbose;
} arguments_t;

extern arguments_t arguments;


/// @brief [argp] Parse a single option.
/// @param key[in] option key
/// @param arg[in] pointer to argument value
/// @param state pointer to argp_state
/// @return error_t error code
extern error_t parse_opt(int key, char* arg, struct argp_state* state);

#endif // __args_h__
1 change: 1 addition & 0 deletions software/src/defs.h
Loading

0 comments on commit 9b41be7

Please sign in to comment.