added Exposure code, DS3231, SSD1306, interfaces, started with protocol buffers impl.

This commit is contained in:
Lurkars
2020-07-22 21:44:17 +02:00
parent 04f7e8e1d6
commit 4ba1352a05
38 changed files with 5800 additions and 178 deletions
+1
View File
@@ -3,6 +3,7 @@ idf_component_register(
"ena-interface.c"
"ena-interface-datetime.c"
"ena-interface-menu.c"
"ena-interface-status.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES
ena
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include "esp_log.h"
#include "ena-interface.h"
@@ -22,15 +24,51 @@
static int interface_datetime_state = ENA_INTERFACE_DATETIME_STATE_YEAR;
const uint32_t interface_datetime_steps[6] = {
31557600, 2629800, 86400, 3600, 60, 1};
void ena_interface_datetime_esc(void)
{
ena_interface_menu_start();
}
void ena_interface_datetime_ok(void)
{
interface_datetime_state++;
if (interface_datetime_state > ENA_INTERFACE_DATETIME_STATE_SECONDS)
{
interface_datetime_state = ENA_INTERFACE_DATETIME_STATE_YEAR;
}
ESP_LOGD(ENA_INTERFACE_LOG, "datetime to %d", interface_datetime_state);
}
void ena_interface_datetime_up(void)
{
time_t curtime = time(NULL);
curtime += interface_datetime_steps[interface_datetime_state];
struct timeval tv = {0};
tv.tv_sec = curtime;
settimeofday(&tv, NULL);
ESP_LOGD(ENA_INTERFACE_LOG, "increment %d about %u %s", interface_datetime_state, interface_datetime_steps[interface_datetime_state], ctime(&curtime));
}
void ena_interface_datetime_down(void)
{
time_t curtime = time(NULL);
curtime -= interface_datetime_steps[interface_datetime_state];
struct timeval tv = {0};
tv.tv_sec = curtime;
settimeofday(&tv, NULL);
ESP_LOGD(ENA_INTERFACE_LOG, "decrement %d about %u %s", interface_datetime_state, interface_datetime_steps[interface_datetime_state], ctime(&curtime));
}
void ena_interface_datetime_start(void)
{
ena_interface_set_state(ENA_INTERFACE_STATE_SET_YEAR);
ena_interface_set_state(ENA_INTERFACE_STATE_SET_DATETIME);
ena_interface_register_touch_callback(TOUCH_PAD_ESC, &ena_interface_datetime_esc);
ena_interface_register_touch_callback(TOUCH_PAD_OK, &ena_interface_datetime_ok);
ena_interface_register_touch_callback(TOUCH_PAD_UP, &ena_interface_datetime_up);
ena_interface_register_touch_callback(TOUCH_PAD_DOWN, &ena_interface_datetime_down);
ESP_LOGD(ENA_INTERFACE_LOG, "start datetime interface");
}
+24 -5
View File
@@ -17,6 +17,7 @@
#include "driver/touch_pad.h"
#include "ena-interface.h"
#include "ena-interface-datetime.h"
#include "ena-interface-status.h"
#include "ena-interface-menu.h"
@@ -24,17 +25,35 @@ static int interface_menu_state = ENA_INTERFACE_MENU_STATE_IDLE;
void ena_interface_menu_ok(void)
{
if (interface_menu_state == ENA_INTERFACE_MENU_STATE_SELECT_TIME) {
if (interface_menu_state == ENA_INTERFACE_MENU_STATE_SELECT_TIME)
{
ena_interface_datetime_start();
}
else if (interface_menu_state == ENA_INTERFACE_MENU_STATE_SELECT_STATUS)
{
ena_interface_status_start();
}
else if (interface_menu_state == ENA_INTERFACE_MENU_STATE_IDLE)
{
if (ena_interface_get_state() == ENA_INTERFACE_STATE_MENU)
{
ena_interface_set_state(ENA_INTERFACE_STATE_IDLE);
ena_interface_register_touch_callback(TOUCH_PAD_UP, NULL);
ena_interface_register_touch_callback(TOUCH_PAD_DOWN, NULL);
}
else
{
ena_interface_menu_start();
}
}
}
void ena_interface_menu_up(void)
{
interface_menu_state--;
if (interface_menu_state < 0)
if (interface_menu_state < ENA_INTERFACE_MENU_STATE_IDLE)
{
interface_menu_state = sizeof(interface_menu_state) - 1;
interface_menu_state = ENA_INTERFACE_MENU_STATE_SELECT_STATUS;
}
ESP_LOGD(ENA_INTERFACE_LOG, "menu up to %d", interface_menu_state);
}
@@ -42,9 +61,9 @@ void ena_interface_menu_up(void)
void ena_interface_menu_down(void)
{
interface_menu_state++;
if (interface_menu_state == sizeof(interface_menu_state))
if (interface_menu_state > ENA_INTERFACE_MENU_STATE_SELECT_STATUS)
{
interface_menu_state = 0;
interface_menu_state = ENA_INTERFACE_MENU_STATE_IDLE;
}
ESP_LOGD(ENA_INTERFACE_LOG, "menu down to %d", interface_menu_state);
}
@@ -0,0 +1,37 @@
// 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 <stdio.h>
#include "esp_log.h"
#include "driver/touch_pad.h"
#include "ena-interface.h"
#include "ena-interface-menu.h"
#include "ena-interface-status.h"
void ena_interface_status_esc(void)
{
ena_interface_menu_start();
}
void ena_interface_status_start(void)
{
ena_interface_set_state(ENA_INTERFACE_STATE_STATUS);
ena_interface_register_touch_callback(TOUCH_PAD_ESC, &ena_interface_status_esc);
ena_interface_register_touch_callback(TOUCH_PAD_OK, NULL);
ena_interface_register_touch_callback(TOUCH_PAD_UP, NULL);
ena_interface_register_touch_callback(TOUCH_PAD_DOWN, NULL);
ESP_LOGD(ENA_INTERFACE_LOG, "start status interface");
}
+13 -17
View File
@@ -33,24 +33,23 @@ void ena_interface_register_touch_callback(int touch_pad, ena_interface_touch_ca
void ena_interface_run(void *pvParameter)
{
uint16_t touch_value;
uint16_t touch_thresh;
bool touch_status_current[4] = {0};
static uint16_t touch_value;
static uint16_t touch_thresh;
static bool touch_status_current[TOUCH_PAD_MAX] = {0};
while (1)
{
for (int i = 0; i < TOUCH_PAD_COUNT; i++)
{
int touch_id = touch_mapping[i];
ESP_ERROR_CHECK_WITHOUT_ABORT(touch_pad_read_filtered(touch_id, &touch_value));
ESP_ERROR_CHECK_WITHOUT_ABORT(touch_pad_get_thresh(touch_id, &touch_thresh));
ESP_ERROR_CHECK_WITHOUT_ABORT(touch_pad_read_filtered(touch_mapping[i], &touch_value));
ESP_ERROR_CHECK_WITHOUT_ABORT(touch_pad_get_thresh(touch_mapping[i], &touch_thresh));
touch_status_current[i] = touch_value < touch_thresh;
if (!touch_status[i] & touch_status_current[i])
{
ESP_LOGD(ENA_INTERFACE_LOG, "touch %u at %d (thresh %u)", touch_value, touch_id, touch_thresh);
if (touch_callbacks[touch_id] != NULL)
ESP_LOGD(ENA_INTERFACE_LOG, "touch %u at %d (thresh %u)", touch_value, touch_mapping[i], touch_thresh);
if (touch_callbacks[touch_mapping[i]] != NULL)
{
(*touch_callbacks[touch_id])();
(*touch_callbacks[touch_mapping[i]])();
}
}
touch_status[i] = touch_status_current[i];
@@ -73,22 +72,19 @@ void ena_interface_start(void)
for (int i = 0; i < TOUCH_PAD_COUNT; i++)
{
int touch_id = touch_mapping[i];
ESP_ERROR_CHECK(touch_pad_config(touch_id, 0));
ESP_ERROR_CHECK(touch_pad_config(touch_mapping[i], 0));
}
ESP_ERROR_CHECK(touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD));
uint16_t touch_value;
for (int i = 0; i < TOUCH_PAD_COUNT; i++)
{
int touch_id = touch_mapping[i];
ESP_ERROR_CHECK(touch_pad_read_filtered(touch_id, &touch_value));
ESP_ERROR_CHECK(touch_pad_set_thresh(touch_id, touch_value * 2 / 3));
ESP_LOGD(ENA_INTERFACE_LOG, "calibrate %u at %u (thresh %u)", touch_id, touch_value, (touch_value * 2 / 3));
ESP_ERROR_CHECK(touch_pad_read_filtered(touch_mapping[i], &touch_value));
ESP_ERROR_CHECK(touch_pad_set_thresh(touch_mapping[i], touch_value * 2 / 3));
ESP_LOGD(ENA_INTERFACE_LOG, "calibrate %u at %u (thresh %u)", touch_mapping[i], touch_value, (touch_value * 2 / 3));
}
xTaskCreate(&ena_interface_run, "ena_interface_run", configMINIMAL_STACK_SIZE * 4, NULL, 5, NULL);
xTaskCreate(&ena_interface_run, "ena_interface_run", 4096, NULL, 5, NULL);
}
int ena_interface_get_state(void)
@@ -18,7 +18,7 @@ typedef enum
{
ENA_INTERFACE_MENU_STATE_IDLE = 0,
ENA_INTERFACE_MENU_STATE_SELECT_TIME,
ENA_INTERFACE_MENU_STATE_SELECT_INFO,
ENA_INTERFACE_MENU_STATE_SELECT_STATUS,
} ena_interface_menu_state;
void ena_interface_menu_start(void);
@@ -0,0 +1,19 @@
// 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 _ena_INTERFACE_STATUS_H_
#define _ena_INTERFACE_STATUS_H_
void ena_interface_status_start(void);
#endif
@@ -28,15 +28,10 @@
*/
typedef enum
{
ENA_INTERFACE_STATE_IDLE = 0, // ilde state, do nothing
ENA_INTERFACE_STATE_MENU, // main menu
ENA_INTERFACE_STATE_SET_YEAR, // set current year
ENA_INTERFACE_STATE_SET_MONTH, // set current month
ENA_INTERFACE_STATE_SET_DAY, // set current day
ENA_INTERFACE_STATE_SET_HOUR, // set current hour
ENA_INTERFACE_STATE_SET_MINUTE, // set current minute
ENA_INTERFACE_STATE_SET_SECONDS, // set current second
ENA_INTERFACE_STATE_STATUS, // view current status
ENA_INTERFACE_STATE_IDLE = 0, // ilde state, do nothing
ENA_INTERFACE_STATE_MENU, // main menu
ENA_INTERFACE_STATE_SET_DATETIME, // set current date and time
ENA_INTERFACE_STATE_STATUS, // current status
} ena_interface_state;
/**