Merge pull request 'Fixing formatin and .clang-format' (#1) from test into dev
Reviewed-on: http://git.n0x.io/_N0x/f8prog/pulls/1
This commit is contained in:
commit
6e76a65844
@ -106,7 +106,6 @@ IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: None
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
LambdaBodyIndentation: Signature
|
||||
LanguageKind: Cpp
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include "../include/config_handling.h"
|
||||
|
||||
#include "../include/keycodes_conv.h"
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "../include/config_handling.h"
|
||||
#include "../include/keycodes_conv.h"
|
||||
|
||||
/* define declarations */
|
||||
#define JO_MACROS "macros"
|
||||
#define JO_MACRO_NO "macro_no"
|
||||
@ -17,13 +18,14 @@
|
||||
/* method declarations */
|
||||
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 *macro = NULL;
|
||||
const cJSON *macro = NULL;
|
||||
|
||||
/* 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) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL) {
|
||||
@ -35,20 +37,23 @@ prog_actionP *get_config(char *conf_name) {
|
||||
// READ IN VALUES //
|
||||
macros = cJSON_GetObjectItemCaseSensitive(config_json, JO_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;
|
||||
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
cJSON *actions = cJSON_GetObjectItemCaseSensitive(macro, JO_ACTIONS);
|
||||
cJSON_ArrayForEach(action, actions) {
|
||||
cJSON *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);
|
||||
|
||||
prog_actionP pa = calloc(1, sizeof(*pa));
|
||||
pa->k_modifier = get_modkeycode_by_name(cJSON_GetStringValue(mod_keys));
|
||||
pa->k_delay = 0x00;
|
||||
pa->k_modifier =
|
||||
get_modkeycode_by_name(cJSON_GetStringValue(mod_keys));
|
||||
pa->k_delay = 0x00;
|
||||
pa->k_action1 = get_keycode_by_name(
|
||||
cJSON_GetStringValue(cJSON_GetArrayItem(keys, 0)));
|
||||
pa->k_action2 = get_keycode_by_name(
|
||||
@ -69,7 +74,8 @@ prog_actionP *get_config(char *conf_name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *read_in_config(char *conf_name) {
|
||||
char *
|
||||
read_in_config(char *conf_name) {
|
||||
|
||||
FILE *fp = fopen(conf_name, "r");
|
||||
if (!fp) {
|
||||
|
@ -4,15 +4,16 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
/* Just for debugging */
|
||||
#include <ctype.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));
|
||||
|
||||
FILE *firmware = fopen(filename, "rb");
|
||||
FILE *firmware = fopen(filename, "rb");
|
||||
if (!firmware) {
|
||||
perror("Error while reading in Firmware File.\r\nExiting.");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -25,7 +26,7 @@ f_bffrP get_firmware_buffer(char *filename) {
|
||||
}
|
||||
|
||||
/* 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);
|
||||
fread(p_fb->buffer, p_fb->size, 1, firmware);
|
||||
|
||||
@ -37,7 +38,8 @@ f_bffrP get_firmware_buffer(char *filename) {
|
||||
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+");
|
||||
if (!firmware_file) {
|
||||
@ -50,11 +52,13 @@ void write_firmware_buffer(char *filename, f_bffrP p_fb) {
|
||||
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);
|
||||
}
|
||||
|
||||
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++) {
|
||||
|
||||
// Check if an action for that position exists
|
||||
|
@ -223,25 +223,18 @@ const keyCode keycodes[] = {
|
||||
};
|
||||
|
||||
const keyCode modkeycodes[] = {
|
||||
KEYCODE(MODKEY_LCTR),
|
||||
KEYCODE(MODKEY_LSHI),
|
||||
KEYCODE(MODKEY_LALT),
|
||||
KEYCODE(MODKEY_LWIN),
|
||||
KEYCODE(MODKEY_RCTR),
|
||||
KEYCODE(MODKEY_RSHI),
|
||||
KEYCODE(MODKEY_RALT),
|
||||
KEYCODE(MODKEY_RWIN),
|
||||
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),
|
||||
KEYCODE(MODKEY_LCTR), KEYCODE(MODKEY_LSHI),
|
||||
KEYCODE(MODKEY_LALT), KEYCODE(MODKEY_LWIN),
|
||||
KEYCODE(MODKEY_RCTR), KEYCODE(MODKEY_RSHI),
|
||||
KEYCODE(MODKEY_RALT), KEYCODE(MODKEY_RWIN),
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint8_t get_modkeycode_by_name(char *modkey_name) {
|
||||
uint8_t
|
||||
get_modkeycode_by_name(char *modkey_name) {
|
||||
uint8_t keycode = -1;
|
||||
|
||||
for (int i = 0; i < (sizeof(modkeycodes) / sizeof(modkeycodes[0])); i++) {
|
||||
|
49
src/main.c
49
src/main.c
@ -1,14 +1,15 @@
|
||||
#include "../include/firmware_handling.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
/* Read in the firmware file into a f_bffr_t struct */
|
||||
f_bffrP p_fb = get_firmware_buffer(argv[1]);
|
||||
|
||||
@ -23,9 +24,10 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *updated_file_name(char *orig) {
|
||||
char *ne = "_new.bin";
|
||||
int len = strlen(orig);
|
||||
char *
|
||||
updated_file_name(char *orig) {
|
||||
char *ne = "_new.bin";
|
||||
int len = strlen(orig);
|
||||
|
||||
char *new_name = malloc(len + 4);
|
||||
|
||||
@ -37,8 +39,8 @@ char *updated_file_name(char *orig) {
|
||||
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);
|
||||
@ -51,7 +53,6 @@ void testing(f_bffrP p_fb) {
|
||||
set_key_value(p_fb->buffer, F8_KEY8, KEY_2_At);
|
||||
*/
|
||||
|
||||
|
||||
/* for debugging -> print content of buffer to terminal */
|
||||
/*
|
||||
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));
|
||||
pa->k_modifier = 0x00;
|
||||
pa->k_delay = 0x00;
|
||||
pa->k_action1 = 0x0B;
|
||||
pa->k_action2 = 0x04;
|
||||
pa->k_action3 = 0x0F;
|
||||
pa->k_action4 = 0x0F;
|
||||
pa->k_action5 = 0x12;
|
||||
pa->k_action6 = 0x00;
|
||||
pa->k_modifier = 0x00;
|
||||
pa->k_delay = 0x00;
|
||||
pa->k_action1 = 0x0B;
|
||||
pa->k_action2 = 0x04;
|
||||
pa->k_action3 = 0x0F;
|
||||
pa->k_action4 = 0x0F;
|
||||
pa->k_action5 = 0x12;
|
||||
pa->k_action6 = 0x00;
|
||||
|
||||
key_progP kp = calloc(1, sizeof(*kp));
|
||||
kp->prog_offset = PROG1_OFFSET;
|
||||
kp->prog_actions[0] = pa;
|
||||
kp->prog_actions[1] = pa;
|
||||
kp->prog_actions[2] = pa;
|
||||
kp->prog_actions[3] = pa;
|
||||
key_progP kp = calloc(1, sizeof(*kp));
|
||||
kp->prog_offset = PROG1_OFFSET;
|
||||
kp->prog_actions[0] = pa;
|
||||
kp->prog_actions[1] = pa;
|
||||
kp->prog_actions[2] = pa;
|
||||
kp->prog_actions[3] = pa;
|
||||
kp->prog_actions[99] = pa;
|
||||
//*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user