Skip to content

Commit

Permalink
Convert the samples rates array to be NULL terminated.
Browse files Browse the repository at this point in the history
Convert the samples rates array to be NULL terminated so it is possible to pass
the struct as return value and iterate of the struct in a easy fashion.
  • Loading branch information
keesj committed Dec 29, 2009
1 parent e3b13a5 commit 3c79253
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
11 changes: 4 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ void short_usage(const char *message, ...)

void full_usage()
{
int i;
struct slogic_sample_rate *sample_rates;
size_t n_sample_rates;

slogic_available_sample_rates(&sample_rates, &n_sample_rates);
const struct slogic_sample_rate * sample_iterator = slogic_get_sample_rates();

fprintf(stderr, "usage: %s -f <output file> -r <sample rate> [-n <number of samples>]\n", me);
fprintf(stderr, "\n");
Expand All @@ -50,8 +46,9 @@ void full_usage()
fprintf(stderr, " -h: This help message.\n");
fprintf(stderr, " -r: Select sample rate for the Logic.\n");
fprintf(stderr, " Available sample rates:\n");
for (i = 0; i < n_sample_rates; i++, sample_rates++) {
fprintf(stderr, " o %s\n", sample_rates->text);
while (sample_iterator->text != NULL){
fprintf(stderr, " o %s\n", sample_iterator->text);
sample_iterator++;
}
fprintf(stderr, "\n");
fprintf(stderr, "Advanced options:\n");
Expand Down
35 changes: 16 additions & 19 deletions slogic.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@
#define USB_VENDOR_ID 0x0925
#define USB_PRODUCT_ID 0x3881

struct slogic_handle {
/* pointer to the usb handle */
libusb_device_handle *device_handle;
libusb_context *context;
size_t transfer_buffer_size;
int n_transfer_buffers;
unsigned int transfer_timeout;
FILE *debug_file;
};

/*
* Sample Rates
*/
Expand All @@ -50,27 +40,34 @@ struct slogic_sample_rate sample_rates[] = {
{95, "500kHz", 500000},
{191, "250kHz", 250000},
{239, "200kHz", 200000},
{0,NULL,0},
};

struct slogic_handle {
/* pointer to the usb handle */
libusb_device_handle *device_handle;
libusb_context *context;
size_t transfer_buffer_size;
int n_transfer_buffers;
unsigned int transfer_timeout;
FILE *debug_file;
};

static const int n_sample_rates = sizeof(sample_rates) / sizeof(struct slogic_sample_rate);

void slogic_available_sample_rates(struct slogic_sample_rate **sample_rates_out, size_t * size)
struct slogic_sample_rate *slogic_get_sample_rates()
{
*sample_rates_out = sample_rates;
*size = n_sample_rates;
return sample_rates;
}

struct slogic_sample_rate *slogic_parse_sample_rate(const char *str)
{
int i;

for (i = 0; i < n_sample_rates; i++) {
struct slogic_sample_rate *sample_rate = &sample_rates[i];
struct slogic_sample_rate *sample_rate = slogic_get_sample_rates();
while (sample_rate->text != NULL){
sample_rate++;
if (strcmp(sample_rate->text, str) == 0) {
return sample_rate;
}
}

return NULL;
}

Expand Down
4 changes: 3 additions & 1 deletion slogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ enum slogic_recording_state {
UNKNOWN = 100,
};

void slogic_available_sample_rates(struct slogic_sample_rate **sample_rates_out, size_t * size);
/* returns an array of available sample rates. The array is terminates with an entry having a
0 sample_delay , a NULL text and a 0 samples_per_second */
struct slogic_sample_rate *slogic_get_sample_rates();
struct slogic_sample_rate *slogic_parse_sample_rate(const char *str);

/*
Expand Down

0 comments on commit 3c79253

Please sign in to comment.