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
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
LanguageKind: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1

View File

@ -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,7 +18,8 @@
/* 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;
@ -35,7 +37,8 @@ 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;
@ -43,11 +46,13 @@ prog_actionP *get_config(char *conf_name) {
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_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)));
@ -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) {

View File

@ -4,11 +4,12 @@
#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));
@ -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

View File

@ -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++) {

View File

@ -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);
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,7 +24,8 @@ int main(int argc, char *argv[]) {
return 0;
}
char *updated_file_name(char *orig) {
char *
updated_file_name(char *orig) {
char *ne = "_new.bin";
int len = strlen(orig);
@ -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++){