| Line 30... |
Line 30... |
| 30 |
static int chooser_action_handler_wheel_init(struct chooser_data* data)
|
30 |
static int chooser_action_handler_wheel_init(struct chooser_data* data)
|
| 31 |
{
|
31 |
{
|
| 32 |
const struct chooser_action_handler_wheel_params* params;
|
32 |
const struct chooser_action_handler_wheel_params* params;
|
| 33 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
33 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
| 34 |
if (params->version != CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION) return -1;
|
34 |
if (params->version != CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION) return -1;
|
| - |
|
35 |
data->actionhandlerdata = malloc(sizeof(struct chooser_action_handler_wheel_data));
|
| - |
|
36 |
if (!data->actionhandlerdata) return -2;
|
| - |
|
37 |
struct chooser_action_handler_wheel_data* adata;
|
| - |
|
38 |
adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
| - |
|
39 |
adata->timeout_remaining = params->timeout_initial;
|
| - |
|
40 |
adata->lasttick = USEC_TIMER;
|
| 35 |
return 0;
|
41 |
return 0;
|
| 36 |
}
|
42 |
}
|
| 37 |
|
43 |
|
| 38 |
static enum chooser_result chooser_action_handler_wheel_handleevent(struct chooser_data* data,
|
44 |
static enum chooser_result chooser_action_handler_wheel_handleevent(struct chooser_data* data,
|
| 39 |
enum button_event event,
|
45 |
enum button_event event,
|
| 40 |
int which, int value)
|
46 |
int which, int value)
|
| 41 |
{
|
47 |
{
|
| 42 |
const struct chooser_action_handler_wheel_params* params;
|
48 |
const struct chooser_action_handler_wheel_params* params;
|
| 43 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
49 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
| - |
|
50 |
struct chooser_action_handler_wheel_data* adata;
|
| - |
|
51 |
adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
| 44 |
if (params->eventfilter && params->eventfilter(data, event, which, value))
|
52 |
if (params->eventfilter && params->eventfilter(data, event, which, value))
|
| 45 |
return CHOOSER_RESULT_OK;
|
53 |
return CHOOSER_RESULT_OK;
|
| - |
|
54 |
adata->timeout_remaining = params->timeout_idle;
|
| 46 |
int spi = params->stepsperitem;
|
55 |
int spi = params->stepsperitem;
|
| 47 |
switch (event)
|
56 |
switch (event)
|
| 48 |
{
|
57 |
{
|
| 49 |
case BUTTON_PRESS:
|
58 |
case BUTTON_PRESS:
|
| 50 |
if (which < params->buttoncount)
|
59 |
if (which < params->buttoncount)
|
| Line 77... |
Line 86... |
| 77 |
return CHOOSER_RESULT_REDRAW;
|
86 |
return CHOOSER_RESULT_REDRAW;
|
| 78 |
}
|
87 |
}
|
| 79 |
return CHOOSER_RESULT_OK;
|
88 |
return CHOOSER_RESULT_OK;
|
| 80 |
}
|
89 |
}
|
| 81 |
|
90 |
|
| - |
|
91 |
static enum chooser_result chooser_action_handler_wheel_handletick(struct chooser_data* data)
|
| - |
|
92 |
{
|
| - |
|
93 |
const struct chooser_action_handler_wheel_params* params;
|
| - |
|
94 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
| - |
|
95 |
struct chooser_action_handler_wheel_data* adata;
|
| - |
|
96 |
adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
| - |
|
97 |
if (adata->timeout_remaining == TIMEOUT_BLOCK) return CHOOSER_RESULT_OK;
|
| - |
|
98 |
long time = USEC_TIMER;
|
| - |
|
99 |
adata->timeout_remaining -= time - adata->lasttick;
|
| - |
|
100 |
adata->lasttick = time;
|
| - |
|
101 |
if (adata->timeout_remaining < 0)
|
| - |
|
102 |
{
|
| - |
|
103 |
if (params->timeout_item == CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL)
|
| - |
|
104 |
return CHOOSER_RESULT_CANCEL;
|
| - |
|
105 |
else if (params->timeout_item != CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_KEEP)
|
| - |
|
106 |
data->selected = &data->info->items[params->timeout_item];
|
| - |
|
107 |
return CHOOSER_RESULT_FINISHED;
|
| - |
|
108 |
}
|
| - |
|
109 |
if (params->tick_force_redraw) return CHOOSER_RESULT_REDRAW;
|
| - |
|
110 |
return CHOOSER_RESULT_OK;
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| 82 |
static int chooser_action_handler_wheel_stepsperitem(struct chooser_data* data)
|
113 |
static int chooser_action_handler_wheel_stepsperitem(struct chooser_data* data)
|
| 83 |
{
|
114 |
{
|
| 84 |
const struct chooser_action_handler_wheel_params* params;
|
115 |
const struct chooser_action_handler_wheel_params* params;
|
| 85 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
116 |
params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
| 86 |
return params->stepsperitem;
|
117 |
return params->stepsperitem;
|
| 87 |
}
|
118 |
}
|
| 88 |
|
119 |
|
| - |
|
120 |
static void chooser_ction_handler_wheel_destroy(struct chooser_data* data)
|
| - |
|
121 |
{
|
| - |
|
122 |
free(data->actionhandlerdata);
|
| - |
|
123 |
}
|
| - |
|
124 |
|
| 89 |
|
125 |
|
| 90 |
const struct chooser_action_handler chooser_action_handler_wheel =
|
126 |
const struct chooser_action_handler chooser_action_handler_wheel =
|
| 91 |
{
|
127 |
{
|
| 92 |
.version = CHOOSER_ACTION_HANDLER_VERSION,
|
128 |
.version = CHOOSER_ACTION_HANDLER_VERSION,
|
| 93 |
.init = chooser_action_handler_wheel_init,
|
129 |
.init = chooser_action_handler_wheel_init,
|
| 94 |
.handleevent = chooser_action_handler_wheel_handleevent,
|
130 |
.handleevent = chooser_action_handler_wheel_handleevent,
|
| 95 |
.handletick = NULL,
|
131 |
.handletick = chooser_action_handler_wheel_handletick,
|
| 96 |
.stepsperitem = chooser_action_handler_wheel_stepsperitem,
|
132 |
.stepsperitem = chooser_action_handler_wheel_stepsperitem,
|
| 97 |
.destroy = NULL
|
133 |
.destroy = chooser_ction_handler_wheel_destroy
|
| 98 |
};
|
134 |
};
|