Created
February 17, 2024 21:29
-
-
Save maxpromer/420f5aa4d591767094b38e068320a636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <lvgl.h> | |
#include <ATD3.5-S3.h> | |
#include "gui/ui.h" | |
#include "driver/gpio.h" | |
#include "driver/twai.h" | |
#define CAN_TX_PIN GPIO_NUM_1 | |
#define CAN_RX_PIN GPIO_NUM_2 | |
void setup() { | |
Serial.begin(115200); | |
// Setup peripherals | |
Display.begin(0); // rotation number 0 | |
Touch.begin(); | |
Sound.begin(); | |
// Card.begin(); // uncomment if you want to Read/Write/Play/Load file in MicroSD Card | |
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(CAN_TX_PIN, CAN_RX_PIN, TWAI_MODE_NORMAL); | |
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_125KBITS(); | |
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); | |
// Install TWAI driver | |
if (twai_driver_install(&g_config, &t_config, &f_config) != ESP_OK) { | |
Serial.printf("Failed to install driver\n"); | |
return; | |
} | |
// Start TWAI driver | |
if (twai_start() != ESP_OK) { | |
Serial.printf("Failed to start driver\n"); | |
return; | |
} | |
// Map peripheral to LVGL | |
Display.useLVGL(); // Map display to LVGL | |
Touch.useLVGL(); // Map touch screen to LVGL | |
Sound.useLVGL(); // Map speaker to LVGL | |
// Card.useLVGL(); // Map MicroSD Card to LVGL File System | |
// Add load your UI function | |
ui_init(); | |
// Add event handle | |
} | |
void loop() { | |
Display.loop(); // Keep GUI work | |
twai_message_t message; | |
if (twai_receive(&message, 0) == ESP_OK) { | |
uint16_t adc = (message.data[0] << 8) | message.data[1]; | |
lv_arc_set_value(ui_adc_value_arc, adc); | |
lv_label_set_text_fmt(ui_adc_value_label, "%d", adc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment