/* Copyright 2017 Zach White * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "2019.h" #include "encoder.h" void matrix_init_kb(void) { // Set our LED pins as output setPinOutput(B4); setPinOutput(B5); setPinOutput(B6); // Set our Tilt Sensor pins as input setPinInputHigh(SHAKE_PIN_A); setPinInputHigh(SHAKE_PIN_B); // Run the keymap level init matrix_init_user(); } #ifdef SHAKE_ENABLE uint8_t tilt_state = 0x11; uint8_t detected_shakes = 0; static uint16_t shake_timer; #endif void matrix_scan_kb(void) { #ifdef SHAKE_ENABLE // Read the current state of the tilt sensor. It is physically // impossible for both pins to register a low state at the same time. uint8_t tilt_read = (readPin(SHAKE_PIN_A) << 4) | readPin(SHAKE_PIN_B); // Check to see if the tilt sensor has changed state since our last read for (uint8_t i = 0; i < 2; i++) { if (tilt_state != tilt_read) { shake_timer = timer_read(); detected_shakes++; tilt_state = tilt_read; } } if ((detected_shakes > 0) && (timer_elapsed(shake_timer) > SHAKE_TIMEOUT)) { if (detected_shakes > SHAKE_COUNT) { dprintf("Shake triggered! We detected %d shakes.\n", detected_shakes); tap_code16(SHAKE_KEY); } else { dprintf("Shake not triggered! We detected %d shakes.\n", detected_shakes); } detected_shakes = 0; } #endif matrix_scan_user(); } bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } void led_set_kb(uint8_t usb_led) { // Toggle numlock as needed if (usb_led & (1<