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 <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);
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);
}
/*