Skip to content

Commit 85adbac

Browse files
committed
Build documentation for libmkc
1 parent 8042cc6 commit 85adbac

File tree

8 files changed

+235
-65
lines changed

8 files changed

+235
-65
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface to the LEDs on the MasterKeys keyboard series.
1212
source/devices
1313
source/examples/index
1414
Documentation: libmk <source/libmk/index>
15+
Documentation: libmkc <source/libmkc/index>
1516
Documentation: masterkeys <source/masterkeys/index>
1617

1718
.. |Travis| image:: https://api.travis-ci.com/RedFantom/masterkeys-linux.svg

docs/source/libmkc/enums/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enums
2+
=====
3+
4+
.. doxygenenum:: LibMK_Controller_State
5+
.. doxygenenum:: LibMK_Instruction_Type
6+

docs/source/libmkc/funcs/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Functions
2+
=========
3+
4+
.. doxygenfunction:: libmk_create_controller
5+
.. doxygenfunction:: libmk_free_controller
6+
.. doxygenfunction:: libmk_sched_instruction
7+
.. doxygenfunction:: libmk_cancel_instruction
8+
.. doxygenfunction:: libmk_start_controller
9+
.. doxygenfunction:: libmk_run_controller
10+
.. doxygenfunction:: libmk_stop_controller
11+
.. doxygenfunction:: libmk_wait_controller
12+
.. doxygenfunction:: libmk_join_controller
13+
.. doxygenfunction:: libmk_set_controller_error
14+
.. doxygenfunction:: libmk_create_instruction
15+
.. doxygenfunction:: libmk_create_instruction_full
16+
.. doxygenfunction:: libmk_create_instruction_all
17+
.. doxygenfunction:: libmk_create_instruction_flash
18+
.. doxygenfunction:: libmk_create_instruction_single
19+
.. doxygenfunction:: libmk_free_instruction
20+
.. doxygenfunction:: libmk_exec_instruction

docs/source/libmkc/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Documentation
2+
=============
3+
4+
.. toctree::
5+
6+
enums/index
7+
funcs/index
8+
structs/index
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Structs
2+
=======
3+
4+
.. doxygenstruct:: LibMK_Instruction
5+
:members:
6+
.. doxygenstruct:: LibMK_Controller
7+
:members:
8+

libmk/libmk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef enum LibMK_Result {
5151
LIBMK_ERR_DESCR = -11, ///< Failed to get libusb device descriptor
5252
LIBMK_ERR_PROTOCOL = -13, ///< Keyboard interaction protocol error
5353
LIBMK_ERR_INVALID_ARG = -14, ///< Invalid arguments passed by caller
54-
LIBMK_ERR_STILL_ACTIVE = -15,
54+
LIBMK_ERR_STILL_ACTIVE = -15, ///< Controller is still active
5555
} LibMK_Result;
5656

5757

libmk/libmkc.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
LibMK_Controller* libmk_create_controller(LibMK_Handle* handle) {
16-
/** Build a new LibMK Controller for a Device */
1716
LibMK_Controller* controller = (LibMK_Controller*) malloc(
1817
sizeof(LibMK_Controller));
1918
if (controller == NULL)
@@ -32,7 +31,6 @@ LibMK_Controller* libmk_create_controller(LibMK_Handle* handle) {
3231

3332

3433
LibMK_Controller_State libmk_get_controller_state(LibMK_Controller* c) {
35-
/** Return whether the given controller is running (active) */
3634
pthread_mutex_lock(&(c->state_lock));
3735
LibMK_Controller_State b = c->state;
3836
pthread_mutex_unlock(&c->state_lock);
@@ -41,7 +39,6 @@ LibMK_Controller_State libmk_get_controller_state(LibMK_Controller* c) {
4139

4240

4341
LibMK_Result libmk_get_controller_error(LibMK_Controller* c) {
44-
/** Return an error if the controller has one set */
4542
pthread_mutex_lock(&(c->error_lock));
4643
LibMK_Result r = c->error;
4744
pthread_mutex_unlock(&(c->error_lock));
@@ -50,7 +47,6 @@ LibMK_Result libmk_get_controller_error(LibMK_Controller* c) {
5047

5148

5249
LibMK_Result libmk_free_controller(LibMK_Controller* c) {
53-
/** Free the memory allocated for a LibMK_Controller struct */
5450
if (libmk_get_controller_state(c) == LIBMK_STATE_ACTIVE)
5551
return LIBMK_ERR_STILL_ACTIVE;
5652
pthread_mutex_destroy(&c->state_lock);
@@ -67,7 +63,6 @@ LibMK_Result libmk_free_controller(LibMK_Controller* c) {
6763

6864

6965
LibMK_Result libmk_start_controller(LibMK_Controller* controller) {
70-
/** Start a LibMK_Controller in a new thread */
7166
LibMK_Result r = (LibMK_Result) libmk_enable_control(controller->handle);
7267
if (r != LIBMK_SUCCESS)
7368
return r;
@@ -79,7 +74,6 @@ LibMK_Result libmk_start_controller(LibMK_Controller* controller) {
7974

8075

8176
void libmk_run_controller(LibMK_Controller* controller) {
82-
/** Execute instructions on a LibMK_Controller in a separate thread */
8377
pthread_mutex_lock(&(controller->state_lock));
8478
controller->state = LIBMK_STATE_ACTIVE;
8579
pthread_mutex_unlock(&(controller->state_lock));
@@ -124,7 +118,6 @@ void libmk_run_controller(LibMK_Controller* controller) {
124118

125119

126120
void libmk_set_controller_error(LibMK_Controller* c, LibMK_Result e) {
127-
/** Set an error in the controller struct if one has not been set */
128121
pthread_mutex_lock(&(c->error_lock));
129122
if (c->error == LIBMK_SUCCESS)
130123
c->error = e;
@@ -133,27 +126,27 @@ void libmk_set_controller_error(LibMK_Controller* c, LibMK_Result e) {
133126

134127

135128
LibMK_Result libmk_exec_instruction(LibMK_Handle* h, LibMK_Instruction* i) {
136-
/** Execute a single instruction on the keyboard controlled */
137129
if (i == NULL)
138130
return libmk_send_control_packet(h);
139131
else if (i->type == LIBMK_INSTR_ALL) {
140132
return libmk_set_all_led_color(h, i->colors);
141133
} else if (i->type == LIBMK_INSTR_FULL) {
142134
return libmk_set_full_color(h, i->color[0], i->color[1], i->color[2]);
135+
} else if (i->type == LIBMK_INSTR_SINGLE) {
136+
return libmk_set_single_led(
137+
h, i->r, i->c, i->color[0], i->color[1], i->color[2]);
143138
}
144139
}
145140

146141

147142
void libmk_stop_controller(LibMK_Controller* controller) {
148-
/** Stop a LibMK_Controller running in a separate thread */
149143
pthread_mutex_lock(&(controller->exit_flag_lock));
150144
controller->exit_flag = true;
151145
pthread_mutex_unlock(&(controller->exit_flag_lock));
152146
}
153147

154148

155149
void libmk_wait_controller(LibMK_Controller* controller) {
156-
/** Set the flag to wait for the controller to finish scheduled instr */
157150
pthread_mutex_lock(&(controller->exit_flag_lock));
158151
controller->wait_flag = true;
159152
pthread_mutex_unlock(&(controller->exit_flag_lock));
@@ -162,7 +155,6 @@ void libmk_wait_controller(LibMK_Controller* controller) {
162155

163156
LibMK_Controller_State libmk_join_controller(
164157
LibMK_Controller* controller, double timeout) {
165-
/** Join a LibMK_Controller into the current thread (return state) */
166158
LibMK_Controller_State s;
167159
clock_t t = clock();
168160
double elapsed;
@@ -181,7 +173,6 @@ LibMK_Controller_State libmk_join_controller(
181173

182174

183175
void libmk_free_instruction(LibMK_Instruction* i) {
184-
/** Free the memory allocated for an executed instruction */
185176
fflush(stdout);
186177
if (i->colors != NULL)
187178
free(i->colors);
@@ -190,20 +181,30 @@ void libmk_free_instruction(LibMK_Instruction* i) {
190181

191182

192183
LibMK_Instruction* libmk_create_instruction() {
193-
/** Allocate a new LibMK_Instruction struct */
194184
LibMK_Instruction* i =
195185
(LibMK_Instruction*) malloc(sizeof(LibMK_Instruction));
196186
i->duration = 0;
197-
i->id = 0;
187+
i->id = -1;
198188
i->type = -1;
199189
i->next = NULL;
200190
i->colors = NULL;
201191
return i;
202192
}
203193

204194

195+
LibMK_Instruction* libmk_create_instruction_single(
196+
unsigned char row, unsigned char column, unsigned char color[3]) {
197+
LibMK_Instruction* i = libmk_create_instruction();
198+
i->type = LIBMK_INSTR_SINGLE;
199+
for (unsigned char j=0; j<3; j++)
200+
i->color[j] = color[j];
201+
i->r = row;
202+
i->c = column;
203+
return i;
204+
}
205+
206+
205207
LibMK_Instruction* libmk_create_instruction_full(unsigned char c[3]) {
206-
/** Create a new instruction that sets a full LED color */
207208
LibMK_Instruction* i = libmk_create_instruction();
208209
for (unsigned char j=0; j<3; j++)
209210
i->color[j] = c[j];
@@ -214,7 +215,6 @@ LibMK_Instruction* libmk_create_instruction_full(unsigned char c[3]) {
214215

215216
LibMK_Instruction* libmk_create_instruction_all(
216217
unsigned char c[LIBMK_MAX_ROWS][LIBMK_MAX_COLS][3]) {
217-
/** Create a new instruction that sets the color of all individual LEDs */
218218
LibMK_Instruction* i = libmk_create_instruction();
219219
i->colors = (unsigned char*) malloc(
220220
sizeof(unsigned char) * LIBMK_MAX_ROWS * LIBMK_MAX_COLS * 3);
@@ -252,10 +252,11 @@ LibMK_Instruction* libmk_create_instruction_flash(
252252
}
253253

254254

255-
LibMK_Result libmk_sched_instruction(
256-
LibMK_Controller* c, LibMK_Instruction* i) {
257-
/** Schedule a single instruction for execution on the controller */
255+
int libmk_sched_instruction(
256+
LibMK_Controller* c, LibMK_Instruction* i) {
258257
pthread_mutex_lock(&(c->instr_lock));
258+
if (i->id != -1)
259+
return LIBMK_ERR_INVALID_ARG; // Instruction already scheduled!
259260
if (c->instr == NULL) {
260261
c->instr = i;
261262
c->instr->id = 1;
@@ -279,13 +280,13 @@ LibMK_Result libmk_sched_instruction(
279280
k = k->next;
280281
}
281282
}
283+
int first_id = i->id;
282284
pthread_mutex_unlock(&(c->instr_lock));
283-
return LIBMK_SUCCESS;
285+
return first_id;
284286
}
285287

286288

287289
LibMK_Result libmk_cancel_instruction(LibMK_Controller* c, unsigned int id) {
288-
/** Cancel a scheduled instruction from executing */
289290
pthread_mutex_lock(&(c->instr_lock));
290291
LibMK_Instruction* prev = NULL;
291292
LibMK_Instruction* curr = c->instr;

0 commit comments

Comments
 (0)