Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add QMK LED support #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 88 additions & 34 deletions stuff/flicc/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,31 @@
//CHANGE THIS
char arrow_keys[4] = {KC_UP, KC_LEFT, KC_DOWN, KC_RIGHT}; // up, left, down, right


static uint8_t joystickMode = 0;
static uint8_t joystick_modes = 2; // amount of modes
static int actuation = 256; // actuation point for arrows (0-511)
static int actuation = 256; // actuation point for arrows (0-511)

enum my_keycodes {
JSMODE = SAFE_RANGE,
JSMODE = SAFE_RANGE,
};

bool arrows[4];

// layer leds
#define LED1 D7 // pin 6
#define LED2 C6 // pin 5
#define LED3 D0 // pin 3

// runs on startup
void keyboard_pre_init_user(void) {
// set pins as output
setPinOutput(LED1);
setPinOutput(LED2);
setPinOutput(LED3);
}

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

[0] = LAYOUT(
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, MO(1),
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T,
Expand All @@ -50,12 +62,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, JSMODE, KC_TRNS
),


};




//joystick config
joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {
[0] = JOYSTICK_AXIS_VIRTUAL,
Expand All @@ -64,72 +72,118 @@ joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {

bool process_record_user(uint16_t keycode, keyrecord_t *record) {

//#ifdef CONSOLE_ENABLE
// uprintf("kc:%u x:%u y:%u mode:%u\n", analogReadPin(F5), analogReadPin(F4), keycode, joystickMode, record->event.pressed);
//#endif
switch(keycode) {
//#ifdef CONSOLE_ENABLE
// uprintf("kc:%u x:%u y:%u mode:%u\n", analogReadPin(F5), analogReadPin(F4), keycode, joystickMode, record->event.pressed);
//#endif
switch (keycode)
{
case JSMODE:
if (record->event.pressed) {
joystickMode++;
if (joystickMode == joystick_modes){
joystickMode = 0;
if (joystickMode == joystick_modes) {
joystickMode = 0;
}
}
}
return true;
}

void joystick_task(){
void joystick_task() {

switch (joystickMode) {
case 0: // gamepad
joystick_status.axes[0] = -(analogReadPin(F5)/4 - 127);
joystick_status.axes[1] = analogReadPin(F4)/4 - 128;
joystick_status.status |= JS_UPDATED;
switch (joystickMode) {
case 0: // gamepad
joystick_status.axes[0] = -(analogReadPin(F5) / 4 - 127);
joystick_status.axes[1] = analogReadPin(F4) / 4 - 128;
joystick_status.status |= JS_UPDATED;
send_joystick_packet(&joystick_status);
break;
break;
case 1: // arrows
if (!arrows[0] && analogReadPin(F5) - 512 > actuation){
if (!arrows[0] && analogReadPin(F5) - 512 > actuation) {
arrows[0] = true;
register_code16(arrow_keys[1]);
}
else if (arrows[0] && analogReadPin(F5) - 512 < actuation){
} else if (arrows[0] && analogReadPin(F5) - 512 < actuation) {
arrows[0] = false;
unregister_code16(arrow_keys[1]);
}
if (!arrows[1] && analogReadPin(F5) - 512 < -actuation){
if (!arrows[1] && analogReadPin(F5) - 512 < -actuation) {
arrows[1] = true;
register_code16(arrow_keys[3]);
}
else if (arrows[1] && analogReadPin(F5) - 512 > -actuation){
} else if (arrows[1] && analogReadPin(F5) - 512 > -actuation) {
arrows[1] = false;
unregister_code16(arrow_keys[3]);
}
if (!arrows[2] && analogReadPin(F4) - 512 > actuation){
if (!arrows[2] && analogReadPin(F4) - 512 > actuation) {
arrows[2] = true;
register_code16(arrow_keys[2]);
}
else if (arrows[2] && analogReadPin(F4) - 512 < actuation){
} else if (arrows[2] && analogReadPin(F4) - 512 < actuation) {
arrows[2] = false;
unregister_code16(arrow_keys[2]);
}
if (!arrows[3] && analogReadPin(F4) - 512 < -actuation){
if (!arrows[3] && analogReadPin(F4) - 512 < -actuation) {
arrows[3] = true;
register_code16(arrow_keys[0]);
}
else if (arrows[3] && analogReadPin(F4) - 512 > -actuation){
} else if (arrows[3] && analogReadPin(F4) - 512 > -actuation) {
arrows[3] = false;
unregister_code16(arrow_keys[0]);
}
break;

/*case 2: // mouse
/*case 2: // mouse

report_mouse_t currentReport = pointint_device_get_report()
currentReport.x = (analogReadPin(F5)-512)/4;
currentReport.y = -(analogReadPin(F4)-512)/4;
pointint_device_set_report(currentReport);
poining_device_send();
break;*/
}
}
}

// Automatically sets leds based on the layer
uint32_t layer_state_set_user(uint32_t state) {

// first turn all leds off
writePin(LED1, 0);
writePin(LED2, 0);
writePin(LED3, 0);

switch (biton32(state)) {
case 0:
// no lights
break;

case 1:
writePin(LED1, 50);
break;

case 2:
writePin(LED2, 50);
break;

case 3:
writePin(LED3, 50);
break;

case 4:
writePin(LED1, 50);
writePin(LED2, 50);
break;

case 5:
writePin(LED1, 50);
writePin(LED3, 50);
break;

case 6:
writePin(LED2, 50);
writePin(LED3, 50);
break;

case 7:
writePin(LED1, 50);
writePin(LED2, 50);
writePin(LED3, 50);
break;
}
return state;
}
Loading