Skip to content

Commit 8df771b

Browse files
author
Sebastien Bourdeauducq
committedNov 13, 2011
simple mode: random delays
1 parent 252720c commit 8df771b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed
 

Diff for: ‎src/performance.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <assert.h>
1919
#include <rtems.h>
2020
#include <stdio.h>
21+
#include <stdlib.h>
2122
#include <string.h>
2223
#include <dirent.h>
2324
#include <fcntl.h>
@@ -357,7 +358,15 @@ static int keycode_to_index(int keycode)
357358
}
358359

359360
static rtems_interval next_as_time;
360-
#define AUTOSWITCH_PERIOD 3000
361+
#define AUTOSWITCH_PERIOD_MIN (2*60*100)
362+
#define AUTOSWITCH_PERIOD_MAX (4*60*100)
363+
static void update_next_as_time()
364+
{
365+
rtems_interval t;
366+
367+
t = rtems_clock_get_ticks_since_boot();
368+
next_as_time = t + AUTOSWITCH_PERIOD_MIN + (rand() % (AUTOSWITCH_PERIOD_MAX - AUTOSWITCH_PERIOD_MIN));
369+
}
361370

362371
static int suitable_for_simple(struct patch *p)
363372
{
@@ -384,18 +393,16 @@ static void event_callback(mtk_event *e, int count)
384393
next = 0;
385394
for(i=0;i<count;i++) {
386395
if(e[i].type == EVENT_TYPE_PRESS) {
387-
if (e[i].press.code == MTK_KEY_F11)
396+
if(e[i].press.code == MTK_KEY_F11)
388397
next = 1;
389-
if (e[i].press.code == MTK_KEY_F9)
398+
if(e[i].press.code == MTK_KEY_F9)
390399
next = -1;
391400
}
392401
}
393402
if(as_mode) {
394403
t = rtems_clock_get_ticks_since_boot();
395-
if(t >= next_as_time) {
404+
if(t >= next_as_time)
396405
next = 1;
397-
next_as_time = t + AUTOSWITCH_PERIOD;
398-
}
399406
}
400407
if(next) {
401408
looped = current_patch;
@@ -407,6 +414,8 @@ static void event_callback(mtk_event *e, int count)
407414
current_patch = npatches - 1;
408415
} while(!suitable_for_simple(patches[current_patch].p) && (looped != current_patch));
409416
index = current_patch;
417+
if(as_mode)
418+
update_next_as_time();
410419
}
411420
if(dt_mode && (index != -1))
412421
osd_event(patches[index].filename);
@@ -460,7 +469,7 @@ static void refresh_callback(mtk_event *e, int count)
460469
if(compiled_patches == npatches) {
461470
/* All patches compiled. Start rendering. */
462471
input_delete_callback(refresh_callback);
463-
next_as_time = t + AUTOSWITCH_PERIOD;
472+
update_next_as_time();
464473
input_add_callback(event_callback);
465474
mtk_cmd(appid, "l_status.set(-text \"Ready.\")");
466475

0 commit comments

Comments
 (0)
Please sign in to comment.