Skip to content

Commit

Permalink
Implemented #195 (#196)
Browse files Browse the repository at this point in the history
* Implemented #195
  • Loading branch information
akopachov committed Aug 28, 2023
1 parent 3d1c00e commit 62cff06
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "commands/reset/reset.h"
#include "commands/automation/automation.h"
#include "commands/details/details.h"
#include "commands/version/version.h"

struct TotpCliContext {
PluginState* plugin_state;
Expand Down Expand Up @@ -74,6 +75,8 @@ static void totp_cli_handler(Cli* cli, FuriString* args, void* context) {
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DETAILS) == 0 ||
furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_DETAILS_ALT) == 0) {
totp_cli_command_details_handle(plugin_state, args, cli);
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_VERSION) == 0) {
totp_cli_command_version_handle();
} else {
totp_cli_print_unknown_command(cmd);
}
Expand Down
7 changes: 7 additions & 0 deletions cli/commands/automation/automation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif
#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY "QWERTY"
#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY "AZERTY"
#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ "QWERTZ"
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX "-k"
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT "layout"

Expand Down Expand Up @@ -44,6 +45,7 @@ void totp_cli_command_automation_docopt_options() {
DOCOPT_ARGUMENT(
TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT)) " Automation keyboard layout. Must be one of: " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY
", " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY
", " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ
"\r\n");
}
#endif
Expand Down Expand Up @@ -83,6 +85,9 @@ static void print_kb_layout(AutomationKeyboardLayout layout, const char* color)
case AutomationKeyboardLayoutAZERTY:
layoutToPrint = TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY;
break;
case AutomationKeyboardLayoutQWERTZ:
layoutToPrint = TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ;
break;
default:
furi_crash("Unknown automation keyboard layout");
break;
Expand All @@ -98,6 +103,8 @@ static bool
*out = AutomationKeyboardLayoutQWERTY;
} else if(furi_string_cmpi_str(str, TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY) == 0) {
*out = AutomationKeyboardLayoutAZERTY;
} else if(furi_string_cmpi_str(str, TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTZ) == 0) {
*out = AutomationKeyboardLayoutQWERTZ;
} else {
result = false;
}
Expand Down
3 changes: 3 additions & 0 deletions cli/commands/help/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../reset/reset.h"
#include "../automation/automation.h"
#include "../details/details.h"
#include "../version/version.h"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_help_docopt_commands() {
Expand All @@ -29,6 +30,7 @@ void totp_cli_command_help_handle() {
#ifdef TOTP_CLI_RICH_HELP_ENABLED
TOTP_CLI_PRINTF("Usage:\r\n");
totp_cli_command_help_docopt_usage();
totp_cli_command_version_docopt_usage();
totp_cli_command_list_docopt_usage();
totp_cli_command_details_docopt_usage();
totp_cli_command_add_docopt_usage();
Expand All @@ -43,6 +45,7 @@ void totp_cli_command_help_handle() {
cli_nl();
TOTP_CLI_PRINTF("Commands:\r\n");
totp_cli_command_help_docopt_commands();
totp_cli_command_version_docopt_commands();
totp_cli_command_list_docopt_commands();
totp_cli_command_details_docopt_commands();
totp_cli_command_add_docopt_commands();
Expand Down
20 changes: 20 additions & 0 deletions cli/commands/version/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "version.h"
#include "../../cli_helpers.h"
#include "../../../version.h"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_version_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_VERSION " Get application version\r\n");
}
void totp_cli_command_version_docopt_usage() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_VERSION "\r\n");
}
#endif

void totp_cli_command_version_handle() {
TOTP_CLI_PRINTF(
"%" PRIu8 ".%" PRIu8 ".%" PRIu8 "\r\n",
TOTP_APP_VERSION_MAJOR,
TOTP_APP_VERSION_MINOR,
TOTP_APP_VERSION_PATCH);
}
11 changes: 11 additions & 0 deletions cli/commands/version/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_VERSION "version"

void totp_cli_command_version_handle();
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_version_docopt_commands();
void totp_cli_command_version_docopt_usage();
#endif
3 changes: 2 additions & 1 deletion types/automation_kb_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ typedef uint8_t AutomationKeyboardLayout;

enum AutomationKeyboardLayouts {
AutomationKeyboardLayoutQWERTY = 0,
AutomationKeyboardLayoutAZERTY = 1
AutomationKeyboardLayoutAZERTY = 1,
AutomationKeyboardLayoutQWERTZ = 2
};
4 changes: 2 additions & 2 deletions ui/scenes/app_settings/totp_app_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#else
#define AUTOMATION_LIST_MAX_INDEX (1)
#endif
#define BAD_KB_LAYOUT_LIST_MAX_INDEX (1)
#define BAD_KB_LAYOUT_LIST_MAX_INDEX (2)
#define FONT_TEST_STR_LENGTH (7)

static const char* YES_NO_LIST[] = {"NO", "YES"};
Expand All @@ -33,7 +33,7 @@ static const char* AUTOMATION_LIST[] = {
"BT and USB"
#endif
};
static const char* BAD_KB_LAYOUT_LIST[] = {"QWERTY", "AZERTY"};
static const char* BAD_KB_LAYOUT_LIST[] = {"QWERTY", "AZERTY", "QWERTZ"};
static const char* FONT_TEST_STR = "0123BCD";

typedef enum {
Expand Down
13 changes: 13 additions & 0 deletions workers/type_code_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ static const uint8_t hid_azerty_keys_map[HID_KEYS_MAP_LENGTH] = {
HID_KEYBOARD_U, HID_KEYBOARD_V, HID_KEYBOARD_Z, HID_KEYBOARD_X, HID_KEYBOARD_Y,
HID_KEYBOARD_W};

static const uint8_t hid_qwertz_keys_map[HID_KEYS_MAP_LENGTH] = {
HID_KEYBOARD_0, HID_KEYBOARD_1, HID_KEYBOARD_2, HID_KEYBOARD_3, HID_KEYBOARD_4,
HID_KEYBOARD_5, HID_KEYBOARD_6, HID_KEYBOARD_7, HID_KEYBOARD_8, HID_KEYBOARD_9,
HID_KEYBOARD_A, HID_KEYBOARD_B, HID_KEYBOARD_C, HID_KEYBOARD_D, HID_KEYBOARD_E,
HID_KEYBOARD_F, HID_KEYBOARD_G, HID_KEYBOARD_H, HID_KEYBOARD_I, HID_KEYBOARD_J,
HID_KEYBOARD_K, HID_KEYBOARD_L, HID_KEYBOARD_M, HID_KEYBOARD_N, HID_KEYBOARD_O,
HID_KEYBOARD_P, HID_KEYBOARD_Q, HID_KEYBOARD_R, HID_KEYBOARD_S, HID_KEYBOARD_T,
HID_KEYBOARD_U, HID_KEYBOARD_V, HID_KEYBOARD_W, HID_KEYBOARD_X, HID_KEYBOARD_Z,
HID_KEYBOARD_Y};

static uint32_t get_keystroke_delay(TokenAutomationFeature features) {
if(features & TokenAutomationFeatureTypeSlower) {
return 100;
Expand Down Expand Up @@ -70,6 +80,9 @@ void totp_type_code_worker_execute_automation(
case AutomationKeyboardLayoutAZERTY:
keyboard_layout_dict = &hid_azerty_keys_map[0];
break;
case AutomationKeyboardLayoutQWERTZ:
keyboard_layout_dict = &hid_qwertz_keys_map[0];
break;

default:
return;
Expand Down

0 comments on commit 62cff06

Please sign in to comment.