Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: m-labs/flickernoise
base: 4385882
...
head fork: m-labs/flickernoise
compare: 2776d11
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Sep 18, 2011
Xiangfu Liu ignore video patch when there is no camera connectted
Signed-off-by: Xiangfu Liu <xiangfu@sharism.cc>
f8e9008
Sébastien Bourdeauducq sbourdeauducq performance: skip advanced patches and patches using unavailable vide…
…o on patch switch
2776d11
Showing with 74 additions and 10 deletions.
  1. +14 −4 src/compiler.c
  2. +6 −1 src/compiler.h
  3. +54 −5 src/performance.c
18 src/compiler.c
View
@@ -161,11 +161,19 @@ static const char pfv_names[COMP_PFV_COUNT][FPVM_MAXSYMLEN] = {
"video_a"
};
-static int pfv_from_name(const char *name)
+static int pfv_from_name(struct compiler_sc *sc, const char *name)
{
int i;
- for(i=0;i<COMP_PFV_COUNT;i++)
- if(strcmp(pfv_names[i], name) == 0) return i;
+ for(i=0;i<COMP_PFV_COUNT;i++) {
+ if(strcmp(pfv_names[i], name) == 0) {
+ if(i >= pfv_dmx1 && i <= pfv_idmx8) sc->p->require |= REQUIRE_DMX;
+ if(i >= pfv_osc1 && i <= pfv_osc4) sc->p->require |= REQUIRE_OSC;
+ if(i >= pfv_midi1 && i <= pfv_midi8) sc->p->require |= REQUIRE_MIDI;
+ if(i == pfv_video_a) sc->p->require |= REQUIRE_VIDEO;
+ return i;
+ }
+ }
+
if(strcmp(name, "fDecay") == 0) return pfv_decay;
if(strcmp(name, "nWaveMode") == 0) return pfv_wave_mode;
if(strcmp(name, "fWaveScale") == 0) return pfv_wave_scale;
@@ -181,6 +189,8 @@ static void load_defaults(struct compiler_sc *sc)
{
int i;
+ sc->p->require = 0;
+
for(i=0;i<COMP_PFV_COUNT;i++)
sc->p->pfv_initial[i] = 0.0;
sc->p->pfv_initial[pfv_sx] = 1.0;
@@ -552,7 +562,7 @@ static bool process_top_assign(struct compiler_sc *sc, char *left, char *right)
while(*right == ' ') right++;
if(*right == 0) return true;
- pfv = pfv_from_name(left);
+ pfv = pfv_from_name(sc, left);
if(pfv >= 0) {
/* patch initial condition or global parameter */
set_initial(sc, pfv, atof(right));
7 src/compiler.h
View
@@ -192,7 +192,13 @@ enum {
COMP_PVV_COUNT /* must be last */
};
+#define REQUIRE_DMX (1 << 0)
+#define REQUIRE_OSC (1 << 1)
+#define REQUIRE_MIDI (1 << 2)
+#define REQUIRE_VIDEO (1 << 3)
+
struct patch {
+ unsigned int require; /* < bitmask: dmx, osc, midi, video */
/* per-frame */
float pfv_initial[COMP_PFV_COUNT]; /* < patch initial conditions */
int pfv_allocation[COMP_PFV_COUNT]; /* < where per-frame variables are mapped in PFPU regf, -1 if unmapped */
@@ -212,4 +218,3 @@ struct patch *patch_compile(const char *patch_code, report_message rmc);
void patch_free(struct patch *p);
#endif /* __COMPILER_H */
-
59 src/performance.c
View
@@ -20,9 +20,13 @@
#include <stdio.h>
#include <string.h>
#include <dirent.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <sys/stat.h>
+#include <sys/ioctl.h>
#include <mtklib.h>
#include <mtkeycodes.h>
+#include <bsp/milkymist_video.h>
#include "input.h"
#include "fb.h"
@@ -49,6 +53,7 @@ static struct patch_info patches[MAX_PATCHES];
static int simple_mode;
static int dt_mode;
static int as_mode;
+static int input_video;
static int add_patch(const char *filename)
{
@@ -354,12 +359,25 @@ static int keycode_to_index(int keycode)
static rtems_interval next_as_time;
#define AUTOSWITCH_PERIOD 3000
+static int suitable_for_simple(struct patch *p)
+{
+ int suitable;
+
+ suitable = 1;
+ if(p->require & REQUIRE_DMX) suitable = 0;
+ if(p->require & REQUIRE_OSC) suitable = 0;
+ if(p->require & REQUIRE_MIDI) suitable = 0;
+ if((p->require & REQUIRE_VIDEO) && !input_video) suitable = 0;
+ return suitable;
+}
+
static void event_callback(mtk_event *e, int count)
{
int i;
int index;
int next;
rtems_interval t;
+ int looped;
index = -1;
if(simple_mode) {
@@ -380,11 +398,14 @@ static void event_callback(mtk_event *e, int count)
}
}
if(next) {
- current_patch += next;
- if(current_patch == npatches)
- current_patch = 0;
- if(current_patch < 0)
- current_patch = npatches - 1;
+ looped = current_patch;
+ do {
+ current_patch += next;
+ if(current_patch == npatches)
+ current_patch = 0;
+ if(current_patch < 0)
+ current_patch = npatches - 1;
+ } while(!suitable_for_simple(patches[current_patch].p) && (looped != current_patch));
index = current_patch;
}
if(dt_mode && (index != -1))
@@ -430,6 +451,7 @@ static void stop_callback()
static void refresh_callback(mtk_event *e, int count)
{
rtems_interval t;
+ int looped;
t = rtems_clock_get_ticks_since_boot();
if(t >= next_update) {
@@ -441,6 +463,16 @@ static void refresh_callback(mtk_event *e, int count)
next_as_time = t + AUTOSWITCH_PERIOD;
input_add_callback(event_callback);
mtk_cmd(appid, "l_status.set(-text \"Ready.\")");
+
+ looped = current_patch;
+ while(!suitable_for_simple(patches[current_patch].p)) {
+ current_patch++;
+ if(current_patch == npatches)
+ current_patch = 0;
+ if(looped == current_patch)
+ break;
+ }
+
if(!guirender(appid, patches[current_patch].p, stop_callback))
stop_callback();
return;
@@ -468,6 +500,22 @@ void open_performance_window()
static rtems_id comp_task_id;
+static int check_input_video()
+{
+ int fd;
+ unsigned int status;
+
+ fd = open("/dev/video", O_RDWR);
+ if(fd == -1) {
+ perror("Unable to open video device");
+ return 0;
+ }
+ ioctl(fd, VIDEO_GET_SIGNAL, &status);
+ status &= 0x01;
+ close(fd);
+ return status;
+}
+
void start_performance(int simple, int dt, int as)
{
rtems_status_code sc;
@@ -478,6 +526,7 @@ void start_performance(int simple, int dt, int as)
simple_mode = simple;
dt_mode = dt;
as_mode = as;
+ input_video = check_input_video();
open_performance_window();
/* build patch list */

No commit comments for this range

Something went wrong with that request. Please try again.