]> git.scottworley.com Git - tattlekey/blobdiff - client/press.c
client: Specify license
[tattlekey] / client / press.c
index cec17094d29830bbf1322449c001fe770fe5c235..4468bd9aa508a6269368550906de473ad226fa11 100644 (file)
@@ -1,3 +1,20 @@
+/* tattlekey: A one-key UDP keyboard
+ * Copyright (C) 2023  Scott Worley <scottworley@scottworley.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
 #include "press.h"
 #include "blink.h"
 #include "config.h"
@@ -28,10 +45,11 @@ press_pile_t *create_press_pile() {
   press_pile_t *pp = (press_pile_t *)xcalloc(1, sizeof(press_pile_t));
   pp->presses = (queue_t *)xcalloc(config_resend_count, sizeof(queue_t));
   pp->sleeps = (queue_t **)xcalloc(config_resend_count, sizeof(queue_t *));
-  for (int i = 0; i < config_resend_count; i++) {
-    uint element_count = 1 << i;
-    element_count = MAX(element_count, 32);
-    element_count = MIN(element_count, 512);
+  for (uint i = 0; i < config_resend_count; i++) {
+    const uint paranoid_safety_fudge = 10;
+    uint element_count = paranoid_safety_fudge + (1 << i);
+    element_count = MAX(element_count, config_minimum_queue_size);
+    element_count = MIN(element_count, config_maximum_queue_size);
     queue_init(&pp->presses[i], sizeof(press_t), element_count);
   }
   pp->sleeps_heap =
@@ -42,7 +60,7 @@ press_pile_t *create_press_pile() {
 }
 
 void add_press(press_pile_t *pp, press_t *press) {
-  int sc = press->send_count;
+  u16_t sc = press->send_count;
   if (sc >= config_resend_count)
     signal_error_by_blinking();
   bool was_empty = queue_is_empty(&pp->presses[sc]);