From 021fd23ab6cb10f9666f26bb5ceb810b42427c52 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sat, 2 Jul 2022 19:36:27 -0400 Subject: [PATCH] Modify the program to regularly send out primes. --- prime-tx/main.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/prime-tx/main.c b/prime-tx/main.c index a2957fd..0b92f32 100644 --- a/prime-tx/main.c +++ b/prime-tx/main.c @@ -6,12 +6,16 @@ #include #include -void status(display_t *display, rfm_t *radio) { +void status(display_t *display, rfm_t *radio, int clock) { op_mode_t mode = rfm_mode(radio); interrupt_flags_t flags = rfm_interrupts(radio); display_clear(display); + char clock_str[16]; + sprintf(clock_str, "%4d ", clock); + display_write_message(display, clock_str); + if (mode.listen_on) display_write_message(display, "Listen "); if (mode.mode == sleep) display_write_message(display, "Sleep"); if (mode.mode == standby) display_write_message(display, "Standby"); @@ -36,6 +40,8 @@ void status(display_t *display, rfm_t *radio) { } int main(void) { + int clock = 0; + display_t display = { .reg = { .output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 }, @@ -62,20 +68,22 @@ int main(void) { rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error); - status(&display, &radio); - _delay_ms(1000); - - rfm_transmit(&radio, (uint8_t [7]){ 1, 2, 3, 5, 7, 11, 13 }, 7); - status(&display, &radio); + status(&display, &radio, clock); + int next_transmit = 0; while (1) { - _delay_ms(1000); - status(&display, &radio); + if (clock >= next_transmit) { + rfm_transmit(&radio, (uint8_t [7]){ 1, 2, 3, 5, 7, 11, 13 }, 7); + next_transmit = clock + 15; + } + status(&display, &radio, clock); interrupt_flags_t flags = rfm_interrupts(&radio); if (flags.packet_sent) { rfm_standby(&radio); } + clock++; + _delay_ms(1000); } /*