Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
hayschan committed Jan 19, 2024
1 parent 9a0a814 commit 0462cc2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
2 changes: 0 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

# set(EXTRA_COMPONENT_DIRS ../../MAX6675)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_compile_options("-Wno-format")
get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME)
Expand Down
2 changes: 1 addition & 1 deletion example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# for more information about component CMakeLists.txt files.

idf_component_register(
SRCS "max6675_example_test.c" # list the source files of this component
SRCS "dwin_example_test.cpp" # list the source files of this component
INCLUDE_DIRS "../../include" # optional, add here public include directories
)
42 changes: 42 additions & 0 deletions example/main/dwin_example_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// dwin_example_test.cpp

#include "DWIN.h"

#define ADDRESS_A "1010"
#define ADDRESS_B "1020"

#define DGUS_BAUD 115200
#define RX_PIN 16 // Set these according to your ESP32's pinout
#define TX_PIN 17

// Create an instance of the DWIN class
DWIN hmi(UART_NUM_1, RX_PIN, TX_PIN, DGUS_BAUD);

void hmi_listen_task(void * args)
{
while (1) {
hmi.listen(); // Listen HMI Events
vTaskDelay(10 / portTICK_PERIOD_MS); // Add a small delay to allow other tasks to run
}
}

// Event Occurs when response comes from HMI
void onHMIEvent(std::string address, int lastByte, std::string message, std::string response) {
ESP_LOGI("HMIEvent", "OnEvent : [ A : %s | D : %02X | M : %s | R : %s ]", address.c_str(), lastByte, message.c_str(), response.c_str());
if (address == "1002") {
// Take your custom action call
}
}

extern "C" void app_main() {
// Initialize logging
esp_log_level_set("*", ESP_LOG_INFO);

ESP_LOGI("HMI", "DWIN HMI ~ Hello World");
hmi.echoEnabled(false);
hmi.hmiCallBack(onHMIEvent);
hmi.setPage(1);

// Create a task for hmi.listen() to run in
xTaskCreate(hmi_listen_task, "hmi_listen_task", 4096, NULL, 5, NULL);
}
2 changes: 1 addition & 1 deletion example/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies:
hayschan/max6675:
hayschan/dwin-hmi-esp:
version: "*"
override_path: '../../'
19 changes: 0 additions & 19 deletions example/main/max6675_example_test.c

This file was deleted.

0 comments on commit 0462cc2

Please sign in to comment.