Many changes: added commandhandler module, macro functions, toggle function and
speed settings. Removed key repetition (no idea why it was there).
This commit is contained in:
@ -235,6 +235,7 @@
|
||||
#include "keycodes.h"
|
||||
#include "tools.h"
|
||||
#include "modelinterface.h"
|
||||
#include "commandhandler.h"
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ----------------------------- USB interface ----------------------------- */
|
||||
@ -341,6 +342,17 @@ uint8_t usbFunctionWrite(uchar *data, uchar len) {
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a report buffer to the computer.
|
||||
* \param reportbuffer report buffer
|
||||
*/
|
||||
void usbSendReportBuffer(uint8_t* reportbuffer, uint8_t size) {
|
||||
while (!usbInterruptIsReady()) {
|
||||
usbPoll();
|
||||
}
|
||||
usbSetInterrupt(reportbuffer, size); // send
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a single report to the computer. This function is not used during
|
||||
* normal typing, it is only used to send non-pressed keys to simulate input.
|
||||
@ -353,23 +365,11 @@ void usbSendReport(uint8_t mode, uint8_t key) {
|
||||
repBuffer[0] = mode;
|
||||
repBuffer[2] = key;
|
||||
wdt_reset();
|
||||
while (!usbInterruptIsReady()) {
|
||||
usbPoll();
|
||||
}
|
||||
usbSetInterrupt(repBuffer, sizeof(repBuffer)); // send
|
||||
usbSendReportBuffer(repBuffer, sizeof(repBuffer));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* This structure can be used as a container for a single 'key'. It consists of
|
||||
* the key-code and the modifier-code.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t mode;
|
||||
uint8_t key;
|
||||
} Key;
|
||||
|
||||
/**
|
||||
* Convert an ASCII-character to the corresponding key-code and modifier-code
|
||||
* combination.
|
||||
@ -574,6 +574,7 @@ int main(void) {
|
||||
uint8_t updateNeeded = 0;
|
||||
uint8_t idleCounter = 0;
|
||||
uint8_t updates = 0;
|
||||
uint16_t tickcounter = 0;
|
||||
wdt_enable(WDTO_2S);
|
||||
hardwareInit();
|
||||
usbInit();
|
||||
@ -595,8 +596,12 @@ int main(void) {
|
||||
// check timer if we need periodic reports
|
||||
if (TIFR & (1 << TOV0)) {
|
||||
TIFR = (1 << TOV0); // reset flag
|
||||
if (tickcounter < UINT16_MAX) {
|
||||
tickcounter++;
|
||||
}
|
||||
calculateSpeed(updates);
|
||||
updates = 0;
|
||||
/*
|
||||
if (idleRate != 0) { // do we need periodic reports?
|
||||
if(idleCounter > 4){ // yes, but not yet
|
||||
idleCounter -= 5; // 22ms in units of 4ms
|
||||
@ -605,11 +610,13 @@ int main(void) {
|
||||
idleCounter = idleRate;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
// if an update is needed, send the report
|
||||
if (updateNeeded && usbInterruptIsReady()) {
|
||||
if (updateNeeded) {
|
||||
updateNeeded = 0;
|
||||
usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
|
||||
keypressed(reportBuffer, sizeof(reportBuffer), tickcounter);
|
||||
tickcounter = 0;
|
||||
memcpy(oldReportBuffer, reportBuffer, sizeof(oldReportBuffer));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user