Skip to content

Commit 05daa17

Browse files
committed
Fixlibmkc partially
1 parent d4f2fea commit 05daa17

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

libmkc/libmkc.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ LibMK_Result libmk_start_controller(LibMK_Controller* controller) {
7373
return r;
7474
pthread_create(
7575
&controller->thread, NULL,
76-
(void*) libmk_run_controller, (void*) &controller);
76+
(void*) libmk_run_controller, (void*) controller);
7777
return LIBMK_SUCCESS;
7878
}
7979

@@ -95,12 +95,15 @@ void libmk_run_controller(LibMK_Controller* controller) {
9595
if (r != LIBMK_SUCCESS) {
9696
libmk_set_controller_error(controller, r);
9797
break;
98-
} else {
99-
// Move on to next instruction
100-
LibMK_Instruction* old = controller->instr;
101-
controller->instr = controller->instr->next;
102-
libmk_free_instruction(old);
10398
}
99+
// Sleep
100+
struct timespec delay;
101+
delay.tv_nsec = controller->instr->duration;
102+
nanosleep(&delay, NULL);
103+
// Move on to next instruction
104+
LibMK_Instruction* old = controller->instr;
105+
controller->instr = controller->instr->next;
106+
libmk_free_instruction(old);
104107
}
105108
int r = libmk_disable_control(controller->handle);
106109
if (r != LIBMK_SUCCESS) {
@@ -153,8 +156,8 @@ LibMK_Controller_State libmk_join_controller(
153156
pthread_mutex_lock(&controller->state_lock);
154157
s = controller->state;
155158
pthread_mutex_unlock(&controller->state_lock);
156-
if (s != LIBMK_STATE_ACTIVE)
157-
break;
159+
// if (s != LIBMK_STATE_ACTIVE)
160+
// break;
158161
elapsed = ((double) (clock() - t)) / CLOCKS_PER_SEC;
159162
if (elapsed > timeout)
160163
return LIBMK_STATE_JOIN_ERR;

utils/ctrl.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,24 @@ int main(void) {
3030
continue;
3131
}
3232

33+
fprintf(stdout, " Starting controlller... ");
3334
libmk_start_controller(ctrl);
35+
printf("Done.\n");
36+
37+
fprintf(stdout, " Scheduling instruction... ");
3438
unsigned char color[3] = {100, 0, 0};
3539
LibMK_Instruction* full = libmk_create_instruction_full(color);
3640
unsigned int n = libmk_sched_instruction(ctrl, full);
37-
printf(" Scheduled instruction %d\n", n);
38-
sleep(4);
41+
printf("Done: %d.\n", full->id);
42+
43+
fprintf(stdout, " Waiting for instruction execution...");
44+
sleep(1);
45+
printf(" Done.\n");
46+
47+
fprintf(stdout, " Stopping controller... ");
3948
libmk_stop_controller(ctrl);
49+
printf("Done.\n");
50+
4051
LibMK_Controller_State s = libmk_join_controller(ctrl, 3);
4152
if (s != LIBMK_STATE_STOPPED)
4253
printf(" Could not stop the Controller: %d\n", s);

0 commit comments

Comments
 (0)