Commit e0591a9b authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Rename and move some configuration macros

parent a8db4e0c
Pipeline #9494 failed with stages
in 1 minute and 4 seconds
......@@ -20,19 +20,44 @@
// https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
#define TIMEZONE "PST8PDT,M3.2.0/2,M11.1.0"
#define UPDATE_HOUR_START 2
// Hour of day 00-23 to start the update process
#define APP_UPDATE_HOUR_START 2
// 3 hours
#define UPDATE_MAX_FUDGE_FACTOR_MS ((1000*60*60)*3)
#define APP_UPDATE_MAX_FUDGE_FACTOR_MS ((1000*60*60)*3)
// Every hour
#define UPDATE_CHECK_PERIOD_MS (1000*60*60)
#define APP_UPDATE_CHECK_PERIOD_MS (1000*60*60)
// Every Hour
#define SNTP_UPDATE_INTERVAL (1000*60*60)
// Every Day
#define SNTP_UPDATE_INTERVAL_MS (1000*60*60*24)
//#define UPDATE_SKIP_VERSION_CHECK
#define ROW0_PIN 14
#define ROW1_PIN 12
#define ROW2_PIN 13
#define ROW3_PIN 15
#define COL0_PIN 4
#define COL1_PIN 5
#define COL2_PIN 18
#define DOOR_LOCK_PIN 12
#define DOOR_OPEN_LENGTH_MS (2.5 * 1000)
#define MIN_CODE_LENGTH 4
// 15 minutes
#define STATUS_MAX_NO_CONTACT_TIME_MS (1000 * 60 * 15)
// How often to update the keypad state
#define KEYPAD_SCAN_PERIOD_MS 50
// How long to wait before clearing the keypad if there have been no keypresses
#define KEYPAD_CLEAR_TIME_MS (1000 * 30)
#define KEYPAD_SUBMIT_CODE_KEY '#'
// maximum number of keypresses to remember at once
#define KEYPAD_KEY_PRESS_MEMORY_SIZE 100
#endif //DOOR_CONFIG_H
#include <string.h>
#include <malloc.h>
#include "config.h"
#include "app/api.h"
#include "connectors/http.h"
#include "connectors/rtos.h"
#include "config.h"
#include "app/list.h"
#include "app/token.h"
#include "app/status.h"
#include <malloc.h>
#define MAX_WAITING_REQUESTS 10
#define QUEUE_DONE_CHECK_PERIOD_MS 300
......
#include <stdbool.h>
#include "config.h"
#include "app/keypad.h"
#include "connectors/gpio.h"
#include "app/list.h"
#include "config.h"
#include "connectors/rtos.h"
#define ROWS 4
#define COLUMNS 3
#define SCAN_PERIOD_MS 50
// 1 minute
#define KEYPAD_EVENT_HOOK_WAIT_TIME 1000 * 60
......@@ -177,7 +176,7 @@ void door_keypad_scan_task(void* pvParameters)
do
{
door_rtos_task_delay(SCAN_PERIOD_MS);
door_rtos_task_delay(KEYPAD_SCAN_PERIOD_MS);
// For debouncing, we will just check the state every scan period,
// We will see what is pressed, and handle it. and then will not
// handle that again until we see it released.
......
#include "app/state.h"
#include <stddef.h>
#include "config.h"
#include "app/state.h"
#include "connectors/rtos.h"
#include "app/keypad.h"
#include "app/api.h"
#include "app/lock.h"
#include "app/event.h"
#include "config.h"
// 30 seconds
#define PAD_CLEAR_TIME_MS 1000 * 30
#define KEY_PRESS_MEMORY_SIZE 100
#define SUBMIT_CODE_KEY ('#')
#define KEYS_LOCK_WAIT_TIME_MS 40
#define KEY_QUEUE_BUFFER_SIZE 20
......@@ -18,7 +14,7 @@ static queue_handle_t key_queue;
static unsigned total_keys;
static volatile bool done;
static char keys[KEY_PRESS_MEMORY_SIZE];
static char keys[KEYPAD_KEY_PRESS_MEMORY_SIZE];
// This function will be executed from another thread.
static void new_key_hook(unsigned char c)
......@@ -47,7 +43,7 @@ void door_state_task(void* parameters)
do
{
if (door_rtos_queue_receive(key_queue, &c, PAD_CLEAR_TIME_MS))
if (door_rtos_queue_receive(key_queue, &c, KEYPAD_CLEAR_TIME_MS))
{
// If we are in unlocked mode, just open the door and carry on.
if (door_rtos_event_get(DOOR_OPEN_MODE_EVENT))
......@@ -56,10 +52,10 @@ void door_state_task(void* parameters)
continue;
}
if (total_keys == KEY_PRESS_MEMORY_SIZE)
if (total_keys == KEYPAD_KEY_PRESS_MEMORY_SIZE)
total_keys = 0;
keys[total_keys++] = c;
if (c == SUBMIT_CODE_KEY)
if (c == KEYPAD_SUBMIT_CODE_KEY)
{
// Overwrite the '#' with a null terminator so it can check the API
keys[total_keys - 1] = 0x00;
......
// Hide JSMN symbols
#define JSMN_STATIC
#include "config.h"
#include <stdbool.h>
#include <malloc.h>
#include <string.h>
......@@ -12,12 +13,18 @@
#include "app/event.h"
#include "connectors/sntp.h"
/*
* Need to do this otherwise when compiling the tests the
* compiler won't see the declaration and assume the return
* type is int. This leads to many many problems as the full
* return value does not get put in the rax register, or maybe
* it gets put into eax instead of rax... something like that
* since the upper bits were cut off...
*/
extern const char* strptime(const char*, const char*, struct tm*);
#define STATUS_QUEUE_LENGTH 5
#define STATUS_QUEUE_INSERT_TIMEOUT_MS 100
// 15 minutes
#define STATUS_MAX_NO_CONTACT_TIME_MS (1000 * 60 * 15)
// Every second
#define STATUS_LOCAL_UPDATE_CHECK_TIME_MS 1000
......@@ -26,6 +33,8 @@ extern const char* strptime(const char*, const char*, struct tm*);
// REALLY shouldn't take more than 10 seconds to get through the list
#define LIST_UPDATE_WAIT_TIME_MS 1000 * 10
// The esp32 does not support %F or %z :(
// https://github.com/espressif/esp-idf/issues/2219
//#define TIME_FORMAT "%FT%T%z"
#define TIME_FORMAT "%Y-%m-%dT%H:%M:%S"
......
#include "app/token.h"
#include "connectors/nvs.h"
#include <string.h>
#include <malloc.h>
#include "app/token.h"
#include "connectors/nvs.h"
#define API_TOKEN_NVS_KEY "API_TOKEN"
// Lets not allow tokens longer than this, jut for protection of something else
// Lets not allow tokens longer than this, just for protection of something else
// going wrong
#define API_TOKEN_MAX_LEN 500
......
......@@ -8,16 +8,14 @@
int door_update_do(void)
{
if (door_time_get_current_hour() == UPDATE_HOUR_START)
if (door_time_get_current_hour() == APP_UPDATE_HOUR_START)
{
door_rtos_task_delay(
door_random_get_random_between(0, UPDATE_MAX_FUDGE_FACTOR_MS)
door_random_get_random_between(0, APP_UPDATE_MAX_FUDGE_FACTOR_MS)
);
if (door_http_ota_update(door_token_get()))
{
return NEW_UPDATE;
}
}
return NO_NEW_UPDATE;
}
......@@ -28,7 +26,7 @@ void update_task(void* parameters)
do
{
door_rtos_task_delay(UPDATE_CHECK_PERIOD_MS);
door_rtos_task_delay(APP_UPDATE_CHECK_PERIOD_MS);
} while (door_update_do() == NO_NEW_UPDATE);
door_rtos_restart();
......
......@@ -25,7 +25,7 @@ void door_sntp_initialize(void)
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, NTP_SERVER);
sntp_set_time_sync_notification_cb(time_sync_notification_cb);
sntp_set_sync_interval(SNTP_UPDATE_INTERVAL);
sntp_set_sync_interval(SNTP_UPDATE_INTERVAL_MS);
sntp_init();
setenv("TZ", TIMEZONE, 1);
tzset();
......
......@@ -11,7 +11,7 @@ TEST_CASE("door controller does updates", "[update]")
door_rtos_event_set(TIME_SYNCED_EVENT);
int hour = UPDATE_HOUR_START;
int hour = APP_UPDATE_HOUR_START;
Hooks::sntp->get_time_hook = [&](struct tm* time)
{
......@@ -21,7 +21,7 @@ TEST_CASE("door controller does updates", "[update]")
SECTION("No update if it's not the correct hour")
{
hour = UPDATE_HOUR_START - 1;
hour = APP_UPDATE_HOUR_START - 1;
REQUIRE(door_update_do() == NO_NEW_UPDATE);
}
......@@ -39,10 +39,10 @@ TEST_CASE("door controller does updates", "[update]")
delay = d;
};
random = UPDATE_MAX_FUDGE_FACTOR_MS;
random = APP_UPDATE_MAX_FUDGE_FACTOR_MS;
door_update_do();
REQUIRE(delay == 0);
random = UPDATE_MAX_FUDGE_FACTOR_MS + 1;
random = APP_UPDATE_MAX_FUDGE_FACTOR_MS + 1;
door_update_do();
REQUIRE(delay == 1);
random = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment