Merge branch 'main' into main

This commit is contained in:
pinkit-cwa
2020-08-21 02:44:01 +02:00
committed by GitHub
45 changed files with 2784 additions and 1289 deletions
+1
View File
@@ -3,5 +3,6 @@ idf_component_register(
"main.c"
"display-interface.c"
"wifi/espidf-v4.0.c"
INCLUDE_DIRS ""
)
-20
View File
@@ -1,20 +0,0 @@
menu "Wifi Setup"
config WIFI_SSID
string "WiFi SSID"
default "myssid"
help
SSID (network name) for the example to connect to.
config WIFI_PASSWORD
string "WiFi Password"
default "mypassword"
help
WiFi password (WPA or WPA2) for the example to use.
config WIFI_MAXIMUM_RETRY
int "Maximum retry"
default 5
help
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
endmenu
-153
View File
@@ -1,153 +0,0 @@
// Copyright 2020 Lukas Haubaum
//
// Licensed under the GNU Affero General Public License, Version 3;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "ds3231.h"
#include "ena-exposure.h"
#include "interface.h"
#include "interface-menu.h"
#include "interface-datetime.h"
#include "ssd1306.h"
void interface_display_time(void *pvParameter)
{
static time_t curtime;
static char *curtime_text;
static struct tm rtc_time;
static bool edit_invert = false;
while (1)
{
curtime = time(NULL);
localtime_r(&curtime, &rtc_time);
curtime_text = asctime(&rtc_time);
ssd1306_text_line(SSD1306_ADDRESS, curtime_text, 0, false);
gmtime_r(&curtime, &rtc_time);
curtime_text = asctime(&rtc_time);
ssd1306_text_line(SSD1306_ADDRESS, curtime_text, 1, false);
if (interface_get_state() == INTERFACE_STATE_SET_DATETIME)
{
edit_invert = !edit_invert;
ds3231_set_time(&rtc_time);
char edit_year[4] = "";
char edit_month[3] = "";
char edit_day[2] = "";
char edit_hour[2] = "";
char edit_minute[2] = "";
char edit_second[2] = "";
switch (interface_datetime_state())
{
case INTERFACE_DATETIME_STATE_YEAR:
memcpy(&edit_year, &curtime_text[20], 4);
ssd1306_text_line_column(SSD1306_ADDRESS, edit_year, 0, 20, edit_invert);
break;
case INTERFACE_DATETIME_STATE_MONTH:
memcpy(&edit_month, &curtime_text[4], 3);
ssd1306_text_line_column(SSD1306_ADDRESS, edit_month, 0, 4, edit_invert);
break;
case INTERFACE_DATETIME_STATE_DAY:
memcpy(&edit_day, &curtime_text[8], 2);
ssd1306_text_line_column(SSD1306_ADDRESS, edit_day, 0, 8, edit_invert);
break;
case INTERFACE_DATETIME_STATE_HOUR:
memcpy(&edit_hour, &curtime_text[11], 2);
ssd1306_text_line_column(SSD1306_ADDRESS, edit_hour, 0, 11, edit_invert);
break;
case INTERFACE_DATETIME_STATE_MINUTE:
memcpy(&edit_minute, &curtime_text[14], 2);
ssd1306_text_line_column(SSD1306_ADDRESS, edit_minute, 0, 14, edit_invert);
break;
case INTERFACE_DATETIME_STATE_SECONDS:
memcpy(&edit_second[0], &curtime_text[17], 2);
ssd1306_text_line_column(SSD1306_ADDRESS, edit_second, 0, 17, edit_invert);
break;
}
}
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void interface_display_status(void *pvParameter)
{
static bool get_status = true;
while (1)
{
if (interface_get_state() == INTERFACE_STATE_STATUS)
{
if (get_status)
{
ena_exposure_summary_t summary;
ena_exposure_summary(ena_exposure_default_config(), &summary);
char buffer[23];
sprintf(buffer, "Days: %d", summary.days_since_last_exposure);
ssd1306_text_line(SSD1306_ADDRESS, buffer, 3, false);
sprintf(buffer, "Exposures: %d", summary.num_exposures);
ssd1306_text_line(SSD1306_ADDRESS, buffer, 4, false);
sprintf(buffer, "Score: %d, Max: %d", summary.risk_score_sum, summary.max_risk_score);
ssd1306_text_line(SSD1306_ADDRESS, buffer, 5, false);
get_status = false;
}
}
else if (!get_status)
{
ssd1306_clear_line(SSD1306_ADDRESS, 3, false);
ssd1306_clear_line(SSD1306_ADDRESS, 4, false);
ssd1306_clear_line(SSD1306_ADDRESS, 5, false);
get_status = true;
}
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void interface_display_idle(void *pvParameter)
{
static bool set_status = true;
while (1)
{
if (interface_get_state() == INTERFACE_STATE_IDLE)
{
if (set_status)
{
ssd1306_on(SSD1306_ADDRESS, false);
set_status = false;
}
}
else if (!set_status)
{
ssd1306_on(SSD1306_ADDRESS, true);
set_status = true;
}
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
void display_interface_start(void)
{
ssd1306_start(SSD1306_ADDRESS);
ssd1306_clear(SSD1306_ADDRESS);
interface_start();
interface_menu_start();
xTaskCreate(&interface_display_time, "interface_display_time", 4096, NULL, 5, NULL);
xTaskCreate(&interface_display_status, "interface_display_status", 4096, NULL, 5, NULL);
xTaskCreate(&interface_display_idle, "interface_display_idle", 4096, NULL, 5, NULL);
}
-22
View File
@@ -1,22 +0,0 @@
// Copyright 2020 Lukas Haubaum
//
// Licensed under the GNU Affero General Public License, Version 3;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _display_interface_H_
#define _display_interface_H_
/**
* @brief start display + interface
*/
void display_interface_start(void);
#endif
+11 -5
View File
@@ -25,16 +25,17 @@
#include "ena-exposure.h"
#include "ena-bluetooth-advertise.h"
#include "ena-bluetooth-scan.h"
#include "interface.h"
#include "ena-cwa.h"
#include "interface.h"
#include "ds3231.h"
#include "display-interface.h"
#include "wifi.h"
#include "ssd1306.h"
#include "wifi-controller.h"
#include "sdkconfig.h"
void app_main(void)
{
// debug only own LOG TAGs
esp_log_level_set("*", ESP_LOG_WARN);
esp_log_level_set(ENA_LOG, ESP_LOG_DEBUG);
@@ -47,6 +48,9 @@ void app_main(void)
esp_log_level_set(INTERFACE_LOG, ESP_LOG_DEBUG);
esp_log_level_set(WIFI_LOG, ESP_LOG_DEBUG);
// start interface
interface_start();
// set system time from DS3231
struct tm rtc_time;
ds3231_get_time(&rtc_time);
@@ -62,11 +66,13 @@ void app_main(void)
ena_start();
display_interface_start();
// start with main interface
interface_main_start();
while (1)
{
ena_run();
ena_cwa_run();
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
-38
View File
@@ -1,38 +0,0 @@
// Copyright 2020 Lukas Haubaum
//
// Licensed under the GNU Affero General Public License, Version 3;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.gnu.org/licenses/agpl-3.0.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _wifi_H_
#define _wifi_H_
#define WIFI_LOG "ESP-ENA-wifi" // TAG for Logging
#define WIFI_SSID (CONFIG_WIFI_SSID)
#define WIFI_PASSWORD (CONFIG_WIFI_PASSWORD)
#define WIFI_MAXIMUM_RETRY (CONFIG_WIFI_MAXIMUM_RETRY)
/**
* @brief start wifi connection to configured AP
*/
void wifi_start(void);
/**
* @brief stop wifi (restart does not work for now!)
*/
void wifi_stop(void);
/**
* @brief check if a wifi is connected
*/
bool wifi_is_connected(void);
#endif