Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

simple mode: random delays

  • Loading branch information...
commit 8df771b5a2806f4ab73be415938e16b2c9671bd0 1 parent 252720c
Sébastien Bourdeauducq authored

Showing 1 changed file with 16 additions and 7 deletions. Show diff stats Hide diff stats

  1. 23  src/performance.c
23  src/performance.c
@@ -18,6 +18,7 @@
18 18
 #include <assert.h>
19 19
 #include <rtems.h>
20 20
 #include <stdio.h>
  21
+#include <stdlib.h>
21 22
 #include <string.h>
22 23
 #include <dirent.h>
23 24
 #include <fcntl.h>
@@ -357,7 +358,15 @@ static int keycode_to_index(int keycode)
357 358
 }
358 359
 
359 360
 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
+}
361 370
 
362 371
 static int suitable_for_simple(struct patch *p)
363 372
 {
@@ -384,18 +393,16 @@ static void event_callback(mtk_event *e, int count)
384 393
 		next = 0;
385 394
 		for(i=0;i<count;i++) {
386 395
 			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)
388 397
 					next = 1;
389  
-				if (e[i].press.code == MTK_KEY_F9)
  398
+				if(e[i].press.code == MTK_KEY_F9)
390 399
 					next = -1;
391 400
 			}
392 401
 		}
393 402
 		if(as_mode) {
394 403
 			t = rtems_clock_get_ticks_since_boot();
395  
-			if(t >= next_as_time) {
  404
+			if(t >= next_as_time)
396 405
 				next = 1;
397  
-				next_as_time = t + AUTOSWITCH_PERIOD;
398  
-			}
399 406
 		}
400 407
 		if(next) {
401 408
 			looped = current_patch;
@@ -407,6 +414,8 @@ static void event_callback(mtk_event *e, int count)
407 414
 					current_patch = npatches - 1;
408 415
 			} while(!suitable_for_simple(patches[current_patch].p) && (looped != current_patch));
409 416
 			index = current_patch;
  417
+			if(as_mode)
  418
+				update_next_as_time();
410 419
 		}
411 420
 		if(dt_mode && (index != -1))
412 421
 			osd_event(patches[index].filename);
@@ -460,7 +469,7 @@ static void refresh_callback(mtk_event *e, int count)
460 469
 			if(compiled_patches == npatches) {
461 470
 				/* All patches compiled. Start rendering. */
462 471
 				input_delete_callback(refresh_callback);
463  
-				next_as_time = t + AUTOSWITCH_PERIOD;
  472
+				update_next_as_time();
464 473
 				input_add_callback(event_callback);
465 474
 				mtk_cmd(appid, "l_status.set(-text \"Ready.\")");
466 475
 

0 notes on commit 8df771b

Please sign in to comment.
Something went wrong with that request. Please try again.