diff --git a/prime-tx/main.c b/prime-tx/main.c index 0b92f32..512688f 100644 --- a/prime-tx/main.c +++ b/prime-tx/main.c @@ -41,7 +41,9 @@ void status(display_t *display, rfm_t *radio, int clock) { int main(void) { int clock = 0; + uint8_t primes[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 0 }; + /* display_t display = { .reg = { .output = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 7 }, @@ -49,6 +51,7 @@ int main(void) { .latch_clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 5 }, }, }; + */ rfm_t radio = (rfm_t){ .spi = { @@ -61,22 +64,33 @@ int main(void) { .reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 }, }; - _delay_ms(15); - display_init(&display); + // _delay_ms(15); + // display_init(&display); rfm_error_e error; rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error); - status(&display, &radio, clock); + // status(&display, &radio, clock); int next_transmit = 0; + int prime = 0; while (1) { if (clock >= next_transmit) { - rfm_transmit(&radio, (uint8_t [7]){ 1, 2, 3, 5, 7, 11, 13 }, 7); - next_transmit = clock + 15; + // display_clear(&display); + char msg[16]; + sprintf(msg, "sending %d", primes[prime]); + // display_write_message(&display, msg); + rfm_transmit(&radio, &primes[prime], 1); + if (primes[prime] == 0) { + prime = 0; + } else { + prime++; + } + next_transmit = clock + 10; + _delay_ms(1000); } - status(&display, &radio, clock); + // status(&display, &radio, clock); interrupt_flags_t flags = rfm_interrupts(&radio); if (flags.packet_sent) { @@ -85,112 +99,5 @@ int main(void) { clock++; _delay_ms(1000); } - - /* - */ - - /* - if (!error) { - display_clear(&display); - display_write_message(&display, "Error detected"); - } else { - while (1) { - status(&display, &radio); - _delay_ms(1000); - - rfm_receive_mode(&radio); - status(&display, &radio); - _delay_ms(1000); - rfm_standby(&radio); - - } - } - */ - - /* - status(&display, &radio); - _delay_ms(1000); - - rfm_set_mode(&display, &radio, (op_mode_t){ .listen_on = true, .mode = standby }); - _delay_ms(1000); - rfm_set_mode(&display, &radio, (op_mode_t){ .listen_on = true, .mode = standby }); - _delay_ms(1000); - */ - - /* - rfm_packet_format(&radio, fixed, 8); - - rfm_set_mode(&display, &radio, (op_mode_t){ .listen_on = false, .mode = rx }); - _delay_ms(1000); - status(&display, &radio); - */ - - - /* - while (1) { - status(&display, &radio); - _delay_ms(1000); - - uint8_t data; - rfm_receive(rfm, &data, 1); - */ - - /* - uint8_t b[8]; - char msg[32]; - status(&display, &radio); - _delay_ms(1000); - - interrupt_flags_t flags = rfm_interrupts(&radio); - - if (flags.fifo_not_empty) { - rfm_receive(&radio, b, 8); - - display_clear(&display); - for (int i = 0; i < 8; i++) { - sprintf(msg, "%x", b[i]); - } - display_write_message(&display, msg); - _delay_ms(1000); - } - */ - // } - - /* - spi_acquire(&rfm.spi); - spi_transfer_byte(&rfm.spi, 0x11); - spi_transfer_byte(&rfm.spi, 0x01); - spi_release(&rfm.spi); - - spi_acquire(&rfm.spi); - spi_transfer_byte(&rfm.spi, 0x10); - spi_transfer_byte(&rfm.spi, 1); - spi_transfer_byte(&rfm.spi, 2); - spi_transfer_byte(&rfm.spi, 3); - spi_transfer_byte(&rfm.spi, 5); - spi_transfer_byte(&rfm.spi, 7); - spi_transfer_byte(&rfm.spi, 11); - spi_transfer_byte(&rfm.spi, 13); - spi_release(&rfm.spi); - - status = rfm_status(&rfm); - if (status & _BV(7)) { - clear_line(&light); - } else { - set_line(&light); - } - */ - - /* - uint8_t count[1] = { 0 }; - while(1) { - rfm_send_data(&rfm, count, 1); - count[0]++; - set_line(&light); - _delay_ms(50); - clear_line(&light); - _delay_ms(50); - } - */ return 0; }