nene1234

lilka lvgl navigation

Nov 15th, 2025
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 8.49 KB | None | 0 0
  1. esphome:
  2.   name: lilka
  3.   friendly_name: lilka
  4.   on_boot:
  5.     priority: 600
  6.     then:
  7.       - output.turn_on: display_power
  8.       - delay: 100ms
  9.  
  10. esp32:
  11.   board: esp32-s3-devkitc-1
  12.   framework:
  13.     type: esp-idf
  14.  
  15. logger:
  16. api:
  17.   encryption:
  18.     key: "Yw3yq8lxsaze+jdggjAwxKpV4GD6gNZptvw4d6OPfOc="
  19.  
  20. ota:
  21.   - platform: esphome
  22.     password: "bb198feb99159fdaefc8092f10039acd"
  23.  
  24. wifi:
  25.   ssid: !secret wifi_ssid
  26.   password: !secret wifi_password
  27.   ap:
  28.     ssid: "Lilka Fallback Hotspot"
  29.     password: "hnYImYM4O6I0"
  30.  
  31. captive_portal:
  32. # Веб-сервер
  33. web_server:
  34.   port: 80
  35.  
  36. # Увімкнення живлення дисплея
  37. output:
  38.   - platform: gpio
  39.     pin: 46
  40.     id: display_power
  41.     inverted: false
  42.  
  43. # Сенсор батареї
  44. sensor:
  45.   - platform: adc
  46.     pin: GPIO3
  47.     name: "Battery Voltage"
  48.     id: battery_voltage
  49.     update_interval: 10s
  50.     attenuation: 12db
  51.     filters:
  52.       - multiply: 1.33
  53.    
  54.   - platform: template
  55.     name: "Battery Level"
  56.     id: battery_level
  57.     unit_of_measurement: "%"
  58.     accuracy_decimals: 0
  59.     update_interval: 10s
  60.     lambda: |-
  61.       float voltage = id(battery_voltage).state;
  62.       float percent = (voltage - 3.0) / (4.2 - 3.0) * 100.0;
  63.       if (percent > 100) percent = 100;
  64.       if (percent < 0) percent = 0;
  65.       return percent;
  66.  
  67. # SPI шина
  68. spi:
  69.   clk_pin: 18
  70.   mosi_pin: 17
  71.  
  72. # Дисплей ST7789V
  73. display:
  74.   - platform: mipi_spi
  75.     model: ST7789V
  76.     id: my_display
  77.     dc_pin: 15
  78.     cs_pin: 7
  79.     update_interval: 1s
  80.     rotation: 270
  81.     invert_colors: true
  82.     color_order: BGR
  83.     pixel_mode: 16bit
  84.     dimensions:
  85.       width: 280
  86.       height: 240
  87.       offset_width: 20
  88.       offset_height: 0
  89.     auto_clear_enabled: false
  90.  
  91. # LVGL - з чорним фоном
  92. lvgl:
  93.   log_level: INFO
  94.  
  95.   style_definitions:
  96.     - id: default_style
  97.       bg_color: 0x000000
  98.       text_color: 0xFFFFFF
  99.     - id: focused_style
  100.       border_color: 0xFFFFFF
  101.       border_width: 3
  102.       outline_color: 0xFFFFFF
  103.       outline_width: 2
  104.  
  105.   pages:
  106.     - id: main_page
  107.       bg_color: 0x000000
  108.       widgets:
  109.        # Червона кнопка - Battery %
  110.         - button:
  111.             id: red_button
  112.             align: CENTER
  113.             y: -40
  114.             width: 180
  115.             height: 50
  116.             bg_color: 0xFF0000  # Червоний
  117.             widgets:
  118.               - label:
  119.                   id: battery_label
  120.                   text: "Battery: --"
  121.                   align: CENTER
  122.                   text_color: 0xFFFFFF
  123.        
  124.         # Зелена кнопка - Voltage
  125.         - button:
  126.             id: green_button
  127.             align: CENTER
  128.             y: 20
  129.             width: 180
  130.             height: 50
  131.             bg_color: 0x00FF00  # Зелений
  132.             widgets:
  133.               - label:
  134.                   id: voltage_label
  135.                   text: "Voltage: --"
  136.                   align: CENTER
  137.                   text_color: 0x000000
  138.        
  139.         # Синя кнопка - Lilka LVGL
  140.         - button:
  141.             id: blue_button
  142.             align: CENTER
  143.             y: 80
  144.             width: 180
  145.             height: 50
  146.             bg_color: 0x0000FF  # Синій
  147.             widgets:
  148.               - label:
  149.                   text: "Lilka LVGL"
  150.                   align: CENTER
  151.                   text_color: 0xFFFFFF
  152.  
  153. # Глобальна змінна для відстеження поточної кнопки
  154. globals:
  155.   - id: current_button_index
  156.     type: int
  157.     restore_value: no
  158.     initial_value: '0'
  159.  
  160. # Кнопки керування
  161. binary_sensor:
  162.   - platform: gpio
  163.     pin:
  164.       number: 38
  165.       mode: INPUT_PULLUP
  166.       inverted: true
  167.     name: "Button Up"
  168.     id: button_up
  169.     filters:
  170.       - delayed_on_off: 50ms
  171.     on_press:
  172.       - lambda: |-
  173.           id(current_button_index) -= 1;
  174.           if (id(current_button_index) < 0) id(current_button_index) = 2;
  175.       # Прибираємо обводку з усіх кнопок
  176.       - lvgl.widget.update:
  177.           id: red_button
  178.           border_width: 0
  179.       - lvgl.widget.update:
  180.           id: green_button
  181.           border_width: 0
  182.       - lvgl.widget.update:
  183.           id: blue_button
  184.           border_width: 0
  185.       # Додаємо обводку до вибраної
  186.       - if:
  187.           condition:
  188.             lambda: 'return id(current_button_index) == 0;'
  189.           then:
  190.             - lvgl.widget.update:
  191.                 id: red_button
  192.                 border_width: 3
  193.                 border_color: 0xFFFFFF
  194.       - if:
  195.           condition:
  196.             lambda: 'return id(current_button_index) == 1;'
  197.           then:
  198.             - lvgl.widget.update:
  199.                 id: green_button
  200.                 border_width: 3
  201.                 border_color: 0xFFFFFF
  202.       - if:
  203.           condition:
  204.             lambda: 'return id(current_button_index) == 2;'
  205.           then:
  206.             - lvgl.widget.update:
  207.                 id: blue_button
  208.                 border_width: 3
  209.                 border_color: 0xFFFFFF
  210.    
  211.   - platform: gpio
  212.     pin:
  213.       number: 41
  214.       mode: INPUT_PULLUP
  215.       inverted: true
  216.     name: "Button Down"
  217.     id: button_down
  218.     filters:
  219.       - delayed_on_off: 50ms
  220.     on_press:
  221.       - lambda: |-
  222.           id(current_button_index) += 1;
  223.           if (id(current_button_index) > 2) id(current_button_index) = 0;
  224.       # Прибираємо обводку з усіх кнопок
  225.       - lvgl.widget.update:
  226.           id: red_button
  227.           border_width: 0
  228.       - lvgl.widget.update:
  229.           id: green_button
  230.           border_width: 0
  231.       - lvgl.widget.update:
  232.           id: blue_button
  233.           border_width: 0
  234.       # Додаємо обводку до вибраної
  235.       - if:
  236.           condition:
  237.             lambda: 'return id(current_button_index) == 0;'
  238.           then:
  239.             - lvgl.widget.update:
  240.                 id: red_button
  241.                 border_width: 3
  242.                 border_color: 0xFFFFFF
  243.       - if:
  244.           condition:
  245.             lambda: 'return id(current_button_index) == 1;'
  246.           then:
  247.             - lvgl.widget.update:
  248.                 id: green_button
  249.                 border_width: 3
  250.                 border_color: 0xFFFFFF
  251.       - if:
  252.           condition:
  253.             lambda: 'return id(current_button_index) == 2;'
  254.           then:
  255.             - lvgl.widget.update:
  256.                 id: blue_button
  257.                 border_width: 3
  258.                 border_color: 0xFFFFFF
  259.    
  260.   - platform: gpio
  261.     pin:
  262.       number: 39
  263.       mode: INPUT_PULLUP
  264.       inverted: true
  265.     name: "Button Left"
  266.     id: button_left
  267.     filters:
  268.       - delayed_on_off: 50ms
  269.    
  270.   - platform: gpio
  271.     pin:
  272.       number: 40
  273.       mode: INPUT_PULLUP
  274.       inverted: true
  275.     name: "Button Right"
  276.     id: button_right
  277.     filters:
  278.       - delayed_on_off: 50ms
  279.  
  280.   - platform: gpio
  281.     pin:
  282.       number: 5
  283.       mode: INPUT_PULLUP
  284.       inverted: true
  285.     name: "Button A"
  286.     id: button_a
  287.     filters:
  288.       - delayed_on_off: 50ms
  289.    
  290.   - platform: gpio
  291.     pin:
  292.       number: 6
  293.       mode: INPUT_PULLUP
  294.       inverted: true
  295.     name: "Button B"
  296.     id: button_b
  297.     filters:
  298.       - delayed_on_off: 50ms
  299.  
  300.   - platform: gpio
  301.     pin:
  302.       number: 10
  303.       mode: INPUT_PULLUP
  304.       inverted: true
  305.     name: "Button C"
  306.     id: button_c
  307.     filters:
  308.       - delayed_on_off: 50ms
  309.  
  310.   - platform: gpio
  311.     pin:
  312.       number: 9
  313.       mode: INPUT_PULLUP
  314.       inverted: true
  315.     name: "Button D"
  316.     id: button_d
  317.     filters:
  318.       - delayed_on_off: 50ms
  319.  
  320.   - platform: gpio
  321.     pin:
  322.       number: 4
  323.       mode: INPUT_PULLUP
  324.       inverted: true
  325.     name: "Button Start"
  326.     id: button_start
  327.     filters:
  328.       - delayed_on_off: 50ms
  329.  
  330.   - platform: gpio
  331.     pin:
  332.       number: 0
  333.       mode: INPUT_PULLUP
  334.       inverted: true
  335.     name: "Button Select"
  336.     id: button_select
  337.     filters:
  338.       - delayed_on_off: 50ms
  339.  
  340. # Оновлення даних на кнопках
  341. interval:
  342.   - interval: 5s
  343.     then:
  344.       - lvgl.label.update:
  345.           id: battery_label
  346.           text: !lambda |-
  347.             return std::string("Battery: ") + to_string((int)id(battery_level).state) + "%";
  348.       - lvgl.label.update:
  349.           id: voltage_label
  350.           text: !lambda |-
  351.             char buf[20];
  352.             snprintf(buf, sizeof(buf), "Voltage: %.2fV", id(battery_voltage).state);
  353.             return std::string(buf);
Advertisement
Add Comment
Please, Sign In to add comment