Modify the program to regularly send out primes.

This commit is contained in:
Savanni D'Gerinel 2022-07-02 19:36:27 -04:00
parent 576ad4089e
commit 021fd23ab6
1 changed files with 16 additions and 8 deletions

View File

@ -6,12 +6,16 @@
#include <stdio.h> #include <stdio.h>
#include <util/delay.h> #include <util/delay.h>
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); op_mode_t mode = rfm_mode(radio);
interrupt_flags_t flags = rfm_interrupts(radio); interrupt_flags_t flags = rfm_interrupts(radio);
display_clear(display); 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.listen_on) display_write_message(display, "Listen ");
if (mode.mode == sleep) display_write_message(display, "Sleep"); if (mode.mode == sleep) display_write_message(display, "Sleep");
if (mode.mode == standby) display_write_message(display, "Standby"); 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 main(void) {
int clock = 0;
display_t display = { display_t display = {
.reg = { .reg = {
.output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 }, .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); rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
status(&display, &radio); status(&display, &radio, clock);
_delay_ms(1000);
rfm_transmit(&radio, (uint8_t [7]){ 1, 2, 3, 5, 7, 11, 13 }, 7);
status(&display, &radio);
int next_transmit = 0;
while (1) { while (1) {
_delay_ms(1000); if (clock >= next_transmit) {
status(&display, &radio); 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); interrupt_flags_t flags = rfm_interrupts(&radio);
if (flags.packet_sent) { if (flags.packet_sent) {
rfm_standby(&radio); rfm_standby(&radio);
} }
clock++;
_delay_ms(1000);
} }
/* /*