static callback_t button_callback = NULL;
static void respond_to_gpio_interrupt(uint gpio, uint32_t event_mask) {
- if (gpio == button_pin && event_mask & GPIO_IRQ_EDGE_FALL &&
+ if (gpio == config_button_pin && event_mask & GPIO_IRQ_EDGE_FALL &&
button_callback) {
button_callback();
}
void begin_listening_for_button_press(callback_t callback) {
button_callback = callback;
- gpio_set_pulls(button_pin, 1, 0);
+ gpio_set_pulls(config_button_pin, 1, 0);
/* Allow some time for the pull-up to take effect.
* I'm not sure if this is necessary.
* the internal GPIO pull-up resistors are 50k. */
sleep_ms(100);
- gpio_set_irq_enabled_with_callback(button_pin, GPIO_IRQ_EDGE_FALL, 1,
+ gpio_set_irq_enabled_with_callback(config_button_pin, GPIO_IRQ_EDGE_FALL, 1,
respond_to_gpio_interrupt);
}
#include "config.h"
/* Wi-Fi credentials */
-char wifi_ssid[] = "THEWIFISSID";
-char wifi_pass[] = "THEWIFIPASSWORD";
+char config_wifi_ssid[] = "THEWIFISSID";
+char config_wifi_pass[] = "THEWIFIPASSWORD";
/* Network address of the server to contact */
-char tattle_server_ip_address[] = "192.168.10.10";
-u16_t tattle_port = 29803; // 'tk'
+char config_tattle_server_ip_address[] = "192.168.10.10";
+u16_t config_tattle_port = 29803; // 'tk'
/* For distinguishing reports from multiple tattlekey devices. */
-u16_t this_tattler_identity = 1;
+u16_t config_this_tattler_identity = 1;
/* Which GPIO pin is the button connected to?
* The button should span this pin and ground, connecting this pin to ground
* when pressed.
* https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/10
* recommends pins 18, 22, or 28. */
-uint button_pin = 18;
+uint config_button_pin = 18;
/* Don't bother reporting each separate button press when it is pressed many
* times in short succession. (We also use this to de-bounce. :) */
-u32_t minimum_seconds_between_button_presses = 1;
+u32_t config_minimum_seconds_between_button_presses = 1;
/* Send each report multiple times. */
-uint resend_count = 5;
-u32_t resend_interval_ms = 1000;
+uint config_resend_count = 5;
+u32_t config_resend_interval_ms = 1000;
#include "lwip/arch.h"
/* Wi-Fi credentials */
-extern char wifi_ssid[];
-extern char wifi_pass[];
+extern char config_wifi_ssid[];
+extern char config_wifi_pass[];
/* Network address of the server to contact */
-extern char tattle_server_ip_address[];
-extern u16_t tattle_port;
+extern char config_tattle_server_ip_address[];
+extern u16_t config_tattle_port;
/* For distinguishing reports from multiple tattlekey devices. */
-extern u16_t this_tattler_identity;
+extern u16_t config_this_tattler_identity;
/* Which GPIO pin is the button connected to?
* The button should span this pin and ground, connecting this pin to ground
* when pressed.
* https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/10
* recommends pins 18, 22, or 28. */
-extern uint button_pin;
+extern uint config_button_pin;
/* Don't bother reporting each separate button press when it is pressed many
* times in short succession. (We also use this to de-bounce. :) */
-extern u32_t minimum_seconds_between_button_presses;
+extern u32_t config_minimum_seconds_between_button_presses;
/* Send each report multiple times. */
-extern uint resend_count;
-extern u32_t resend_interval_ms;
+extern uint config_resend_count;
+extern u32_t config_resend_interval_ms;
#endif
signal_error_by_blinking();
ip_addr_t ipaddr;
- if (ip4addr_aton(tattle_server_ip_address, &ipaddr) == 0)
+ if (ip4addr_aton(config_tattle_server_ip_address, &ipaddr) == 0)
signal_error_by_blinking();
- if (udp_connect(the_pcb, &ipaddr, tattle_port) != ERR_OK)
+ if (udp_connect(the_pcb, &ipaddr, config_tattle_port) != ERR_OK)
signal_error_by_blinking();
}
struct tattle_message_wire_format *msg =
(struct tattle_message_wire_format *)(p->payload);
- msg->sender = htons(this_tattler_identity);
+ msg->sender = htons(config_this_tattler_identity);
msg->seq = htons(seq);
msg->ago = htons(ago);
static uint64_t last_button_press_time = 0;
uint32_t now = time_s();
uint32_t time_since_last_press = now - last_button_press_time;
- if (time_since_last_press >= minimum_seconds_between_button_presses) {
+ if (time_since_last_press >= config_minimum_seconds_between_button_presses) {
last_button_press_time = now;
/* We don't check for failure (full queue) here because there's not much to
* be done about it. */
signal_error_by_blinking();
cyw43_arch_enable_sta_mode();
signal(3, 100);
- if (cyw43_arch_wifi_connect_timeout_ms(wifi_ssid, wifi_pass,
+ if (cyw43_arch_wifi_connect_timeout_ms(config_wifi_ssid, config_wifi_pass,
CYW43_AUTH_WPA2_AES_PSK, 90000))
signal_error_by_blinking();
signal(2, 300);
uint32_t t;
queue_remove_blocking(&queue, &t);
seq++;
- for (int i = 0; i < resend_count; i++) {
+ for (int i = 0; i < config_resend_count; i++) {
uint32_t now = time_s();
uint32_t ago = now - t;
send_report(seq, ago);
signal(i == 0 ? 2 : 1, 100);
- sleep_ms(resend_interval_ms);
+ sleep_ms(config_resend_interval_ms);
}
}
}