dev #4

Closed
_N0x wants to merge 4 commits from dev into master
5 changed files with 67 additions and 63 deletions
Showing only changes of commit 24429cde26 - Show all commits

View File

@ -106,7 +106,6 @@ IndentWrappedFunctionNames: false
InsertTrailingCommas: None InsertTrailingCommas: None
KeepEmptyLinesAtTheStartOfBlocks: true KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature LambdaBodyIndentation: Signature
LanguageKind: Cpp
MacroBlockBegin: '' MacroBlockBegin: ''
MacroBlockEnd: '' MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1 MaxEmptyLinesToKeep: 1

View File

@ -1,11 +1,12 @@
#include "../include/config_handling.h"
#include "../include/keycodes_conv.h"
#include <cjson/cJSON.h> #include <cjson/cJSON.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "../include/config_handling.h"
#include "../include/keycodes_conv.h"
/* define declarations */ /* define declarations */
#define JO_MACROS "macros" #define JO_MACROS "macros"
#define JO_MACRO_NO "macro_no" #define JO_MACRO_NO "macro_no"
@ -17,13 +18,14 @@
/* method declarations */ /* method declarations */
char *read_in_config(char *conf_name); char *read_in_config(char *conf_name);
prog_actionP *get_config(char *conf_name) { prog_actionP *
get_config(char *conf_name) {
const cJSON *macros = NULL; const cJSON *macros = NULL;
const cJSON *macro = NULL; const cJSON *macro = NULL;
/* parse the read in config file */ /* parse the read in config file */
cJSON *config_json = cJSON_Parse(read_in_config(conf_name)); cJSON *config_json = cJSON_Parse(read_in_config(conf_name));
if (config_json == NULL) { if (config_json == NULL) {
const char *error_ptr = cJSON_GetErrorPtr(); const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL) { if (error_ptr != NULL) {
@ -35,20 +37,23 @@ prog_actionP *get_config(char *conf_name) {
// READ IN VALUES // // READ IN VALUES //
macros = cJSON_GetObjectItemCaseSensitive(config_json, JO_MACROS); macros = cJSON_GetObjectItemCaseSensitive(config_json, JO_MACROS);
cJSON_ArrayForEach(macro, macros) { cJSON_ArrayForEach(macro, macros) {
//cJSON *macro_no = cJSON_GetObjectItemCaseSensitive(macro, JO_MACRO_NO); // cJSON *macro_no = cJSON_GetObjectItemCaseSensitive(macro,
// JO_MACRO_NO);
cJSON *action = NULL; cJSON *action = NULL;
int i = 0; int i = 0;
cJSON *actions = cJSON_GetObjectItemCaseSensitive(macro, JO_ACTIONS); cJSON *actions = cJSON_GetObjectItemCaseSensitive(macro, JO_ACTIONS);
cJSON_ArrayForEach(action, actions) { cJSON_ArrayForEach(action, actions) {
cJSON *mod_keys = cJSON *mod_keys =
cJSON_GetObjectItemCaseSensitive(action, JO_MOD_KEYS); cJSON_GetObjectItemCaseSensitive(action, JO_MOD_KEYS);
//cJSON *delay = cJSON_GetObjectItemCaseSensitive(action, JO_DELAY); // cJSON *delay = cJSON_GetObjectItemCaseSensitive(action,
// JO_DELAY);
cJSON *keys = cJSON_GetObjectItemCaseSensitive(action, JO_KEYS); cJSON *keys = cJSON_GetObjectItemCaseSensitive(action, JO_KEYS);
prog_actionP pa = calloc(1, sizeof(*pa)); prog_actionP pa = calloc(1, sizeof(*pa));
pa->k_modifier = get_modkeycode_by_name(cJSON_GetStringValue(mod_keys)); pa->k_modifier =
pa->k_delay = 0x00; get_modkeycode_by_name(cJSON_GetStringValue(mod_keys));
pa->k_delay = 0x00;
pa->k_action1 = get_keycode_by_name( pa->k_action1 = get_keycode_by_name(
cJSON_GetStringValue(cJSON_GetArrayItem(keys, 0))); cJSON_GetStringValue(cJSON_GetArrayItem(keys, 0)));
pa->k_action2 = get_keycode_by_name( pa->k_action2 = get_keycode_by_name(
@ -69,7 +74,8 @@ prog_actionP *get_config(char *conf_name) {
return NULL; return NULL;
} }
char *read_in_config(char *conf_name) { char *
read_in_config(char *conf_name) {
FILE *fp = fopen(conf_name, "r"); FILE *fp = fopen(conf_name, "r");
if (!fp) { if (!fp) {

View File

@ -4,15 +4,16 @@
#include <sys/stat.h> #include <sys/stat.h>
/* Just for debugging */ /* Just for debugging */
#include <ctype.h>
#include "../include/firmware_handling.h" #include "../include/firmware_handling.h"
f_bffrP get_firmware_buffer(char *filename) { #include <ctype.h>
f_bffrP
get_firmware_buffer(char *filename) {
f_bffrP p_fb = malloc(sizeof(*p_fb)); f_bffrP p_fb = malloc(sizeof(*p_fb));
FILE *firmware = fopen(filename, "rb"); FILE *firmware = fopen(filename, "rb");
if (!firmware) { if (!firmware) {
perror("Error while reading in Firmware File.\r\nExiting."); perror("Error while reading in Firmware File.\r\nExiting.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -25,7 +26,7 @@ f_bffrP get_firmware_buffer(char *filename) {
} }
/* set buffer size and read in firmware file into buffer*/ /* set buffer size and read in firmware file into buffer*/
p_fb->size = sb.st_size; p_fb->size = sb.st_size;
p_fb->buffer = malloc(p_fb->size); p_fb->buffer = malloc(p_fb->size);
fread(p_fb->buffer, p_fb->size, 1, firmware); fread(p_fb->buffer, p_fb->size, 1, firmware);
@ -37,7 +38,8 @@ f_bffrP get_firmware_buffer(char *filename) {
return p_fb; return p_fb;
} }
void write_firmware_buffer(char *filename, f_bffrP p_fb) { void
write_firmware_buffer(char *filename, f_bffrP p_fb) {
FILE *firmware_file = fopen(filename, "wb+"); FILE *firmware_file = fopen(filename, "wb+");
if (!firmware_file) { if (!firmware_file) {
@ -50,11 +52,13 @@ void write_firmware_buffer(char *filename, f_bffrP p_fb) {
fclose(firmware_file); fclose(firmware_file);
} }
void set_key_value(char *firmware_buffer, int key, int value) { void
set_key_value(char *firmware_buffer, int key, int value) {
memset(firmware_buffer + key, value, 1); memset(firmware_buffer + key, value, 1);
} }
void set_program(f_bffrP p_fb, key_progP kp) { void
set_program(f_bffrP p_fb, key_progP kp) {
for (int i = 0; i < MAX_ACTION; i++) { for (int i = 0; i < MAX_ACTION; i++) {
// Check if an action for that position exists // Check if an action for that position exists

View File

@ -223,25 +223,18 @@ const keyCode keycodes[] = {
}; };
const keyCode modkeycodes[] = { const keyCode modkeycodes[] = {
KEYCODE(MODKEY_LCTR), KEYCODE(MODKEY_LCTR), KEYCODE(MODKEY_LSHI),
KEYCODE(MODKEY_LSHI), KEYCODE(MODKEY_LALT), KEYCODE(MODKEY_LWIN),
KEYCODE(MODKEY_LALT), KEYCODE(MODKEY_RCTR), KEYCODE(MODKEY_RSHI),
KEYCODE(MODKEY_LWIN), KEYCODE(MODKEY_RALT), KEYCODE(MODKEY_RWIN),
KEYCODE(MODKEY_RCTR), KEYCODE(MODKEY_RWIN_RSHI), KEYCODE(MODKEY_RWIN_RCTR),
KEYCODE(MODKEY_RSHI), KEYCODE(MODKEY_RWIN_RALT), KEYCODE(MODKEY_RWIN_RCTR_RSHI),
KEYCODE(MODKEY_RALT), KEYCODE(MODKEY_RCTR_RALT), KEYCODE(MODKEY_RCTR_RSHI),
KEYCODE(MODKEY_RWIN), KEYCODE(MODKEY_RALT_RSHI), KEYCODE(MODKEY_RALT_RCTR_RSHI),
KEYCODE(MODKEY_RWIN_RSHI),
KEYCODE(MODKEY_RWIN_RCTR),
KEYCODE(MODKEY_RWIN_RALT),
KEYCODE(MODKEY_RWIN_RCTR_RSHI),
KEYCODE(MODKEY_RCTR_RALT),
KEYCODE(MODKEY_RCTR_RSHI),
KEYCODE(MODKEY_RALT_RSHI),
KEYCODE(MODKEY_RALT_RCTR_RSHI),
}; };
uint8_t get_keycode_by_name(char *key_name) { uint8_t
get_keycode_by_name(char *key_name) {
uint8_t keycode = -1; uint8_t keycode = -1;
for (int i = 0; i < (sizeof(keycodes) / sizeof(keycodes[0])); i++) { for (int i = 0; i < (sizeof(keycodes) / sizeof(keycodes[0])); i++) {
@ -254,7 +247,8 @@ uint8_t get_keycode_by_name(char *key_name) {
return keycode; return keycode;
} }
uint8_t get_modkeycode_by_name(char *modkey_name) { uint8_t
get_modkeycode_by_name(char *modkey_name) {
uint8_t keycode = -1; uint8_t keycode = -1;
for (int i = 0; i < (sizeof(modkeycodes) / sizeof(modkeycodes[0])); i++) { for (int i = 0; i < (sizeof(modkeycodes) / sizeof(modkeycodes[0])); i++) {

View File

@ -1,14 +1,15 @@
#include "../include/firmware_handling.h"
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "../include/firmware_handling.h" void testing(f_bffrP p_fb);
void testing(f_bffrP p_fb);
char *updated_file_name(char *orig); char *updated_file_name(char *orig);
int main(int argc, char *argv[]) { int
main(int argc, char *argv[]) {
/* Read in the firmware file into a f_bffr_t struct */ /* Read in the firmware file into a f_bffr_t struct */
f_bffrP p_fb = get_firmware_buffer(argv[1]); f_bffrP p_fb = get_firmware_buffer(argv[1]);
@ -23,9 +24,10 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
char *updated_file_name(char *orig) { char *
char *ne = "_new.bin"; updated_file_name(char *orig) {
int len = strlen(orig); char *ne = "_new.bin";
int len = strlen(orig);
char *new_name = malloc(len + 4); char *new_name = malloc(len + 4);
@ -37,8 +39,8 @@ char *updated_file_name(char *orig) {
return new_name; return new_name;
} }
void testing(f_bffrP p_fb) { void
testing(f_bffrP p_fb) {
/* /*
set_key_value(p_fb->buffer, F8_KEY1, KEY_9_LeftParenthesis); set_key_value(p_fb->buffer, F8_KEY1, KEY_9_LeftParenthesis);
@ -51,7 +53,6 @@ void testing(f_bffrP p_fb) {
set_key_value(p_fb->buffer, F8_KEY8, KEY_2_At); set_key_value(p_fb->buffer, F8_KEY8, KEY_2_At);
*/ */
/* for debugging -> print content of buffer to terminal */ /* for debugging -> print content of buffer to terminal */
/* /*
for(int i = 0; i<p_fb->size; i++){ for(int i = 0; i<p_fb->size; i++){
@ -60,21 +61,21 @@ void testing(f_bffrP p_fb) {
*/ */
prog_actionP pa = calloc(1, sizeof(*pa)); prog_actionP pa = calloc(1, sizeof(*pa));
pa->k_modifier = 0x00; pa->k_modifier = 0x00;
pa->k_delay = 0x00; pa->k_delay = 0x00;
pa->k_action1 = 0x0B; pa->k_action1 = 0x0B;
pa->k_action2 = 0x04; pa->k_action2 = 0x04;
pa->k_action3 = 0x0F; pa->k_action3 = 0x0F;
pa->k_action4 = 0x0F; pa->k_action4 = 0x0F;
pa->k_action5 = 0x12; pa->k_action5 = 0x12;
pa->k_action6 = 0x00; pa->k_action6 = 0x00;
key_progP kp = calloc(1, sizeof(*kp)); key_progP kp = calloc(1, sizeof(*kp));
kp->prog_offset = PROG1_OFFSET; kp->prog_offset = PROG1_OFFSET;
kp->prog_actions[0] = pa; kp->prog_actions[0] = pa;
kp->prog_actions[1] = pa; kp->prog_actions[1] = pa;
kp->prog_actions[2] = pa; kp->prog_actions[2] = pa;
kp->prog_actions[3] = pa; kp->prog_actions[3] = pa;
kp->prog_actions[99] = pa; kp->prog_actions[99] = pa;
//*/ //*/