-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #409 from paulscottrobson/mouse_support
USB mouse support
- Loading branch information
Showing
9 changed files
with
213 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// *************************************************************************************** | ||
// *************************************************************************************** | ||
// | ||
// Name : mouse.cpp | ||
// Authors : Paul Robson ([email protected]) | ||
// Sascha Schneider ([email protected]) | ||
// Date : 3rd April 2024 | ||
// Reviewed : No | ||
// Purpose : Mouse code. | ||
// | ||
// *************************************************************************************** | ||
// *************************************************************************************** | ||
|
||
#include "common.h" | ||
#include "data/cursors.h" | ||
|
||
static uint16_t xCursor, yCursor; // Current position | ||
static bool isCursorVisible; // True if visible | ||
static uint8_t buttonState; | ||
static uint8_t scrollWheelState; | ||
|
||
// *************************************************************************************** | ||
// | ||
// Initialise mouse | ||
// | ||
// *************************************************************************************** | ||
|
||
void MSEInitialise(void) { | ||
xCursor = yCursor = 0; | ||
buttonState = 0; | ||
scrollWheelState = 0; | ||
isCursorVisible = false; | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Set cursor position | ||
// | ||
// *************************************************************************************** | ||
|
||
void MSESetPosition(uint16_t x, uint16_t y) { | ||
xCursor = x; | ||
yCursor = y; | ||
} | ||
|
||
void MSEOffsetPosition(int8_t dx, int8_t dy) { | ||
if(dx < 0 && xCursor < abs(dx)) { | ||
xCursor = 0; | ||
} else { | ||
xCursor += dx; | ||
} | ||
if(dy < 0 && yCursor < abs(dy)) { | ||
yCursor = 0; | ||
} else { | ||
yCursor += dy; | ||
} | ||
|
||
if(xCursor > gMode.xGSize) xCursor = gMode.xGSize; | ||
if(yCursor > gMode.yGSize) yCursor = gMode.yGSize; | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Update cursor visibility | ||
// | ||
// *************************************************************************************** | ||
|
||
void MSESetVisible(bool isVisible) { | ||
isCursorVisible = isVisible; | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Get cursor draw information | ||
// | ||
// *************************************************************************************** | ||
|
||
bool MSEGetCursorDrawInformation(const uint8_t **pData, uint16_t *pX, uint16_t *pY) { | ||
*pData = default_cursor_data; // Just one cursor | ||
*pX = xCursor; *pY = yCursor; // This is top left - so crosshairs will need adjusting for example. | ||
return isCursorVisible && xCursor < gMode.xGSize && yCursor < gMode.yGSize; // On and on screen. | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Update mouse scroll wheel state | ||
// | ||
// *************************************************************************************** | ||
|
||
void MSEUpdateScrollWheel(int8_t ds) { | ||
scrollWheelState += ds; | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Update mouse button state | ||
// | ||
// *************************************************************************************** | ||
|
||
void MSEUpdateButtonState(uint8_t bs) { | ||
buttonState = bs; | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Get mouse position, button state and scroll wheel state | ||
// | ||
// *************************************************************************************** | ||
|
||
void MSEGetState(uint16_t *pX, uint16_t *pY, uint8_t *pButtonState, uint8_t *pScrollWheelState) { | ||
*pX = xCursor; | ||
*pY = yCursor; | ||
*pButtonState = buttonState; | ||
*pScrollWheelState = scrollWheelState; | ||
} | ||
|
||
// *************************************************************************************** | ||
// | ||
// Date Revision | ||
// ==== ======== | ||
// | ||
// *************************************************************************************** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.