Skip to content

Commit

Permalink
update more
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzw655 committed Nov 2, 2023
1 parent 75af3bc commit bb68d54
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 358 deletions.
39 changes: 3 additions & 36 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
# ChangeLog

## v0.1.3 - 2023-6-2
## v0.0.1 - 2023-11-2

### Enhancements:

* Add power on knob position detection to avoid logical inversion caused by knob position
* Change test to test_apps project

## v0.1.2 - 2023-3-9

### Enhancements:

* Use cu_pkg_define_version to define the version of this component.

## v0.1.1 - 2023-1-18

### Bug Fixes:

* Knob:
* Fix callback return usr_data root pointer, the usr_data of the relevant callback will now be returned.

## v0.1.0 - 2023-1-5

### Enhancements:

* Initial version

* The following types of events are supported

| EVENT | 描述 |
| ---------- | -------------------------------------- |
| KNOB_LEFT | EVENT: Rotate to the left |
| KNOB_RIGHT | EVENT: Rotate to the right |
| KNOB_H_LIM | EVENT: Count reaches maximum limit |
| KNOB_L_LIM | EVENT: Count reaches the minimum limit |
| KNOB_ZERO | EVENT: Count back to 0 |

* Support for defining multiple knobs

* Support binding callback functions for each event and adding user-data
* Support for all ESP SoCs.
* Support multiple events, including `left`, `right`, `high limit`, `low limit`, and `back to zero`.
27 changes: 8 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
[![Arduino Lint](https://github.com/esp-arduino-libs/ESP32_Knob/actions/workflows/arduino_lint.yml/badge.svg)](https://github.com/esp-arduino-libs/ESP32_Knob/actions/workflows/arduino_lint.yml) [![pre-commit](https://github.com/esp-arduino-libs/ESP32_Knob/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/esp-arduino-libs/ESP32_Knob/actions/workflows/pre-commit.yml) [![Build Test Apps](https://github.com/esp-arduino-libs/ESP32_Knob/actions/workflows/build_test.yml/badge.svg)](https://github.com/esp-arduino-libs/ESP32_Knob/actions/workflows/build_test.yml)

# ESP32_Knob

## Component Knob
ESP32_Knob is an Arduino library designed for driving encoders (such as EC11) using ESP SoCs. This library has implemented the quadrature decoding function similar to the ESP PCNT peripheral through software. It is useful for chips that do not have this peripheral, such as ESP32-C2 and ESP32-C3.

`Knob` is the component that provides the software PCNT, it can be used on chips(esp32c2, esp32c3) that do not have PCNT hardware capabilities. By using this component, you can quickly use a physical encoder, such as the EC11 encoder.
ESP32_Knob encapsulates the component from the [Espressif Components Registry](https://components.espressif.com/). It is developed based on [arduino-esp32](https://github.com/espressif/arduino-esp32) and can be easily downloaded and integrated into the Arduino IDE.

Features:
## Features

1. Support multiple knobs
2. Support each event can register its own callback
3. Support setting the upper and lower count limits

List of supported events:

* Knob left
* Knob right
* Knob high limit
* Knob low limit
* Knob back to zero
* Support for all ESP SoCs.
* Support multiple events, including `left`, `right`, `high limit`, `low limit`, and `back to zero`.

## Supported Drivers

Expand Down Expand Up @@ -58,11 +50,8 @@ static void knob_left_cb(void *arg, void *data)
knob->begin();
knob->registerEvent(KNOB_LEFT, knob_left_cb, NULL);

// Release the ESP_IOExpander object
// Release the ESP_Knob object
delete knob;
```
`Note`: This component is only suitable for decoding low-speed rotary encoders such as EC11, and does not guarantee the complete correctness of the pulse count. For high-speed and accurate calculations, please use hardware [PCNT](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-reference/peripherals/pcnt.html?highlight=pcnt)
* | Hardware PCNT Supported Targets | ESP32 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
| ------------------------------- | ----- | -------- | -------- | -------- | -------- |
**Note**: This component is only suitable for decoding low-speed rotary encoders such as EC11, and does not guarantee the complete correctness of the pulse count. For high-speed and accurate calculations, please use hardware [PCNT](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/pcnt.html?highlight=pcnt)
39 changes: 21 additions & 18 deletions examples/TestFunctions/TestFunctions.ino
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
#include <Arduino.h>
#include <ESP_Knob.h>

#define GPIO_KNOB_A 1
#define GPIO_KNOB_B 2
#define GPIO_NUM_KNOB_PIN_A 1
#define GPIO_NUM_KNOB_PIN_B 2

ESP_Knob *knob = new ESP_Knob(GPIO_KNOB_A, GPIO_KNOB_B);
ESP_Knob *knob;

static void knob_left_cb(void *arg, void *data)
void onKnobLeftEventCallback(int count, void *usr_data)
{
Serial.printf("KNOB_LEFT Count is %d\n", knob->getCountValue());
Serial.printf("Detect left event, count is %d\n", count);
}

static void knob_right_cb(void *arg, void *data)
void onKnobRightEventCallback(int count, void *usr_data)
{
Serial.printf("KNOB_RIGHT Count is %d\n", knob->getCountValue());
Serial.printf("Detect right event, count is %d\n", count);
}

static void knob_h_lim_cb(void *arg, void *data)
void onKnobHighLimitEventCallback(int count, void *usr_data)
{
Serial.println("KNOB_H_LIM");
Serial.printf("Detect high limit event, count is %d\n", count);
}

static void knob_l_lim_cb(void *arg, void *data)
void onKnobLowLimitEventCallback(int count, void *usr_data)
{
Serial.println("KNOB_L_LIM");
Serial.printf("Detect low limit event, count is %d\n", count);
}

static void knob_zero_cb(void *arg, void *data)
void onKnobZeroEventCallback(int count, void *usr_data)
{
Serial.println("KNOB_ZERO");
Serial.printf("Detect zero event, count is %d\n", count);
}

void setup() {
Serial.begin(115200);
Serial.println("ESP_Knob example");

knob = new ESP_Knob(GPIO_NUM_KNOB_PIN_A, GPIO_NUM_KNOB_PIN_B);

// knob->invertDirection();
knob->begin();
knob->registerEvent(KNOB_LEFT, knob_left_cb, NULL);
knob->registerEvent(KNOB_RIGHT, knob_right_cb,NULL);
knob->registerEvent(KNOB_H_LIM, knob_h_lim_cb, NULL);
knob->registerEvent(KNOB_L_LIM, knob_l_lim_cb, NULL);
knob->registerEvent(KNOB_ZERO, knob_zero_cb, NULL);
knob->attachLeftEventCallback(onKnobLeftEventCallback);
knob->attachRightEventCallback(onKnobRightEventCallback);
knob->attachHighLimitEventCallback(onKnobHighLimitEventCallback);
knob->attachLowLimitEventCallback(onKnobLowLimitEventCallback);
knob->attachZeroEventCallback(onKnobZeroEventCallback);
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name=ESP32_Knob
version=0.0.1
author=espressif
maintainer=espressif
sentence=ESP32_Knob is a library designed for driving encoders using ESP32 SoCs
sentence=ESP32_Knob is a library designed for driving encoders using ESP SoCs
paragraph=Currently support multiple encoders, such as the EC11.
category=Other
architectures=esp32
Expand Down
Loading

0 comments on commit bb68d54

Please sign in to comment.