mirror of
https://github.com/Lurkars/esp-ena.git
synced 2026-05-08 20:10:37 +02:00
moved to configurable components, added SSD1306 support
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
idf_component_register(
|
||||
SRCS
|
||||
"interface.c"
|
||||
"interface-datetime.c"
|
||||
"interface-menu.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_REQUIRES
|
||||
ena
|
||||
)
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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_DATETIME_H_
|
||||
#define _ena_INTERFACE_DATETIME_H_
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ENA_INTERFACE_DATETIME_STATE_YEAR = 0,
|
||||
ENA_INTERFACE_DATETIME_STATE_MONTH,
|
||||
ENA_INTERFACE_DATETIME_STATE_DAY,
|
||||
ENA_INTERFACE_DATETIME_STATE_HOUR,
|
||||
ENA_INTERFACE_DATETIME_STATE_MINUTE,
|
||||
ENA_INTERFACE_DATETIME_STATE_SECONDS,
|
||||
} ena_inerface_datetime_state;
|
||||
|
||||
void ena_interface_datetime_start(void);
|
||||
|
||||
int ena_interface_datetime_state(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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_MENU_H_
|
||||
#define _ena_INTERFACE_MENU_H_
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ENA_INTERFACE_MENU_STATE_IDLE = 0,
|
||||
ENA_INTERFACE_MENU_STATE_SELECT_TIME,
|
||||
ENA_INTERFACE_MENU_STATE_SELECT_INFO,
|
||||
} ena_interface_menu_state;
|
||||
|
||||
void ena_interface_menu_start(void);
|
||||
|
||||
int ena_interface_menu_get_state(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
// 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_H_
|
||||
#define _ena_INTERFACE_H_
|
||||
|
||||
#define ENA_INTERFACE_LOG "ESP-ENA-interface" // TAG for Logging
|
||||
|
||||
#define TOUCHPAD_FILTER_TOUCH_PERIOD (10)
|
||||
#define TOUCH_PAD_COUNT (4)
|
||||
#define TOUCH_PAD_ESC (TOUCH_PAD_NUM0)
|
||||
#define TOUCH_PAD_OK (TOUCH_PAD_NUM6)
|
||||
#define TOUCH_PAD_UP (TOUCH_PAD_NUM4)
|
||||
#define TOUCH_PAD_DOWN (TOUCH_PAD_NUM3)
|
||||
|
||||
/**
|
||||
* @brief different interface states
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @brief callback function on touch event
|
||||
*/
|
||||
typedef void (*ena_interface_touch_callback)(void);
|
||||
|
||||
/**
|
||||
* @brief register a callback function for touch event
|
||||
*
|
||||
* @param[in] touch_pad id of the touchpad to listen touch
|
||||
* @param[in] callback callback function
|
||||
*/
|
||||
void ena_interface_register_touch_callback(int touch_pad, ena_interface_touch_callback callback);
|
||||
|
||||
/**
|
||||
* @brief get current interface state
|
||||
*
|
||||
* @return
|
||||
* current state the interface is in
|
||||
*/
|
||||
int ena_interface_get_state(void);
|
||||
|
||||
/**
|
||||
* @brief set current interface state
|
||||
*
|
||||
* @param[in] state new state to set
|
||||
*/
|
||||
void ena_interface_set_state(ena_interface_state state);
|
||||
|
||||
/**
|
||||
* @brief start interface logic
|
||||
*
|
||||
* This will initialize the touch controls and start a task to listen to touch
|
||||
* inputs and calling the callbacks
|
||||
*/
|
||||
void ena_interface_start(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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 "ena-interface.h"
|
||||
#include "driver/touch_pad.h"
|
||||
#include "ena-interface-menu.h"
|
||||
|
||||
#include "ena-interface-datetime.h"
|
||||
|
||||
static int interface_datetime_state = ENA_INTERFACE_DATETIME_STATE_YEAR;
|
||||
|
||||
void ena_interface_datetime_esc(void)
|
||||
{
|
||||
ena_interface_menu_start();
|
||||
}
|
||||
|
||||
void ena_interface_datetime_start(void)
|
||||
{
|
||||
ena_interface_set_state(ENA_INTERFACE_STATE_SET_YEAR);
|
||||
ena_interface_register_touch_callback(TOUCH_PAD_ESC, &ena_interface_datetime_esc);
|
||||
ESP_LOGD(ENA_INTERFACE_LOG, "start datetime interface");
|
||||
}
|
||||
|
||||
int ena_interface_datetime_state(void)
|
||||
{
|
||||
return interface_datetime_state;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// 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-datetime.h"
|
||||
|
||||
#include "ena-interface-menu.h"
|
||||
|
||||
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) {
|
||||
ena_interface_datetime_start();
|
||||
}
|
||||
}
|
||||
|
||||
void ena_interface_menu_up(void)
|
||||
{
|
||||
interface_menu_state--;
|
||||
if (interface_menu_state < 0)
|
||||
{
|
||||
interface_menu_state = sizeof(interface_menu_state) - 1;
|
||||
}
|
||||
ESP_LOGD(ENA_INTERFACE_LOG, "menu up to %d", interface_menu_state);
|
||||
}
|
||||
|
||||
void ena_interface_menu_down(void)
|
||||
{
|
||||
interface_menu_state++;
|
||||
if (interface_menu_state == sizeof(interface_menu_state))
|
||||
{
|
||||
interface_menu_state = 0;
|
||||
}
|
||||
ESP_LOGD(ENA_INTERFACE_LOG, "menu down to %d", interface_menu_state);
|
||||
}
|
||||
|
||||
void ena_interface_menu_start(void)
|
||||
{
|
||||
ena_interface_set_state(ENA_INTERFACE_STATE_MENU);
|
||||
ena_interface_register_touch_callback(TOUCH_PAD_ESC, NULL);
|
||||
ena_interface_register_touch_callback(TOUCH_PAD_OK, &ena_interface_menu_ok);
|
||||
ena_interface_register_touch_callback(TOUCH_PAD_UP, &ena_interface_menu_up);
|
||||
ena_interface_register_touch_callback(TOUCH_PAD_DOWN, &ena_interface_menu_down);
|
||||
|
||||
ESP_LOGD(ENA_INTERFACE_LOG, "start menu interface");
|
||||
}
|
||||
|
||||
int ena_interface_menu_get_state(void)
|
||||
{
|
||||
return interface_menu_state;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// 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 "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "driver/touch_pad.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "ena-interface.h"
|
||||
|
||||
static int interface_state = ENA_INTERFACE_STATE_IDLE;
|
||||
|
||||
static int touch_mapping[TOUCH_PAD_COUNT] = {0};
|
||||
static bool touch_status[TOUCH_PAD_COUNT] = {0};
|
||||
static ena_interface_touch_callback touch_callbacks[TOUCH_PAD_MAX];
|
||||
|
||||
void ena_interface_register_touch_callback(int touch_pad, ena_interface_touch_callback callback)
|
||||
{
|
||||
touch_callbacks[touch_pad] = callback;
|
||||
}
|
||||
|
||||
void ena_interface_run(void *pvParameter)
|
||||
{
|
||||
uint16_t touch_value;
|
||||
uint16_t touch_thresh;
|
||||
bool touch_status_current[4] = {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));
|
||||
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)
|
||||
{
|
||||
(*touch_callbacks[touch_id])();
|
||||
}
|
||||
}
|
||||
touch_status[i] = touch_status_current[i];
|
||||
}
|
||||
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void ena_interface_start(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(touch_pad_init());
|
||||
ESP_ERROR_CHECK(touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V));
|
||||
ESP_ERROR_CHECK(touch_pad_set_trigger_mode(TOUCH_TRIGGER_BELOW));
|
||||
|
||||
touch_mapping[0] = TOUCH_PAD_ESC;
|
||||
touch_mapping[1] = TOUCH_PAD_OK;
|
||||
touch_mapping[2] = TOUCH_PAD_UP;
|
||||
touch_mapping[3] = TOUCH_PAD_DOWN;
|
||||
|
||||
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_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));
|
||||
}
|
||||
|
||||
xTaskCreate(&ena_interface_run, "ena_interface_run", configMINIMAL_STACK_SIZE * 4, NULL, 5, NULL);
|
||||
}
|
||||
|
||||
int ena_interface_get_state(void)
|
||||
{
|
||||
return interface_state;
|
||||
}
|
||||
|
||||
void ena_interface_set_state(ena_interface_state state)
|
||||
{
|
||||
interface_state = state;
|
||||
}
|
||||
Reference in New Issue
Block a user