Exemple #1
0
// メインコマンドの処理
static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
    struct engine* engine = (struct engine*) app->userData;
    switch (cmd) {
    case APP_CMD_SAVE_STATE: // 状態保存を行うとき
        // 状態保存エリア取得
        engine->app->savedState = malloc(sizeof(struct saved_state));
        *((struct saved_state*) engine->app->savedState) = engine->state;
        engine->app->savedStateSize = sizeof(struct saved_state);
        break;
    case APP_CMD_INIT_WINDOW: // ウィンドウを初期化したとき
        if (engine->app->window != NULL) {
            // 画面を初期化する
            engine_init_display(engine);
            // 画面を描画する
            engine_draw_frame(engine);
        }
        break;

    case APP_CMD_TERM_WINDOW: // ウィンドウを破棄するとき
        // EGL情報を破棄する
        engine_term_display(engine);
        break;
    case APP_CMD_GAINED_FOCUS: // アプリがフォーカスを取得したとき
        enable_sensors(engine);
        break;

    case APP_CMD_LOST_FOCUS: // フォーカスが消失したとき
        disable_sensors(engine);
        // アニメーション停止
        engine->animating = 0;
        // 画面を表示
        engine_draw_frame(engine);
        break;
    }
}
Exemple #2
0
/* Checks for delays in communication from the Gumstix to Robostix 1
   as well as delays in communication from Robostix 2 to Robostix 1
*/
void check_receive_delay( )
{
    /* check if new motor signals have been received */
    if( !flag_new_signals )
    {
        /* DO NOT modify motor signals in shut-down mode! */
        if( !flag_shut_down )
        {
            if( motor_signals.front > 0 ||
                motor_signals.right > 0 ||
                motor_signals.rear  > 0 ||
                motor_signals.left  > 0 )
            {
                /* we're possibly airborne, so reduce
                   motor signals to force descending */
                motor_signals.front -= MOTOR_DEC;
                motor_signals.right -= MOTOR_DEC;
                motor_signals.rear  -= MOTOR_DEC;
                motor_signals.left  -= MOTOR_DEC;
            }
            else
            {
                /* we're possibly grounded, so keep
                   motor signals set to the minimum */
                motor_signals.front = 0;
                motor_signals.right = 0;
                motor_signals.rear  = 0;
                motor_signals.left  = 0;
            }

            /* set new motor signals */
            pwm_set_signals( &motor_signals );
        }

        /* reset Gumstix-to-Robostix-1 interface */
        serial_reset( );

        LED_ON( YELLOW );

///////////////////////////////////////////////////////////////////
        enable_sensors( 0 );
///////////////////////////////////////////////////////////////////
    }

    /* check if new sensor data have been received */
    if( !flag_new_sensors )
    {
        /* reset Robostix-2-to-Robostix-1 interface */
        //parallel_reset( );

        LED_ON( BLUE );
    }

    /* update sensor status */
    //enable_sensors( flag_new_signals );

    flag_check_delay = 0;
    flag_new_signals = 0;
    flag_new_sensors = 0;
}
Exemple #3
0
/* Processes COMM_SWITCH_STATE messages
*/
void process_state_switch( void )
{
    if( flag_shut_down )
    {
        /* clear shut-down flag */
        flag_shut_down = 0;

        LED_OFF( RED );
    }

///////////////////////////////////////////////////////////////////
    enable_sensors( 1 );
///////////////////////////////////////////////////////////////////
}
Exemple #4
0
/* Checks for delays in communication from Robostix 1 to Robostix 2
*/
void check_receive_delay( )
{
    /* check if a new request has been received */
    if( !flag_new_request )
    {
        /* disable specific sensors to save power */
        enable_sensors( 0 );

        /* reset Robostix-1-to-Robostix-2 interface */
        parallel_reset( );

        LED_ON( YELLOW );
    }

    flag_check_delay = 0;
    flag_new_request = 0;
}
void
buffer_drv_data_free (BufferDrvData *buffer_data)
{
	int i;

	if (buffer_data == NULL)
		return;

	enable_sensors (buffer_data->device, 0);
	g_clear_object (&buffer_data->device);

	disable_ring_buffer (buffer_data);

	g_free (buffer_data->trigger_name);

	for (i = 0; i < buffer_data->channels_count; i++)
		channel_info_free (buffer_data->channels[i]);
	g_free (buffer_data->channels);
}
Exemple #6
0
/* Processes COMM_SHUT_DOWN messages
*/
void process_shut_down( void )
{
    /* set motor signals to minimum */
    motor_signals.front = 0;
    motor_signals.right = 0;
    motor_signals.rear  = 0;
    motor_signals.left  = 0;

    /* set new motor signals */
    pwm_set_signals( &motor_signals );

    /* set shut-down flag */
    flag_shut_down = 1;

    LED_ON( RED );

///////////////////////////////////////////////////////////////////
    enable_sensors( 0 );
///////////////////////////////////////////////////////////////////
}
Exemple #7
0
/* Processes COMM_SENSOR_DATA messages
*/
void process_sensor_data( const uint8_t *data, uint8_t size )
{
    static uint8_t delay = 0;

    /* notify that a new request has been received */
    flag_new_request = 1;

    /* extract motor signals ID */
    javiator_data.id = (data[ size-3 ] << 8) | data[ size-2 ];

    /* update sensor status */
    enable_sensors( data[ size-1 ] );

    /* send sensor data to Robostix 1 */
    send_sensor_data( );

    if( ++delay % 10 == 0 )
    {
        LED_TOGGLE( YELLOW );
    }
}
BufferDrvData *
buffer_drv_data_new (GUdevDevice *device,
		     const char  *trigger_name)
{
	BufferDrvData *buffer_data;

	buffer_data = g_new0 (BufferDrvData, 1);
	buffer_data->dev_dir_name = g_udev_device_get_sysfs_path (device);
	buffer_data->trigger_name = g_strdup (trigger_name);
	buffer_data->device = g_object_ref (device);

	if (!iio_fixup_sampling_frequency (device) ||
	    !enable_sensors (device, 1) ||
	    !enable_trigger (buffer_data) ||
	    !enable_ring_buffer (buffer_data) ||
	    !build_channels (buffer_data)) {
		buffer_drv_data_free (buffer_data);
		return NULL;
	}

	return buffer_data;
}