Changeset bf2bdccad3f2bcca29d4b102005e6ff1b3a8ccc0
- Timestamp:
- 06/20/07 22:19:24
(1 year ago)
- Author:
- Jérome Decoodt <djc@videolan.org>
- git-committer:
- Jérome Decoodt <djc@videolan.org> 1182370764 +0000
- git-parent:
[22462d18862065dd0ac58f940b65beeb64ff50a2]
- git-author:
- Jérome Decoodt <djc@videolan.org> 1182370764 +0000
- Message:
Add rotate-deciangle for more precision in rotate
Add unimotion (http://members.optusnet.com.au/lbramsay/programs/unimotion.html)
to motion interface
Add a low band filter to the motion
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r9acaa4b |
rbf2bdcc |
|
| 174 | 174 | VLC_ADD_CFLAGS([libvlc vlc],[-x objective-c]) |
|---|
| 175 | 175 | VLC_ADD_LDFLAGS([vlc],[-undefined dynamic_lookup]) |
|---|
| | 176 | VLC_ADD_LDFLAGS([motion],[-framework IOKit -framework CoreFoundation]) |
|---|
| 176 | 177 | AC_ARG_ENABLE(macosx-defaults, |
|---|
| 177 | 178 | [ --enable-macosx-defaults Build the default configuration on Mac OS X (default enabled)]) |
|---|
| … | … | |
| 3330 | 3331 | ] ) |
|---|
| 3331 | 3332 | ]) |
|---|
| 3332 | | |
|---|
| 3333 | 3333 | |
|---|
| 3334 | 3334 | dnl |
|---|
| r147753f |
rbf2bdcc |
|
| 7 | 7 | SOURCES_lirc = lirc.c |
|---|
| 8 | 8 | SOURCES_rc = rc.c |
|---|
| 9 | | SOURCES_motion = motion.c |
|---|
| 10 | 9 | SOURCES_dbus = dbus.c dbus.h |
|---|
| | 10 | if HAVE_DARWIN |
|---|
| | 11 | motion_extra = unimotion.c unimotion.h |
|---|
| | 12 | else |
|---|
| | 13 | motion_extra = $(NULL) |
|---|
| | 14 | endif |
|---|
| | 15 | SOURCES_motion = \ |
|---|
| | 16 | motion.c \ |
|---|
| | 17 | $(motion_extra) \ |
|---|
| | 18 | $(NULL) |
|---|
| | 19 | |
|---|
| r610d26b |
rbf2bdcc |
|
| 2 | 2 | * motion.c: control VLC with laptop built-in motion sensors |
|---|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | | * Copyright (C) 2006 the VideoLAN team |
|---|
| | 4 | * Copyright (C) 2006 - 2007 the VideoLAN team |
|---|
| 5 | 5 | * $Id$ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Author: Sam Hocevar <sam@zoy.org> |
|---|
| | 8 | * Jérôme Decoodt <djc@videolan.org> (unimotion integration) |
|---|
| 8 | 9 | * |
|---|
| 9 | 10 | * This program is free software; you can redistribute it and/or modify |
|---|
| … | … | |
| 27 | 28 | #include <stdlib.h> /* malloc(), free() */ |
|---|
| 28 | 29 | #include <string.h> |
|---|
| | 30 | #include <math.h> |
|---|
| 29 | 31 | |
|---|
| 30 | 32 | #include <vlc/vlc.h> |
|---|
| … | … | |
| 36 | 38 | #endif |
|---|
| 37 | 39 | |
|---|
| | 40 | #ifdef __APPLE__ |
|---|
| | 41 | #include "unimotion.h" |
|---|
| | 42 | #endif |
|---|
| | 43 | |
|---|
| 38 | 44 | /***************************************************************************** |
|---|
| 39 | 45 | * intf_sys_t: description and status of interface |
|---|
| … | … | |
| 41 | 47 | struct intf_sys_t |
|---|
| 42 | 48 | { |
|---|
| 43 | | enum { NO_SENSOR, HDAPS_SENSOR, AMS_SENSOR } sensor; |
|---|
| | 49 | enum { NO_SENSOR, HDAPS_SENSOR, AMS_SENSOR, UNIMOTION_SENSOR } sensor; |
|---|
| | 50 | enum sms_hardware unimotion_hw; |
|---|
| 44 | 51 | |
|---|
| 45 | 52 | int i_calibrate; |
|---|
| … | … | |
| 111 | 118 | p_intf->p_sys->sensor = AMS_SENSOR; |
|---|
| 112 | 119 | } |
|---|
| | 120 | #ifdef __APPLE__ |
|---|
| | 121 | else if( p_intf->p_sys->unimotion_hw = detect_sms() ) |
|---|
| | 122 | p_intf->p_sys->sensor = UNIMOTION_SENSOR; |
|---|
| | 123 | #endif |
|---|
| 113 | 124 | else |
|---|
| 114 | 125 | { |
|---|
| … | … | |
| 137 | 148 | * RunIntf: main loop |
|---|
| 138 | 149 | *****************************************************************************/ |
|---|
| | 150 | #define FILTER_LENGTH 16 |
|---|
| | 151 | #define LOW_THRESHOLD 800 |
|---|
| | 152 | #define HIGH_THRESHOLD 1000 |
|---|
| 139 | 153 | static void RunIntf( intf_thread_t *p_intf ) |
|---|
| 140 | 154 | { |
|---|
| 141 | | int i_x, i_oldx = 0; |
|---|
| | 155 | int i_x, i_oldx = 0, i_sum = 0, i = 0; |
|---|
| | 156 | int p_oldx[FILTER_LENGTH]; |
|---|
| | 157 | memset( p_oldx, 0, FILTER_LENGTH * sizeof( int ) ); |
|---|
| 142 | 158 | |
|---|
| 143 | 159 | while( !intf_ShouldDie( p_intf ) ) |
|---|
| 144 | 160 | { |
|---|
| 145 | | #define LOW_THRESHOLD 80 |
|---|
| 146 | | #define HIGH_THRESHOLD 100 |
|---|
| 147 | 161 | vout_thread_t *p_vout; |
|---|
| 148 | 162 | const char *psz_filter, *psz_type; |
|---|
| … | … | |
| 153 | 167 | |
|---|
| 154 | 168 | i_x = GetOrientation( p_intf ); |
|---|
| | 169 | i_sum += i_x - p_oldx[i]; |
|---|
| | 170 | p_oldx[i++] = i_x; |
|---|
| | 171 | if( i == FILTER_LENGTH ) i = 0; |
|---|
| | 172 | i_x = i_sum / FILTER_LENGTH; |
|---|
| 155 | 173 | |
|---|
| 156 | 174 | if( p_intf->p_sys->b_use_rotate ) |
|---|
| … | … | |
| 163 | 181 | if( p_obj ) |
|---|
| 164 | 182 | { |
|---|
| 165 | | var_SetInteger( p_obj, "rotate-angle",((360+i_x/2)%360) ); |
|---|
| | 183 | var_SetInteger( p_obj, "rotate-deciangle", |
|---|
| | 184 | ((3600+i_x/2)%3600) ); |
|---|
| 166 | 185 | i_oldx = i_x; |
|---|
| 167 | 186 | vlc_object_release( p_obj ); |
|---|
| … | … | |
| 210 | 229 | } |
|---|
| 211 | 230 | } |
|---|
| 212 | | |
|---|
| 213 | | /***************************************************************************** |
|---|
| 214 | | * GetOrientation: get laptop orientation, range -180 / +180 |
|---|
| | 231 | #undef FILTER_LENGTH |
|---|
| | 232 | #undef LOW_THRESHOLD |
|---|
| | 233 | #undef HIGH_THRESHOLD |
|---|
| | 234 | |
|---|
| | 235 | /***************************************************************************** |
|---|
| | 236 | * GetOrientation: get laptop orientation, range -1800 / +1800 |
|---|
| 215 | 237 | *****************************************************************************/ |
|---|
| 216 | 238 | static int GetOrientation( intf_thread_t *p_intf ) |
|---|
| 217 | 239 | { |
|---|
| 218 | 240 | FILE *f; |
|---|
| 219 | | int i_x, i_y; |
|---|
| | 241 | int i_x, i_y, i_z; |
|---|
| 220 | 242 | |
|---|
| 221 | 243 | switch( p_intf->p_sys->sensor ) |
|---|
| … | … | |
| 232 | 254 | fclose( f ); |
|---|
| 233 | 255 | |
|---|
| 234 | | return i_x - p_intf->p_sys->i_calibrate; |
|---|
| | 256 | return ( i_x - p_intf->p_sys->i_calibrate ) * 10; |
|---|
| 235 | 257 | |
|---|
| 236 | 258 | case AMS_SENSOR: |
|---|
| … | … | |
| 244 | 266 | fclose( f ); |
|---|
| 245 | 267 | |
|---|
| 246 | | return - i_x * 3; /* FIXME: arbitrary */ |
|---|
| 247 | | |
|---|
| | 268 | return - i_x * 30; /* FIXME: arbitrary */ |
|---|
| | 269 | #ifdef __APPLE__ |
|---|
| | 270 | case UNIMOTION_SENSOR: |
|---|
| | 271 | if( read_sms_raw( p_intf->p_sys->unimotion_hw, &i_x, &i_y, &i_z ) ) |
|---|
| | 272 | { |
|---|
| | 273 | double d_norm = sqrt( i_x*i_x+i_z*i_z ); |
|---|
| | 274 | if( d_norm < 100 ) |
|---|
| | 275 | return 0; |
|---|
| | 276 | double d_x = i_x / d_norm; |
|---|
| | 277 | if( i_z > 0 ) |
|---|
| | 278 | return -asin(d_x)*3600/3.141; |
|---|
| | 279 | else |
|---|
| | 280 | return 3600 + asin(d_x)*3600/3.141; |
|---|
| | 281 | } |
|---|
| | 282 | #endif |
|---|
| | 283 | else |
|---|
| | 284 | return 0; |
|---|
| 248 | 285 | default: |
|---|
| 249 | 286 | return 0; |
|---|
| r610d26b |
rbf2bdcc |
|
| 44 | 44 | |
|---|
| 45 | 45 | static int RotateCallback( vlc_object_t *p_this, char const *psz_var, |
|---|
| | 46 | vlc_value_t oldval, vlc_value_t newval, |
|---|
| | 47 | void *p_data ); |
|---|
| | 48 | |
|---|
| | 49 | static int PreciseRotateCallback( vlc_object_t *p_this, char const *psz_var, |
|---|
| 46 | 50 | vlc_value_t oldval, vlc_value_t newval, |
|---|
| 47 | 51 | void *p_data ); |
|---|
| … | … | |
| 85 | 89 | static inline void cache_trigo( int i_angle, int *i_sin, int *i_cos ) |
|---|
| 86 | 90 | { |
|---|
| 87 | | const double f_angle = (((double)i_angle)*M_PI)/180.; |
|---|
| | 91 | const double f_angle = (((double)i_angle)*M_PI)/1800.; |
|---|
| 88 | 92 | *i_sin = (int)(sin( f_angle )*256.); |
|---|
| 89 | 93 | *i_cos = (int)(cos( f_angle )*256.); |
|---|
| … | … | |
| 111 | 115 | |
|---|
| 112 | 116 | p_sys->i_angle = var_CreateGetIntegerCommand( p_filter, |
|---|
| 113 | | FILTER_PREFIX "angle" ); |
|---|
| | 117 | FILTER_PREFIX "angle" ) * 10; |
|---|
| | 118 | var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "deciangle" ); |
|---|
| 114 | 119 | var_AddCallback( p_filter, FILTER_PREFIX "angle", RotateCallback, p_sys ); |
|---|
| | 120 | var_AddCallback( p_filter, FILTER_PREFIX "deciangle", PreciseRotateCallback, p_sys ); |
|---|
| 115 | 121 | |
|---|
| 116 | 122 | cache_trigo( p_sys->i_angle, &p_sys->i_sin, &p_sys->i_cos ); |
|---|
| … | … | |
| 221 | 227 | if( !strcmp( psz_var, "rotate-angle" ) ) |
|---|
| 222 | 228 | { |
|---|
| | 229 | p_sys->i_angle = newval.i_int*10; |
|---|
| | 230 | |
|---|
| | 231 | cache_trigo( p_sys->i_angle, &p_sys->i_sin, &p_sys->i_cos ); |
|---|
| | 232 | } |
|---|
| | 233 | return VLC_SUCCESS; |
|---|
| | 234 | } |
|---|
| | 235 | static int PreciseRotateCallback( vlc_object_t *p_this, char const *psz_var, |
|---|
| | 236 | vlc_value_t oldval, vlc_value_t newval, |
|---|
| | 237 | void *p_data ) |
|---|
| | 238 | { |
|---|
| | 239 | filter_sys_t *p_sys = (filter_sys_t *)p_data; |
|---|
| | 240 | |
|---|
| | 241 | if( !strcmp( psz_var, "rotate-deciangle" ) ) |
|---|
| | 242 | { |
|---|
| 223 | 243 | p_sys->i_angle = newval.i_int; |
|---|
| 224 | 244 | |
|---|