From: Scott Worley Date: Mon, 9 Oct 2023 18:32:22 +0000 (-0700) Subject: client: Prefix all the config settings with "config_" X-Git-Tag: v0.1.0~51 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/d7789e5bc00881da0f9e0e96b867309f5289dc8f?ds=inline client: Prefix all the config settings with "config_" --- diff --git a/client/button.c b/client/button.c index 4df8d66..1f111a1 100644 --- a/client/button.c +++ b/client/button.c @@ -8,7 +8,7 @@ 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(); } @@ -17,7 +17,7 @@ static void respond_to_gpio_interrupt(uint gpio, uint32_t event_mask) { 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. @@ -25,6 +25,6 @@ void begin_listening_for_button_press(callback_t callback) { * 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); } diff --git a/client/config.c b/client/config.c index a9dc66e..9bd216d 100644 --- a/client/config.c +++ b/client/config.c @@ -1,27 +1,27 @@ #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; diff --git a/client/config.h b/client/config.h index 66e33a4..91345f9 100644 --- a/client/config.h +++ b/client/config.h @@ -4,29 +4,29 @@ #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 diff --git a/client/net.c b/client/net.c index c692a12..9ced48f 100644 --- a/client/net.c +++ b/client/net.c @@ -20,10 +20,10 @@ static void initialize_the_pcb() { 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(); } @@ -45,7 +45,7 @@ void send_report(u16_t seq, u16_t ago) { 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); diff --git a/client/tattlekey.c b/client/tattlekey.c index b37773c..6313424 100644 --- a/client/tattlekey.c +++ b/client/tattlekey.c @@ -16,7 +16,7 @@ static void button_pressed() { 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. */ @@ -30,7 +30,7 @@ int main() { 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); @@ -44,12 +44,12 @@ int main() { 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); } } }