Skip to content

Commit 35017a5

Browse files
committed
Made printing debug messages optional
Should probably propogate the flag from the build type, but since I'm currently running release builds but may or may not want prints this is more flexible, at least for now.
1 parent 334da74 commit 35017a5

File tree

7 files changed

+125
-103
lines changed

7 files changed

+125
-103
lines changed

animation.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <string.h>
55
#include <math.h>
66

7+
#include "matrix_display.h"
8+
79
#include "animation.h"
810

911
animation::animation(framebuffer& f) : fb(f)
@@ -161,12 +163,14 @@ void animation::render_notification(void)
161163

162164
void animation::new_weather_data(weather_data_t *weather_data)
163165
{
166+
DEBUG_printf("Got new weather data\n");
164167
weather_state.data = *weather_data;
165168
weather_state.framestamp = frame;
166169
}
167170

168171
void animation::new_media_player_data(media_player_data_t *media_player_data)
169172
{
173+
DEBUG_printf("Got new media player data\n");
170174
snprintf(media_player_state.message, sizeof(media_player_state.message),
171175
"'%s' by '%s' on '%s'",
172176
media_player_data->media_title, media_player_data->media_artist,
@@ -177,7 +181,7 @@ void animation::new_media_player_data(media_player_data_t *media_player_data)
177181

178182
void animation::new_calendar_data(calendar_data_t *calendar_data)
179183
{
180-
printf("Got new calendar data\n");
184+
DEBUG_printf("Got new calendar data\n");
181185
calendar_state.data = *calendar_data;
182186
calendar_state.message_pixel_height = 0;
183187
calendar_state.framestamp = frame;
@@ -187,7 +191,7 @@ void animation::new_calendar_data(calendar_data_t *calendar_data)
187191

188192
void animation::new_scroller_data(scroller_data_t *scroller_data)
189193
{
190-
printf("Got new scroller data\n");
194+
DEBUG_printf("Got new scroller data\n");
191195
scroller_state.data = *scroller_data;
192196
for (int i = 0; i < scroller_state.data.array_size; i++) {
193197
special_replacement(scroller_state.data.text[i], "-UP-", CHAR_UP_ARROW);
@@ -197,13 +201,14 @@ void animation::new_scroller_data(scroller_data_t *scroller_data)
197201

198202
void animation::new_transport_data(transport_data_t *transport_data)
199203
{
200-
printf("Got new transport data\n");
204+
DEBUG_printf("Got new transport data\n");
201205
transport_state.data = *transport_data;
202206
transport_state.framestamp = frame;
203207
}
204208

205209
void animation::new_notification(notification_t *notification)
206210
{
211+
DEBUG_printf("Got new notification data\n");
207212
notification_state.data = *notification;
208213
notification_state.framestamp = frame;
209214
notification_state.pixel_length = fb.string_length(medium_font, notification->text);
@@ -261,7 +266,7 @@ void animation::new_ds3231(ds3231_t *ds3231)
261266
strncpy(ds3231_state.date, "XXXX", sizeof(ds3231_state.date));
262267
}
263268

264-
printf("New Time: %s Date: %s\n", ds3231_state.time_colons, ds3231_state.date);
269+
DEBUG_printf("New Time: %s Date: %s\n", ds3231_state.time_colons, ds3231_state.date);
265270
}
266271

267272
void animation::update_configuration(configuration_t *config)
@@ -305,7 +310,7 @@ void animation::update_configuration(configuration_t *config)
305310

306311
void animation::change_page(page_t new_page)
307312
{
308-
printf("changing to new page %d\n", new_page);
313+
DEBUG_printf("changing to new page %d\n", new_page);
309314
page_framestamp = frame;
310315

311316
page = new_page;
@@ -572,7 +577,7 @@ void animation::update_scroller_message(void)
572577
scroller_state.message
573578
);
574579

575-
printf("update_scroller_message: message is: %s\n", scroller_state.message);
580+
DEBUG_printf("update_scroller_message: message is: %s\n", scroller_state.message);
576581

577582
scroller_state.message_offset = 0;
578583
scroller_state.framestamp = frame;

buzzer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <task.h>
1010
#include <queue.h>
1111

12+
#include "matrix_display.h"
13+
1214
#include "messages.h"
1315

1416
#define BUZZER_PIN 27
@@ -19,7 +21,7 @@ void buzzer_task(void *dummy)
1921
{
2022
#if FREE_RTOS_KERNEL_SMP
2123
vTaskCoreAffinitySet(NULL, 1 << 0);
22-
printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
24+
DEBUG_printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
2325
#endif
2426

2527
gpio_set_function(BUZZER_PIN, GPIO_FUNC_PWM);
@@ -32,7 +34,7 @@ void buzzer_task(void *dummy)
3234
message_buzzer_t buzzer = {};
3335

3436
if (xQueueReceive(buzzer_queue, &buzzer, 1000 / portTICK_PERIOD_MS) == pdTRUE) {
35-
printf("Buzz buzz buzz\n");
37+
DEBUG_printf("Buzz buzz buzz\n");
3638

3739
switch (buzzer.message_type) {
3840
case MESSAGE_BUZZER_PLAY:
@@ -67,13 +69,13 @@ void buzzer_task(void *dummy)
6769
break;
6870

6971
default:
70-
printf("Bad buzzer play type %d\n", buzzer.play_type);
72+
DEBUG_printf("Bad buzzer play type %d\n", buzzer.play_type);
7173
break;
7274
}
7375
break;
7476

7577
default:
76-
printf("Bad buzzer message type %d\n", buzzer.message_type);
78+
DEBUG_printf("Bad buzzer message type %d\n", buzzer.message_type);
7779
break;
7880
}
7981
}

framebuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int framebuffer::print_char(font_t *font, int x, int y, char c, rgb_t rgb, bool
6464
{
6565
// Basic sanity please
6666
if (!(c >= 0x20 && c <= 0x7f || c == CHAR_UP_ARROW || c == CHAR_DOWN_ARROW)) {
67-
// printf("Bad character in framebuffer::printchar(): %02x\n", (int) c);
67+
// DEBUG_printf("Bad character in framebuffer::printchar(): %02x\n", (int) c);
6868
return 0;
6969
}
7070

i2c.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <task.h>
1010
#include <queue.h>
1111

12+
#include "matrix_display.h"
13+
1214
#include "messages.h"
1315

1416
#define PICO_I2C_SDA_PIN 20
@@ -42,7 +44,7 @@ void i2c_task(void *dummy)
4244
{
4345
#if FREE_RTOS_KERNEL_SMP
4446
vTaskCoreAffinitySet(NULL, 1 << 0);
45-
printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
47+
DEBUG_printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
4648
#endif
4749

4850
static message_anim_t message_anim = {
@@ -63,7 +65,7 @@ void i2c_task(void *dummy)
6365
bool requested_run = false;
6466

6567
if (!(configure_bme680())) {
66-
printf("BME680: Configure failed\n");
68+
DEBUG_printf("BME680: Configure failed\n");
6769
}
6870
#endif
6971

@@ -76,19 +78,19 @@ void i2c_task(void *dummy)
7678
// See if we are at the top of the next second
7779
if (memcmp(&message_anim.ds3231, &old_ds3231, sizeof(ds3231_t)) != 0) {
7880
if (xQueueSend(animate_queue, &message_anim, 10) != pdTRUE) {
79-
printf("Could not send clock data; dropping\n");
81+
DEBUG_printf("Could not send clock data; dropping\n");
8082
}
8183

8284
if (climate_count == CLIMATE_SEND_INTERVAL) {
8385
#if BME680_PRESENT
8486
if (requested_run) {
8587
if (!(receive_data())) {
86-
printf("BME680: Failed to recieve data\n");
88+
DEBUG_printf("BME680: Failed to recieve data\n");
8789
}
8890
got_data = true;
8991
}
9092
if (!(request_run())) {
91-
printf("BME680: Failed to request run\n");
93+
DEBUG_printf("BME680: Failed to request run\n");
9294
}
9395
requested_run = true;
9496

@@ -98,14 +100,14 @@ void i2c_task(void *dummy)
98100
message_mqtt.climate.humidity = get_humidity();
99101

100102
if (xQueueSend(mqtt_queue, &message_mqtt, 10) != pdTRUE) {
101-
printf("Could not send climate data; dropping\n");
103+
DEBUG_printf("Could not send climate data; dropping\n");
102104
}
103105
}
104106
#else
105107
message_mqtt.climate.temperature = get_temperature();
106108

107109
if (xQueueSend(mqtt_queue, &message_mqtt, 10) != pdTRUE) {
108-
printf("Could not send climate data; dropping\n");
110+
DEBUG_printf("Could not send climate data; dropping\n");
109111
}
110112

111113
#endif
@@ -121,7 +123,7 @@ void i2c_task(void *dummy)
121123
ds3231_t set_ds3231 = {};
122124

123125
if (xQueueReceive(i2c_queue, &set_ds3231, 0) == pdTRUE) {
124-
printf("Clock set\n");
126+
DEBUG_printf("Clock set\n");
125127
set_ds3231_time(set_ds3231.datetime_buffer);
126128
}
127129

main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <queue.h>
1313
#include <semphr.h>
1414

15+
#include "matrix_display.h"
16+
1517
#include "animation.h"
1618

1719
#include "hub75.pio.h"
@@ -47,7 +49,7 @@ int main(void)
4749
{
4850
stdio_init_all();
4951

50-
printf("Hello, matrix here\n");
52+
DEBUG_printf("Hello, matrix here\n");
5153

5254
srand(0);
5355

@@ -78,7 +80,7 @@ void animate_task(void *dummy)
7880
{
7981
#if FREE_RTOS_KERNEL_SMP
8082
vTaskCoreAffinitySet(NULL, 1 << 0);
81-
printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
83+
DEBUG_printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
8284
#endif
8385

8486
message_anim_t message;
@@ -89,7 +91,7 @@ void animate_task(void *dummy)
8991
while (1)
9092
{
9193
while (xQueueReceive(animate_queue, &message, 0) == pdTRUE) {
92-
printf("New message, type: %d\n", message.message_type);
94+
DEBUG_printf("New message, type: %d\n", message.message_type);
9395

9496
switch (message.message_type) {
9597
case MESSAGE_ANIM_WEATHER:
@@ -137,7 +139,7 @@ void animate_task(void *dummy)
137139
break;
138140

139141
default:
140-
printf("Unknown message type: %d\n", message.message_type);
142+
DEBUG_printf("Unknown message type: %d\n", message.message_type);
141143
break;
142144
}
143145
}
@@ -158,7 +160,7 @@ void matrix_task(void *dummy)
158160
{
159161
#if FREE_RTOS_KERNEL_SMP
160162
vTaskCoreAffinitySet(NULL, 1 << 1);
161-
printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
163+
DEBUG_printf("%s: core%u\n", pcTaskGetName(NULL), get_core_num());
162164
#endif
163165

164166
#if SPI_TO_FPGA
@@ -179,7 +181,7 @@ void matrix_task(void *dummy)
179181

180182
const uint dma_tx = dma_claim_unused_channel(true);
181183

182-
printf("Configure TX DMA\n");
184+
DEBUG_printf("Configure TX DMA\n");
183185
dma_channel_config dma_config_c = dma_channel_get_default_config(dma_tx);
184186
// TODO: investigate DMA_SIZE_32 transfers
185187
channel_config_set_transfer_data_size(&dma_config_c, DMA_SIZE_8);

matrix_display.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define DEBUG_MSGS
2+
3+
#ifdef DEBUG_MSGS
4+
#define DEBUG_printf(...) printf(__VA_ARGS__)
5+
#else
6+
#define DEBUG_printf(...)
7+
#endif

0 commit comments

Comments
 (0)