Skip to content

Commit

Permalink
Use a separate print function
Browse files Browse the repository at this point in the history
  • Loading branch information
auvi authored and phillipjohnston committed Feb 18, 2019
1 parent b38155a commit be5551f
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions examples/c/circular_buffer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#define EXAMPLE_BUFFER_SIZE 10

void print_buffer_status(cbuf_handle_t cbuf);

int main(void)
{
uint8_t * buffer = malloc(EXAMPLE_BUFFER_SIZE * sizeof(uint8_t));
Expand All @@ -17,10 +19,8 @@ int main(void)

cbuf_handle_t cbuf = circular_buf_init(buffer, EXAMPLE_BUFFER_SIZE);

printf("Buffer initialized. Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
printf("Buffer initialized. ");
print_buffer_status(cbuf);

printf("\n******\nAdding %d values\n", EXAMPLE_BUFFER_SIZE - 1);
for(uint8_t i = 0; i < (EXAMPLE_BUFFER_SIZE - 1); i++)
Expand All @@ -29,10 +29,7 @@ int main(void)
printf("Added %u, Size now: %zu\n", i, circular_buf_size(cbuf));
}

printf("Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
print_buffer_status(cbuf);

printf("\n******\nAdding %d values\n", EXAMPLE_BUFFER_SIZE);
for(uint8_t i = 0; i < EXAMPLE_BUFFER_SIZE; i++)
Expand All @@ -41,10 +38,7 @@ int main(void)
printf("Added %u, Size now: %zu\n", i, circular_buf_size(cbuf));
}

printf("Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
print_buffer_status(cbuf);

printf("\n******\nReading back values: ");
while(!circular_buf_empty(cbuf))
Expand All @@ -55,10 +49,7 @@ int main(void)
}
printf("\n");

printf("Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
print_buffer_status(cbuf);

printf("\n******\nAdding %d values\n", EXAMPLE_BUFFER_SIZE + 5);
for(uint8_t i = 0; i < EXAMPLE_BUFFER_SIZE + 5; i++)
Expand All @@ -67,10 +58,7 @@ int main(void)
printf("Added %u, Size now: %zu\n", i, circular_buf_size(cbuf));
}

printf("Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
print_buffer_status(cbuf);

printf("\n******\nReading back values: ");
while(!circular_buf_empty(cbuf))
Expand All @@ -87,10 +75,7 @@ int main(void)
circular_buf_put2(cbuf, i);
}

printf("Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
print_buffer_status(cbuf);

printf("\n******\nReading back values: ");
while(!circular_buf_empty(cbuf))
Expand All @@ -106,3 +91,11 @@ int main(void)

return 0;
}

void print_buffer_status(cbuf_handle_t cbuf)
{
printf("Full: %d, empty: %d, size: %zu\n",
circular_buf_full(cbuf),
circular_buf_empty(cbuf),
circular_buf_size(cbuf));
}

0 comments on commit be5551f

Please sign in to comment.