Set up radio listener to control the lantern
This commit is contained in:
parent
7b4429db35
commit
2acff8d3f5
|
@ -253,8 +253,10 @@
|
|||
(packages."x86_64-linux"."animation" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."dio" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."display" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."rfm" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."shift-register" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."sk9822" { inherit gcc cflags; })
|
||||
(packages."x86_64-linux"."spi" { inherit gcc cflags; })
|
||||
];
|
||||
};
|
||||
|
||||
|
|
|
@ -15,10 +15,12 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
#include <dio.h>
|
||||
#include <display.h>
|
||||
#include "lantern.h"
|
||||
#include <rfm.h>
|
||||
#include <sk9822.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FPS 15
|
||||
#define TICKS_PER_SECOND 7812
|
||||
|
@ -28,6 +30,7 @@ You should have received a copy of the GNU General Public License along with thi
|
|||
|
||||
typedef struct {
|
||||
bool frame_timeout;
|
||||
bool message_arrived;
|
||||
} status_flags_t;
|
||||
|
||||
status_flags_t status_flags;
|
||||
|
@ -36,6 +39,10 @@ ISR(TIMER1_COMPA_vect) {
|
|||
status_flags.frame_timeout = true;
|
||||
}
|
||||
|
||||
ISR(INT6_vect) {
|
||||
status_flags.message_arrived = true;
|
||||
}
|
||||
|
||||
void setup_fps_timer(void) {
|
||||
// WGM = 0100: CTC with OCR1nA top
|
||||
// CS = 101: clock / 1024
|
||||
|
@ -51,8 +58,9 @@ void setup_fps_timer(void) {
|
|||
}
|
||||
|
||||
int main(void) {
|
||||
EIMSK = 1 << INT2;
|
||||
EIMSK = 1 << INT6 | 1 << INT2;
|
||||
EICRA |= 1 << ISC21 | 1 << ISC20;
|
||||
EICRB |= 1 << ISC61 | 1 << ISC60;
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -65,6 +73,22 @@ int main(void) {
|
|||
PRR0 = _BV(7) | _BV(5) | _BV(2);
|
||||
PRR1 = _BV(7) | _BV(4) | _BV(3) | _BV(0);
|
||||
|
||||
rfm_t radio = (rfm_t){
|
||||
.spi = {
|
||||
.clock = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 1 },
|
||||
.data_out = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 2 },
|
||||
.data_in = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 3 },
|
||||
.chip_select = { .ddr = &DDRB, .port = &PORTB, .pin = &PINB, .addr = 4 },
|
||||
},
|
||||
.irq = { .ddr = &DDRE, .port = &PORTE, .pin = &PINE, .addr = 6 },
|
||||
.reset = { .ddr = &DDRD, .port = &PORTD, .pin = &PIND, .addr = 4 },
|
||||
};
|
||||
|
||||
rfm_error_e error;
|
||||
rfm_init(&radio, (uint8_t [4]){ 0xde, 0xca, 0xfb, 0xad }, 4, &error);
|
||||
rfm_listen(&radio);
|
||||
|
||||
/*
|
||||
display_t display = {
|
||||
.reg = {
|
||||
.output = { .ddr = &DDRF, .port = &PORTF, .pin = &PINF, .addr = 7 },
|
||||
|
@ -76,6 +100,7 @@ int main(void) {
|
|||
display_init(&display);
|
||||
display_write_message(&display, "ready");
|
||||
_delay_ms(1000);
|
||||
*/
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
@ -104,6 +129,22 @@ int main(void) {
|
|||
status_flags.frame_timeout = false;
|
||||
lantern_step(&lantern, colors);
|
||||
sk9822_send(&lights, colors, LIGHT_COUNT);
|
||||
} else if (status_flags.message_arrived) {
|
||||
status_flags.message_arrived = false;
|
||||
char msg[60];
|
||||
uint8_t length;
|
||||
interrupt_flags_t flags = rfm_interrupts(&radio);
|
||||
while (flags.fifo_not_empty) {
|
||||
rfm_receive(&radio, (uint8_t *)msg, &length);
|
||||
if (!strncmp(msg, "normal", strlen("normal"))) {
|
||||
lantern_set_mode(&lantern, normal);
|
||||
} else if (!strncmp(msg, "spooky", strlen("spooky"))) {
|
||||
lantern_set_mode(&lantern, spooky);
|
||||
} else if (!strncmp(msg, "eerie", strlen("eerie"))) {
|
||||
lantern_set_mode(&lantern, eerie);
|
||||
}
|
||||
flags = rfm_interrupts(&radio);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (status_flags.button_press[0]) {
|
||||
|
|
Loading…
Reference in New Issue