Used a library-reference method to calibrate lightpen drivers.
The mouse reference is a pointer. If it's NULL, the driver uses a default. If it's non-NULL, then it points to a function that the driver can call. That function will adjust the driver's calibration value. It could ask the user to adjust the pen; or, it could read a file that holds a value from a previous calibration. Application writers can choose how it's done: a function that's provided by the library, a custom function, or nothing.
This commit is contained in:
53
libsrc/cbm/penadjust.c
Executable file
53
libsrc/cbm/penadjust.c
Executable file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
** Main lightpen driver calibration functions.
|
||||
**
|
||||
** 2013-06-23, Greg King
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <mouse.h>
|
||||
|
||||
|
||||
static const char *name;
|
||||
|
||||
|
||||
/* Get a lightpen calibration value from a file if it exists. Otherwise, call
|
||||
** pen_calibrate() to create a value; then, write it into a file, so that it
|
||||
** will be available at the next time that the lightpen is used.
|
||||
** Might change the screen.
|
||||
*/
|
||||
static void __fastcall__ adjuster (unsigned char *XOffset)
|
||||
{
|
||||
int fd = open (name, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
pen_calibrate (XOffset);
|
||||
fd = open (name, O_WRONLY | O_CREAT | O_EXCL);
|
||||
if (fd >= 0) {
|
||||
(void) write (fd, XOffset, 1);
|
||||
close (fd);
|
||||
}
|
||||
} else {
|
||||
(void) read (fd, XOffset, 1);
|
||||
close (fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* pen_adjust() is optional; if you want to use its feature,
|
||||
** then it must be called before a driver is installed.
|
||||
** Note: This function merely saves the file-name pointer, and sets
|
||||
** the mouse_adjuster pointer. The file will be read only when a driver
|
||||
** is installed, and only if that driver wants to be calibrated.
|
||||
*/
|
||||
void __fastcall__ pen_adjust (const char *filename)
|
||||
{
|
||||
if (filename != NULL && filename[0] != '\0') {
|
||||
name = filename;
|
||||
mouse_adjuster = adjuster;
|
||||
} else {
|
||||
mouse_adjuster = pen_calibrate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user