2018-12-06 08:31:21 +06:00
|
|
|
#include "dichotomy.h"
|
2017-10-10 23:07:59 +06:00
|
|
|
|
2021-12-15 17:00:39 +06:00
|
|
|
//#include "uart.h"
|
|
|
|
|
2023-04-02 00:01:46 +06:00
|
|
|
bool pointing_device_task(void){
|
2018-12-06 08:31:21 +06:00
|
|
|
/*report_mouse_t currentReport = {};
|
2017-10-10 23:07:59 +06:00
|
|
|
uint32_t timeout = 0;
|
|
|
|
|
|
|
|
//the m character requests the RF slave to send the mouse report
|
2021-12-15 17:00:39 +06:00
|
|
|
uart_write('m');
|
2017-10-10 23:07:59 +06:00
|
|
|
|
|
|
|
//trust the external inputs completely, erase old data
|
|
|
|
uint8_t uart_data[5] = {0};
|
|
|
|
|
|
|
|
//there are 10 bytes corresponding to 10 columns, and an end byte
|
|
|
|
for (uint8_t i = 0; i < 5; i++) {
|
|
|
|
//wait for the serial data, timeout if it's been too long
|
|
|
|
//this only happened in testing with a loose wire, but does no
|
|
|
|
//harm to leave it in here
|
2021-12-15 17:00:39 +06:00
|
|
|
while(!uart_available()){
|
2017-10-10 23:07:59 +06:00
|
|
|
timeout++;
|
|
|
|
if (timeout > 10000){
|
2018-12-06 08:31:21 +06:00
|
|
|
xprintf("\r\nTIMED OUT");
|
2017-10-10 23:07:59 +06:00
|
|
|
break;
|
|
|
|
}
|
2018-12-06 08:31:21 +06:00
|
|
|
}
|
|
|
|
xprintf("\r\nGOT DATA for %d",i);
|
2021-12-15 17:00:39 +06:00
|
|
|
uart_data[i] = uart_read();
|
2017-10-10 23:07:59 +06:00
|
|
|
}
|
|
|
|
|
2018-12-06 08:31:21 +06:00
|
|
|
//check for the end packet, bytes 1-4 are movement and scroll
|
|
|
|
//but byte 5 has bits 0-3 for the scroll button state
|
2017-10-10 23:07:59 +06:00
|
|
|
//(1000 if pressed, 0000 if not) and bits 4-7 are always 1
|
|
|
|
//We can use this to verify the report sent properly.
|
|
|
|
if (uart_data[4] == 0x0F || uart_data[4] == 0x8F)
|
|
|
|
{
|
2018-12-06 08:31:21 +06:00
|
|
|
xprintf("\r\nREQUESTED MOUSE, RECEIVED %i, %i, %i, %i, %i",uart_data[0],uart_data[1],uart_data[2],uart_data[3],uart_data[4]);
|
2017-10-10 23:07:59 +06:00
|
|
|
currentReport = pointing_device_get_report();
|
|
|
|
//shifting and transferring the info to the mouse report varaible
|
|
|
|
//mouseReport.x = 127 max -127 min
|
2018-12-06 08:31:21 +06:00
|
|
|
currentReport.x = (int8_t) uart_data[0];
|
2017-10-10 23:07:59 +06:00
|
|
|
//mouseReport.y = 127 max -127 min
|
2018-12-06 08:31:21 +06:00
|
|
|
currentReport.y = (int8_t) uart_data[1];
|
2017-10-10 23:07:59 +06:00
|
|
|
//mouseReport.v = 127 max -127 min (scroll vertical)
|
2018-12-06 08:31:21 +06:00
|
|
|
currentReport.v = (int8_t) uart_data[2];
|
2017-10-10 23:07:59 +06:00
|
|
|
//mouseReport.h = 127 max -127 min (scroll horizontal)
|
2018-12-06 08:31:21 +06:00
|
|
|
currentReport.h = (int8_t) uart_data[3];
|
2017-10-10 23:07:59 +06:00
|
|
|
//mouseReport.buttons = 0x31 max (bitmask for mouse buttons 1-5) 0x00 min
|
|
|
|
//mouse buttons 1 and 2 are handled by the keymap, but not 3
|
|
|
|
if (uart_data[4] == 0x0F) { //then 3 is not pressed
|
|
|
|
currentReport.buttons &= ~MOUSE_BTN3; //MOUSE_BTN3 is def in report.h
|
|
|
|
} else { //3 must be pressed
|
|
|
|
currentReport.buttons |= MOUSE_BTN3;
|
|
|
|
}
|
|
|
|
pointing_device_set_report(currentReport);
|
2018-12-06 08:31:21 +06:00
|
|
|
} else {
|
|
|
|
xprintf("\r\nRequested packet, data 4 was %d",uart_data[4]);
|
|
|
|
}*/
|
2023-04-02 00:01:46 +06:00
|
|
|
return pointing_device_send();
|
2017-10-10 23:07:59 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
void led_init(void) {
|
2020-03-06 14:47:52 +06:00
|
|
|
setPinOutput(D1);
|
|
|
|
setPinOutput(F5);
|
|
|
|
setPinOutput(F6);
|
|
|
|
|
|
|
|
writePinHigh(D1);
|
|
|
|
writePinHigh(F5);
|
|
|
|
writePinHigh(F6);
|
2017-10-10 23:07:59 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void matrix_init_kb(void) {
|
|
|
|
// put your keyboard start-up code here
|
|
|
|
// runs once when the firmware starts up
|
|
|
|
matrix_init_user();
|
|
|
|
led_init();
|
|
|
|
}
|