Skip to content

Instantly share code, notes, and snippets.

@rcombs
Created April 13, 2013 23:09
Show Gist options
  • Save rcombs/5380543 to your computer and use it in GitHub Desktop.
Save rcombs/5380543 to your computer and use it in GitHub Desktop.
// In a .h:
typedef struct {
unsigned short number;
unsigned short start_time;
unsigned short end_time;
char[32] name;
}period;
// Outside any function:
period *periods;
unsigned short period_count = 0;
// Later, in an init function:
ResHandle config_file = resource_get_handle(RESOURCE_ID_CLASS_LIST);
size_t config_size = resource_size(config_file);
period_count = config_size / 38; // 38 = size of each period record
char[config_size] config_buf;
resource_load(config_file, config_buf, config_size);
uint8_t period_size = sizeof(period);
periods = malloc(period_size * period_count);
for(uint16_t i = 0; i < period_count; i++){
period periods[i];
memcpy(periods[i].number, &config_buf[i * period_size], 2);
memcpy(periods[i].start_time, &config_buf[i * period_size + 2], 2);
memcpy(periods[i].end_time, &config_buf[i * period_size + 4], 2);
memcpy(periods[i].end_time, &config_buf[i * period_size + 6], 32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment