static GObject * impl_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { RBGenericPlayerSource *source; RBGenericPlayerSourcePrivate *priv; GMount *mount; char *mount_name; RBShell *shell; GFile *root; GFileInfo *info; GError *error = NULL; source = RB_GENERIC_PLAYER_SOURCE (G_OBJECT_CLASS (rb_generic_player_source_parent_class)-> constructor (type, n_construct_properties, construct_properties)); priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source); g_object_get (source, "shell", &shell, NULL); g_object_get (shell, "db", &priv->db, NULL); priv->import_errors = rb_import_errors_source_new (shell, priv->error_type); g_object_unref (shell); g_object_get (source, "mount", &mount, NULL); root = g_mount_get_root (mount); mount_name = g_mount_get_name (mount); info = g_file_query_filesystem_info (root, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, &error); if (error != NULL) { rb_debug ("error querying filesystem info for %s: %s", mount_name, error->message); g_error_free (error); priv->read_only = FALSE; } else { priv->read_only = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY); g_object_unref (info); } g_free (mount_name); g_object_unref (root); g_object_unref (mount); priv->folder_depth = -1; /* 0 is a possible value, I guess */ priv->playlist_format_unknown = TRUE; get_device_info (source); load_songs (source); return G_OBJECT (source); }
static gboolean ensure_loaded (RBGenericPlayerSource *source) { RBGenericPlayerSourcePrivate *priv = GET_PRIVATE (source); RBSourceLoadStatus status; if (priv->loaded) { g_object_get (source, "load-status", &status, NULL); return (status == RB_SOURCE_LOAD_STATUS_LOADED); } else { priv->loaded = TRUE; rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (source)); load_songs (source); return FALSE; } }
/** * * Function to initialize the timers, registers, etc. for the ir, ping, servo, lcd */ void initialize() { // Initialize Serial Communication serial_init(57600); // initialize timers for use by ping sensor and servo timer3_init(); timer_init(); // initialize ADC for use by IR sensor ADC_init(); // Initialize Open Interface and sensor data sensor_data = oi_alloc(); oi_init(sensor_data); // initialize LCD lcd_init(); load_songs(); }
static GObject * impl_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { RBGenericPlayerSource *source; RBGenericPlayerSourcePrivate *priv; GMount *mount; char **playlist_formats; char *mount_name; RBShell *shell; GFile *root; GFileInfo *info; GError *error = NULL; source = RB_GENERIC_PLAYER_SOURCE (G_OBJECT_CLASS (rb_generic_player_source_parent_class)-> constructor (type, n_construct_properties, construct_properties)); priv = GENERIC_PLAYER_SOURCE_GET_PRIVATE (source); g_object_get (source, "shell", &shell, NULL); g_object_get (shell, "db", &priv->db, NULL); priv->import_errors = rb_import_errors_source_new (shell, priv->error_type); g_object_unref (shell); g_object_get (source, "mount", &mount, NULL); root = g_mount_get_root (mount); mount_name = g_mount_get_name (mount); info = g_file_query_filesystem_info (root, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, NULL, &error); if (error != NULL) { rb_debug ("error querying filesystem info for %s: %s", mount_name, error->message); g_error_free (error); priv->read_only = FALSE; } else { priv->read_only = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY); g_object_unref (info); } g_free (mount_name); g_object_unref (root); g_object_unref (mount); g_object_get (priv->device_info, "playlist-formats", &playlist_formats, NULL); if (playlist_formats != NULL && g_strv_length (playlist_formats) > 0) { RhythmDBEntryType entry_type; g_object_get (source, "entry-type", &entry_type, NULL); entry_type->has_playlists = TRUE; g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE, entry_type); } g_strfreev (playlist_formats); load_songs (source); return G_OBJECT (source); }
/** * Used to control the robot. * Receive and transmit data, measure the distance from object and navigate to the retrieval zone. **/ int main(void) { lcd_init(); timer3_init(); timer_init(); ADC_init(); USART_Init(); oi_t *sensor_data = oi_alloc(); oi_init(sensor_data);//should turn the iRobot Create's power LED yellow lcd_init(); serial_puts("Start"); //USART_Transmit(13); //USART_Transmit(10); int TempAngle[4] = {0,0,0,0}; int TempIR[4] = {0,0,0,0}; int pos[4] = {0,0,0,0}; int AddIR[4] = {0,0,0,0}; int count[4] = {0,0,0,0}; int found = 0; int x1 = 0; int x2 = 0; int x3 = 0; int x4 = 0; unsigned angle = 0; unsigned char IR = 0; volatile int i=0; volatile int x = 0; char command; char display[100]; char display1[20]; char display2[20]; char display3[20]; char display4[20]; char display5[100]; char display6[100]; while (1) { command = USART_Recieve(); USART_Transmit(command); //USART_Transmit(13); //USART_Transmit(10); if (command == '1') { found = 0; angle = 0; int t; int TempAngle[6] = {0, 0,0,0,0,0}; int TempIR[6] = {0, 0,0,0,0,0}; int pos[6] = {0, 0,0,0,0,0}; int AddIR[6] = {0, 0, 0,0,0,0}; int count[6] = {0, 0, 0,0,0,0}; for (angle = 0;angle < 181;angle++) { move_servo(angle); wait_ms(20); IR = 0; IR = 42800*pow(ADC_read(2),-1.23); sprintf(display6, "Angle: %5d IR: %5d",angle,IR); serial_puts(display6); if (IR < 80) { TempAngle[found]++; count[found]++; AddIR[found]+=IR; TempIR[found]=AddIR[found]/count[found]; } else { if(TempAngle[found] < 5) { TempAngle[found] = 0; } else { pos[found] = angle- TempAngle[found]/2; if (TempIR[found]*TempAngle[found]< 460) { USART_Transmit(13); USART_Transmit(10); for (int i = 0;i<strlen(s8);i++) { USART_Transmit(s8[i]); } sprintf(display5, "object position: %5d",pos[found]); serial_puts(display5); } sprintf(display, "object position: %5d IR: %5d object size: %5d",pos[found],TempIR[found],TempAngle[found]); serial_puts(display); USART_Transmit(13); USART_Transmit(10); found++; } } } OCR3B = 1000-1; //return to 0 degree } if (command == 'w') { move_forward(sensor_data,20); } if (command == 's') { move_backforward(sensor_data,20); } if (command == 'a') { turn_clockwise(sensor_data,82); } if (command == 'd') { turn_counterclockwise(sensor_data,82); } if (command == 'q') { turn_clockwise(sensor_data,38); } if (command == 'e') { turn_counterclockwise(sensor_data, 38); } if (command == '8') { move_forward(sensor_data,5); } if (command == '5') { move_backforward(sensor_data,5); } if (command == 'p') { oi_t* sensor = oi_alloc(); oi_init(sensor); load_songs(); oi_play_song(songings); } if(command == 'k') { oi_update(sensor_data); x1 = sensor_data->cliff_left_signal; x2 = sensor_data->cliff_right_signal; x3 = sensor_data->cliff_frontleft_signal; x4 = sensor_data->cliff_frontright_signal; sprintf (display1, "left = %d",x1); sprintf (display2, "right = %d",x2); sprintf (display3, "front left = %d",x3); sprintf (display4, "front right = %d",x4); USART_Transmit(13); USART_Transmit(10); serial_puts(display1); serial_puts(display3); serial_puts(display4); serial_puts(display2); if (x1>500||x2>500||x3>500||x4>500) { USART_Transmit(13); USART_Transmit(10); for (int i=0;i<strlen(s6);i++) { USART_Transmit(s6[i]); } } } } }