Skip to content

Commit

Permalink
play_on_upload do not emit play during effect update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kethen committed Aug 27, 2024
1 parent b86c7da commit deace1b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
5 changes: 1 addition & 4 deletions driver_loops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,7 @@ static void *uinput_poll_loop(void *arg){
upload.request_id = e.value;
ioctl(loop_context->uinput_fd, UI_BEGIN_FF_UPLOAD, &upload);
pthread_mutex_lock(&loop_context->device_mutex);
upload.retval = lg4ff_upload_effect(&loop_context->ffb_device, &upload.effect, &upload.old, loop_context->context.log_effects);
if(loop_context->context.play_on_upload && upload.retval == 0){
lg4ff_play_effect(&loop_context->ffb_device, upload.effect.id, 1, loop_context->context.log_effects);
}
upload.retval = lg4ff_upload_effect(&loop_context->ffb_device, &upload.effect, &upload.old, loop_context->context.log_effects, loop_context->context.play_on_upload);
pthread_mutex_unlock(&loop_context->device_mutex);
ioctl(loop_context->uinput_fd, UI_END_FF_UPLOAD, &upload);
break;
Expand Down
62 changes: 33 additions & 29 deletions force_feedback.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,37 @@ uint64_t get_time_ms(){
return tp.tv_nsec / 1000000 + tp.tv_sec * 1000;
}

int lg4ff_upload_effect(struct lg4ff_device *device, struct ff_effect *effect, struct ff_effect *old, bool log)
int lg4ff_play_effect(struct lg4ff_device *device, int effect_id, int value, bool log)
{
struct lg4ff_effect_state *state;
uint64_t now = get_time_ms();

state = &device->states[effect_id];

if (value > 0) {
if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
STOP_EFFECT(state);
} else {
device->effects_used++;
}
__set_bit(FF_EFFECT_STARTED, &state->flags);
state->start_at = now;
state->count = value;
if(log){
STDOUT("--play--\n");
log_effect(&state->effect);
}
} else {
if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
STOP_EFFECT(state);
device->effects_used--;
}
}

return 0;
}

int lg4ff_upload_effect(struct lg4ff_device *device, struct ff_effect *effect, struct ff_effect *old, bool log, bool play_on_upload)
{
struct lg4ff_effect_state *state;
uint64_t now = get_time_ms();
Expand All @@ -70,34 +100,8 @@ int lg4ff_upload_effect(struct lg4ff_device *device, struct ff_effect *effect, s
log_effect(effect);
}

return 0;
}

int lg4ff_play_effect(struct lg4ff_device *device, int effect_id, int value, bool log)
{
struct lg4ff_effect_state *state;
uint64_t now = get_time_ms();

state = &device->states[effect_id];

if (value > 0) {
if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
STOP_EFFECT(state);
} else {
device->effects_used++;
}
__set_bit(FF_EFFECT_STARTED, &state->flags);
state->start_at = now;
state->count = value;
if(log){
STDOUT("--play--\n");
log_effect(&state->effect);
}
} else {
if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
STOP_EFFECT(state);
device->effects_used--;
}
if(play_on_upload && !test_bit(FF_EFFECT_PLAYING, &state->flags)){
lg4ff_play_effect(device, effect->id, 1, log);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion force_feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct lg4ff_device{
};

void lg4ff_init_slots(struct lg4ff_device *device);
int lg4ff_upload_effect(struct lg4ff_device *device, struct ff_effect *effect, struct ff_effect *old, bool log);
int lg4ff_upload_effect(struct lg4ff_device *device, struct ff_effect *effect, struct ff_effect *old, bool log, bool play_on_upload);
int lg4ff_play_effect(struct lg4ff_device *device, int effect_id, int value, bool log);
int lg4ff_timer(struct lg4ff_device *device);

Expand Down

0 comments on commit deace1b

Please sign in to comment.