static int camera_get_config (Camera *camera, CameraWidget **window, GPContext *context) { CameraWidget *child; GP_DEBUG ("*** camera_get_config"); gp_widget_new (GP_WIDGET_WINDOW, _("Picture Frame Configuration"), window); gp_widget_new (GP_WIDGET_TOGGLE, _("Synchronize frame data and time with PC"), &child); gp_widget_set_value (child, &camera->pl->syncdatetime); gp_widget_append (*window, child); gp_widget_new (GP_WIDGET_RADIO, _("Orientation"), &child); gp_widget_add_choice (child, orientation_to_string (0)); gp_widget_add_choice (child, orientation_to_string (1)); gp_widget_add_choice (child, orientation_to_string (2)); gp_widget_set_value (child, orientation_to_string (camera->pl->orientation)); gp_widget_append (*window, child); return GP_OK; }
static void accel_changed_func (SensorDriver *driver, gpointer readings_data, gpointer user_data) { SensorData *data = user_data; AccelReadings *readings = (AccelReadings *) readings_data; OrientationUp orientation = data->previous_orientation; //FIXME handle errors g_debug ("Accel sent by driver (quirk applied): %d, %d, %d", readings->accel_x, readings->accel_y, readings->accel_z); orientation = orientation_calc (data->previous_orientation, readings->accel_x, readings->accel_y, readings->accel_z); data->accel_x = readings->accel_x; data->accel_y = readings->accel_y; data->accel_z = readings->accel_z; if (data->previous_orientation != orientation) { OrientationUp tmp; tmp = data->previous_orientation; data->previous_orientation = orientation; send_dbus_event (data, PROP_ACCELEROMETER_ORIENTATION); g_debug ("Emitted orientation changed: from %s to %s", orientation_to_string (tmp), orientation_to_string (data->previous_orientation)); } }
void Player_update(Entity *self, ...) { // The player's update function should be passed a list of key states va_list keys; va_start(keys, self); bool up_pressed = va_arg(keys, int); // The first should be the up key bool right_pressed = va_arg(keys, int); // The second should be right bool down_pressed = va_arg(keys, int); // Third is down bool left_pressed = va_arg(keys, int); // Fourth is left bool x_pressed = va_arg(keys, int); // And fifth is x va_end(keys); if (x_pressed) { if (self->animationProgress == 0) { strcpy(self->currentAnimation, "swing"); } } if (self->animationProgress < 3 && strcmp(self->currentAnimation, "swing") == 0) { char temp[255]; strcpy(temp, orientation_to_string(self->orientation)); strcat(temp, "_swing_%i"); sprintf(self->currentFrame, temp, self->animationProgress); self->animationProgress += 1; return; } else { strcpy(self->currentAnimation, "idle"); strcpy(self->currentFrame, orientation_to_string(self->orientation)); strcat(self->currentFrame, "_idle"); self->animationProgress = 0; } if (up_pressed) { self->moveForward(self); } if (right_pressed) { self->turn(self, RIGHT); strcpy(self->currentFrame, orientation_to_string(self->orientation)); strcat(self->currentFrame, "_idle"); } if (down_pressed) { self->moveBackward(self); } if (left_pressed) { self->turn(self, LEFT); strcpy(self->currentFrame, orientation_to_string(self->orientation)); strcat(self->currentFrame, "_idle"); } //printw("orientation: %s", self->currentFrame); }
static GVariant * handle_get_property (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { SensorData *data = user_data; g_assert (data->connection); if (g_strcmp0 (property_name, "HasAccelerometer") == 0) return g_variant_new_boolean (driver_type_exists (data, DRIVER_TYPE_ACCEL)); if (g_strcmp0 (property_name, "AccelerometerOrientation") == 0) return g_variant_new_string (orientation_to_string (data->previous_orientation)); if (g_strcmp0 (property_name, "HasAmbientLight") == 0) return g_variant_new_boolean (driver_type_exists (data, DRIVER_TYPE_LIGHT)); if (g_strcmp0 (property_name, "LightLevelUnit") == 0) return g_variant_new_string (data->uses_lux ? "lux" : "vendor"); if (g_strcmp0 (property_name, "LightLevel") == 0) return g_variant_new_double (data->previous_level); return NULL; }
static int camera_exit (Camera *camera, GPContext *context) { char buf[2]; if (camera->pl != NULL) { buf[0] = '0' + camera->pl->syncdatetime; buf[1] = 0; gp_setting_set ("st2205", "syncdatetime", buf); gp_setting_set ("st2205", "orientation", orientation_to_string (camera->pl->orientation)); #ifdef HAVE_ICONV if (camera->pl->cd != (iconv_t) -1) iconv_close (camera->pl->cd); #endif st2205_close (camera); free (camera->pl); camera->pl = NULL; } return GP_OK; }
static void send_dbus_event (SensorData *data, PropertiesMask mask) { GVariantBuilder props_builder; GVariant *props_changed = NULL; g_assert (data->connection); if (mask == 0) return; g_assert ((mask & PROP_ALL) == 0 || (mask & PROP_ALL_COMPASS) == 0); g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}")); if (mask & PROP_HAS_ACCELEROMETER) { gboolean has_accel; has_accel = driver_type_exists (data, DRIVER_TYPE_ACCEL); g_variant_builder_add (&props_builder, "{sv}", "HasAccelerometer", g_variant_new_boolean (has_accel)); /* Send the orientation when the device appears */ if (has_accel) mask |= PROP_ACCELEROMETER_ORIENTATION; else data->previous_orientation = ORIENTATION_UNDEFINED; } if (mask & PROP_ACCELEROMETER_ORIENTATION) { g_variant_builder_add (&props_builder, "{sv}", "AccelerometerOrientation", g_variant_new_string (orientation_to_string (data->previous_orientation))); } if (mask & PROP_HAS_AMBIENT_LIGHT) { gboolean has_als; has_als = driver_type_exists (data, DRIVER_TYPE_LIGHT); g_variant_builder_add (&props_builder, "{sv}", "HasAmbientLight", g_variant_new_boolean (has_als)); /* Send the light level when the device appears */ if (has_als) mask |= PROP_LIGHT_LEVEL; } if (mask & PROP_LIGHT_LEVEL) { g_variant_builder_add (&props_builder, "{sv}", "LightLevelUnit", g_variant_new_string (data->uses_lux ? "lux" : "vendor")); g_variant_builder_add (&props_builder, "{sv}", "LightLevel", g_variant_new_double (data->previous_level)); } if (mask & PROP_HAS_COMPASS) { gboolean has_compass; has_compass = driver_type_exists (data, DRIVER_TYPE_COMPASS); g_variant_builder_add (&props_builder, "{sv}", "HasCompass", g_variant_new_boolean (has_compass)); /* Send the heading when the device appears */ if (has_compass) mask |= PROP_COMPASS_HEADING; } if (mask & PROP_COMPASS_HEADING) { g_variant_builder_add (&props_builder, "{sv}", "CompassHeading", g_variant_new_double (data->previous_heading)); } props_changed = g_variant_new ("(s@a{sv}@as)", (mask & PROP_ALL) ? SENSOR_PROXY_IFACE_NAME : SENSOR_PROXY_COMPASS_IFACE_NAME, g_variant_builder_end (&props_builder), g_variant_new_strv (NULL, 0)); g_dbus_connection_emit_signal (data->connection, NULL, (mask & PROP_ALL) ? SENSOR_PROXY_DBUS_PATH : SENSOR_PROXY_COMPASS_DBUS_PATH, "org.freedesktop.DBus.Properties", "PropertiesChanged", props_changed, NULL); }