16 #include "../../gfx.h"
18 #if GFX_USE_GINPUT && GINPUT_NEED_DIAL
22 static GTIMER_DECL(DialTimer);
23 static struct DialStatus_t {
27 } DialStatus[GINPUT_DIAL_NUM_PORTS];
30 static void DialCallback(gU16 instance, gU16 rawvalue) {
31 struct DialStatus_t *pds;
36 pds = DialStatus+instance;
39 if (pds->max != GINPUT_DIAL_MAX_VALUE)
40 rawvalue = (gU16)((gU32)rawvalue * pds->max / GINPUT_DIAL_MAX_VALUE);
43 if (rawvalue >= pds->lastvalue) {
44 if (rawvalue - pds->lastvalue < pds->sensitivity)
return;
46 if (pds->lastvalue - rawvalue < pds->sensitivity)
return;
50 pds->lastvalue = rawvalue;
57 pe->type = GEVENT_DIAL;
58 pe->instance = instance;
59 pe->value = pds->lastvalue;
60 pe->maxvalue = pds->max;
66 struct DialStatus_t *pds;
68 if (instance >= GINPUT_DIAL_NUM_PORTS)
73 for(pds = DialStatus; pds < DialStatus+GINPUT_DIAL_NUM_PORTS; pds++) {
74 pds->max = GINPUT_DIAL_MAX_VALUE;
75 #if GINPUT_DIAL_MAX_VALUE < 100
78 pds->sensitivity = GINPUT_DIAL_MAX_VALUE/100;
82 ginput_lld_dial_init();
83 gtimerStart(&DialTimer, (GTimerFunction)ginput_lld_dial_poll, DialCallback, gTrue, GINPUT_DIAL_POLL_PERIOD);
87 return (GSourceHandle)(DialStatus+instance);
91 if (instance >= GINPUT_DIAL_NUM_PORTS)
98 if (instance >= GINPUT_DIAL_NUM_PORTS)
101 return DialStatus[instance].max;
105 struct DialStatus_t *pds;
107 if (instance >= GINPUT_DIAL_NUM_PORTS)
110 pds = DialStatus+instance;
113 if (max != pds->max) {
114 pds->lastvalue = (gU16)((gU32)pds->lastvalue * max / pds->max);
115 pds->sensitivity = (gU16)((gU32)pds->sensitivity * max / pds->max);
128 if (instance >= GINPUT_DIAL_NUM_PORTS)
131 DialStatus[instance].sensitivity = diff;
143 if (instance >= GINPUT_DIAL_NUM_PORTS)
145 pdial->type = GEVENT_DIAL;
146 pdial->instance = instance;
147 pdial->value = DialStatus[instance].lastvalue;
148 pdial->maxvalue = DialStatus[instance].max;
void ginputSetDialRange(gU16 instance, gU16 max)
Set the maximum value.
void ginputResetDialRange(gU16 instance)
Reset the value back to the hardware default.
GSourceHandle ginputGetDial(gU16 instance)
Create a dial input instance.
gU16 ginputGetDialRange(gU16 instance)
Get the maximum value.
void ginputSetDialSensitivity(gU16 instance, gU16 diff)
Set the level change required before a dial even is generated (threshold)
gBool ginputGetDialStatus(gU16 instance, GEventDial *pdial)
Get the current dial status.
GEvent * geventGetEventBuffer(GSourceListener *psl)
Get the event buffer from the GSourceListener.
void geventSendEvent(GSourceListener *psl)
Called by a source to indicate the listener's event buffer has been filled.
GSourceListener * geventGetSourceListener(GSourceHandle gsh, GSourceListener *lastlr)
Called by a source with a possible event to get a listener record.
void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, gBool periodic, gDelay millisec)
Set a timer going or alter its properties if it is already going.
gBool gtimerIsActive(GTimer *pt)
Test if a timer is currently active.