Digitizer feature improvements (#19034)
This commit is contained in:
parent
8cecf7fad8
commit
6cc9513ab0
10 changed files with 298 additions and 118 deletions
|
@ -13,26 +13,64 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "digitizer.h"
|
||||
|
||||
digitizer_t digitizerReport = {.tipswitch = 0, .inrange = 0, .id = 0, .x = 0, .y = 0, .status = DZ_INITIALIZED};
|
||||
digitizer_t digitizer_state = {
|
||||
.in_range = false,
|
||||
.tip = false,
|
||||
.barrel = false,
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.dirty = false,
|
||||
};
|
||||
|
||||
__attribute__((weak)) void digitizer_send(void) {
|
||||
if (digitizerReport.status & DZ_UPDATED) {
|
||||
host_digitizer_send(&digitizerReport);
|
||||
digitizerReport.status &= ~DZ_UPDATED;
|
||||
void digitizer_flush(void) {
|
||||
if (digitizer_state.dirty) {
|
||||
host_digitizer_send(&digitizer_state);
|
||||
digitizer_state.dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((weak)) void digitizer_task(void) {
|
||||
digitizer_send();
|
||||
void digitizer_in_range_on(void) {
|
||||
digitizer_state.in_range = true;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
||||
digitizer_t digitizer_get_report(void) {
|
||||
return digitizerReport;
|
||||
void digitizer_in_range_off(void) {
|
||||
digitizer_state.in_range = false;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
||||
void digitizer_set_report(digitizer_t newDigitizerReport) {
|
||||
digitizerReport = newDigitizerReport;
|
||||
digitizerReport.status |= DZ_UPDATED;
|
||||
}
|
||||
void digitizer_tip_switch_on(void) {
|
||||
digitizer_state.tip = true;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
||||
void digitizer_tip_switch_off(void) {
|
||||
digitizer_state.tip = false;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
||||
void digitizer_barrel_switch_on(void) {
|
||||
digitizer_state.barrel = true;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
||||
void digitizer_barrel_switch_off(void) {
|
||||
digitizer_state.barrel = false;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
||||
void digitizer_set_position(float x, float y) {
|
||||
digitizer_state.x = x;
|
||||
digitizer_state.y = y;
|
||||
digitizer_state.dirty = true;
|
||||
digitizer_flush();
|
||||
}
|
||||
|
|
|
@ -17,25 +17,70 @@
|
|||
|
||||
#include "quantum.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum digitizer_status { DZ_INITIALIZED = 1, DZ_UPDATED = 2 };
|
||||
/**
|
||||
* \defgroup digitizer
|
||||
*
|
||||
* HID Digitizer
|
||||
* \{
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int8_t tipswitch;
|
||||
int8_t inrange;
|
||||
uint8_t id;
|
||||
float x;
|
||||
float y;
|
||||
uint8_t status : 2;
|
||||
bool in_range : 1;
|
||||
bool tip : 1;
|
||||
bool barrel : 1;
|
||||
float x;
|
||||
float y;
|
||||
bool dirty;
|
||||
} digitizer_t;
|
||||
|
||||
extern digitizer_t digitizer;
|
||||
extern digitizer_t digitizer_state;
|
||||
|
||||
digitizer_t digitizer_get_report(void);
|
||||
/**
|
||||
* \brief Send the digitizer report to the host if it is marked as dirty.
|
||||
*/
|
||||
void digitizer_flush(void);
|
||||
|
||||
void digitizer_set_report(digitizer_t newDigitizerReport);
|
||||
/**
|
||||
* \brief Assert the "in range" indicator, and flush the report.
|
||||
*/
|
||||
void digitizer_in_range_on(void);
|
||||
|
||||
void digitizer_task(void);
|
||||
/**
|
||||
* \brief Deassert the "in range" indicator, and flush the report.
|
||||
*/
|
||||
void digitizer_in_range_off(void);
|
||||
|
||||
/**
|
||||
* \brief Assert the tip switch, and flush the report.
|
||||
*/
|
||||
void digitizer_tip_switch_on(void);
|
||||
|
||||
/**
|
||||
* \brief Deassert the tip switch, and flush the report.
|
||||
*/
|
||||
void digitizer_tip_switch_off(void);
|
||||
|
||||
/**
|
||||
* \brief Assert the barrel switch, and flush the report.
|
||||
*/
|
||||
void digitizer_barrel_switch_on(void);
|
||||
|
||||
/**
|
||||
* \brief Deassert the barrel switch, and flush the report.
|
||||
*/
|
||||
void digitizer_barrel_switch_off(void);
|
||||
|
||||
/**
|
||||
* \brief Set the absolute X and Y position of the digitizer contact, and flush the report.
|
||||
*
|
||||
* \param x The X value of the contact position, from 0 to 1.
|
||||
* \param y The Y value of the contact position, from 0 to 1.
|
||||
*/
|
||||
void digitizer_set_position(float x, float y);
|
||||
|
||||
void host_digitizer_send(digitizer_t *digitizer);
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -90,9 +90,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#if defined(CRC_ENABLE)
|
||||
# include "crc.h"
|
||||
#endif
|
||||
#ifdef DIGITIZER_ENABLE
|
||||
# include "digitizer.h"
|
||||
#endif
|
||||
#ifdef VIRTSER_ENABLE
|
||||
# include "virtser.h"
|
||||
#endif
|
||||
|
@ -662,10 +659,6 @@ void keyboard_task(void) {
|
|||
joystick_task();
|
||||
#endif
|
||||
|
||||
#ifdef DIGITIZER_ENABLE
|
||||
digitizer_task();
|
||||
#endif
|
||||
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
bluetooth_task();
|
||||
#endif
|
||||
|
|
|
@ -207,6 +207,10 @@ extern layer_state_t layer_state;
|
|||
# include "joystick.h"
|
||||
#endif
|
||||
|
||||
#ifdef DIGITIZER_ENABLE
|
||||
# include "digitizer.h"
|
||||
#endif
|
||||
|
||||
#ifdef VIA_ENABLE
|
||||
# include "via.h"
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue