mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-24 06:47:17 +00:00
Fixed conflict. Changed to SO125
This commit is contained in:
commit
f3cedc91a0
40
.github/workflows/CI_github_ESP32.yml
vendored
40
.github/workflows/CI_github_ESP32.yml
vendored
@ -104,46 +104,6 @@ jobs:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
tasmota32-knx:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -U platformio
|
||||
platformio upgrade --dev
|
||||
platformio update
|
||||
- name: Run PlatformIO
|
||||
run: |
|
||||
platformio run -e tasmota32-knx
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
tasmota32-sensors:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -U platformio
|
||||
platformio upgrade --dev
|
||||
platformio update
|
||||
- name: Run PlatformIO
|
||||
run: |
|
||||
platformio run -e tasmota32-sensors
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
tasmota32-display:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
42
.github/workflows/Tasmota_build.yml
vendored
42
.github/workflows/Tasmota_build.yml
vendored
@ -804,46 +804,6 @@ jobs:
|
||||
path: ./build_output
|
||||
|
||||
|
||||
tasmota32-knx:
|
||||
needs: tasmota_pull
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install -U platformio
|
||||
- name: Run PlatformIO
|
||||
run: |
|
||||
platformio run -e tasmota32-knx
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
|
||||
tasmota32-sensors:
|
||||
needs: tasmota_pull
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install -U platformio
|
||||
- name: Run PlatformIO
|
||||
run: |
|
||||
platformio run -e tasmota32-sensors
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
|
||||
tasmota32-display:
|
||||
needs: tasmota_pull
|
||||
runs-on: ubuntu-latest
|
||||
@ -1434,14 +1394,12 @@ jobs:
|
||||
[ ! -f ./mv_firmware/firmware/tasmota-knx.* ] || mv ./mv_firmware/firmware/tasmota-knx.* ./firmware/tasmota/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota-zbbridge.* ] || mv ./mv_firmware/firmware/tasmota-zbbridge.* ./firmware/tasmota/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32.* ] || mv ./mv_firmware/firmware/tasmota32.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-sensors.* ] || mv ./mv_firmware/firmware/tasmota32-sensors.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-ir*.* ] || mv ./mv_firmware/firmware/tasmota32-ir*.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-display.* ] || mv ./mv_firmware/firmware/tasmota32-display.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-web*.* ] || mv ./mv_firmware/firmware/tasmota32-web*.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-odroidgo.* ] || mv ./mv_firmware/firmware/tasmota32-odroidgo.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-core2.* ] || mv ./mv_firmware/firmware/tasmota32-core2.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-bluetooth.* ] || mv ./mv_firmware/firmware/tasmota32-bluetooth.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-knx.* ] || mv ./mv_firmware/firmware/tasmota32-knx.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32* ] || mv ./mv_firmware/firmware/tasmota32* ./firmware/tasmota32/languages/
|
||||
[ ! -f ./mv_firmware/firmware/* ] || mv ./mv_firmware/firmware/* ./firmware/tasmota/languages/
|
||||
[ ! -f ./tools/Esptool/ESP32/*.* ] || mv ./tools/Esptool/ESP32/*.* ./firmware/tasmota32/ESP32_needed_files/
|
||||
|
42
.github/workflows/Tasmota_build_master.yml
vendored
42
.github/workflows/Tasmota_build_master.yml
vendored
@ -804,46 +804,6 @@ jobs:
|
||||
path: ./build_output
|
||||
|
||||
|
||||
tasmota32-knx:
|
||||
needs: tasmota_pull
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install -U platformio
|
||||
- name: Run PlatformIO
|
||||
run: |
|
||||
platformio run -e tasmota32-knx
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
|
||||
tasmota32-sensors:
|
||||
needs: tasmota_pull
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install -U platformio
|
||||
- name: Run PlatformIO
|
||||
run: |
|
||||
platformio run -e tasmota32-sensors
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: firmware
|
||||
path: ./build_output
|
||||
|
||||
|
||||
tasmota32-display:
|
||||
needs: tasmota_pull
|
||||
runs-on: ubuntu-latest
|
||||
@ -1434,14 +1394,12 @@ jobs:
|
||||
[ ! -f ./mv_firmware/firmware/tasmota-knx.* ] || mv ./mv_firmware/firmware/tasmota-knx.* ./firmware/tasmota/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota-zbbridge.* ] || mv ./mv_firmware/firmware/tasmota-zbbridge.* ./firmware/tasmota/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32.* ] || mv ./mv_firmware/firmware/tasmota32.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-sensors.* ] || mv ./mv_firmware/firmware/tasmota32-sensors.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-ir*.* ] || mv ./mv_firmware/firmware/tasmota32-ir*.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-display.* ] || mv ./mv_firmware/firmware/tasmota32-display.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-web*.* ] || mv ./mv_firmware/firmware/tasmota32-web*.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-odroidgo.* ] || mv ./mv_firmware/firmware/tasmota32-odroidgo.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-core2.* ] || mv ./mv_firmware/firmware/tasmota32-core2.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-bluetooth.* ] || mv ./mv_firmware/firmware/tasmota32-bluetooth.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32-knx.* ] || mv ./mv_firmware/firmware/tasmota32-knx.* ./firmware/tasmota32/
|
||||
[ ! -f ./mv_firmware/firmware/tasmota32* ] || mv ./mv_firmware/firmware/tasmota32* ./firmware/tasmota32/languages/
|
||||
[ ! -f ./mv_firmware/firmware/* ] || mv ./mv_firmware/firmware/* ./firmware/tasmota/languages/
|
||||
[ ! -f ./tools/Esptool/ESP32/*.* ] || mv ./tools/Esptool/ESP32/*.* ./firmware/tasmota32/ESP32_needed_files/
|
||||
|
12
CHANGELOG.md
12
CHANGELOG.md
@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased] - Development
|
||||
|
||||
## [9.3.1.2]
|
||||
### Added
|
||||
- Commands ``MqttKeepAlive 1..100`` to set Mqtt Keep Alive timer (default 30) and ``MqttTimeout 1..100`` to set Mqtt Socket Timeout (default 4) (#5341)
|
||||
- Support for TM1638 seven segment display by Ajith Vasudevan (#11031)
|
||||
|
||||
### Changed
|
||||
- PubSubClient library from EspEasy v2.7.12 to Tasmota v2.8.12
|
||||
|
||||
## [9.3.1.1]
|
||||
### Added
|
||||
- Support for CSE7761 energy monitor as used in ESP32 based Sonoff Dual R3 Pow (#10793)
|
||||
@ -16,11 +24,9 @@ All notable changes to this project will be documented in this file.
|
||||
- Crash protection in ext_vnsprintf_P (#11202)
|
||||
- Extent compile time SetOptions support (#11204)
|
||||
- ESP32 Extent BLE (#11212)
|
||||
|
||||
- ESP32 support for WS2812 hardware driver via RMT or I2S
|
||||
|
||||
- ESP32 support for secondary I2C controller
|
||||
|
||||
- Support for MPU6886 on primary or secondary I2C bus
|
||||
|
||||
### Changed
|
||||
- ESP32 core library from v1.0.5-rc6 to v1.0.5
|
||||
|
@ -91,3 +91,4 @@ Index | Define | Driver | Device | Address(es) | Description
|
||||
55 | USE_EZOPMP | xsns_78 | EZOPMP | 0x61 - 0x70 | Peristaltic Pump
|
||||
56 | USE_SEESAW_SOIL | xsns_81 | SEESOIL | 0x36 - 0x39 | Adafruit seesaw soil moisture sensor
|
||||
57 | USE_TOF10120 | xsns_84 | TOF10120 | 0x52 | Time-of-flight (ToF) distance sensor
|
||||
58 | USE_MPU6886 | xsns_85 | MPU6886 | 0x68 | MPU6886 M5Stack
|
@ -78,14 +78,16 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
|
||||
|
||||
[Complete list](BUILDS.md) of available feature and sensors.
|
||||
|
||||
## Changelog v9.3.1.1
|
||||
## Changelog v9.3.1.2
|
||||
### Added
|
||||
- Commands ``MqttKeepAlive 1..100`` to set Mqtt Keep Alive timer (default 30) and ``MqttTimeout 1..100`` to set Mqtt Socket Timeout (default 4) [#5341](https://github.com/arendst/Tasmota/issues/5341)
|
||||
- Command ``Sensor80 1 <0..7>`` to control MFRC522 RFID antenna gain from 18dB (0) to 48dB (7) [#11073](https://github.com/arendst/Tasmota/issues/11073)
|
||||
- Support for SML VBUS [#11125](https://github.com/arendst/Tasmota/issues/11125)
|
||||
- Support for NEC and OPTOMA LCD/DLP Projector serial power control by Jan Bubík [#11145](https://github.com/arendst/Tasmota/issues/11145)
|
||||
- Support for XPT2046 touch screen digitizer on ILI9341 display by nonix [#11159](https://github.com/arendst/Tasmota/issues/11159)
|
||||
- Support for zigbee lumi.sensor_wleak [#11200](https://github.com/arendst/Tasmota/issues/11200)
|
||||
- Support for CSE7761 energy monitor as used in ESP32 based Sonoff Dual R3 Pow [#10793](https://github.com/arendst/Tasmota/issues/10793)
|
||||
- Support for TM1638 seven segment display by Ajith Vasudevan [#11031](https://github.com/arendst/Tasmota/issues/11031)
|
||||
- Allow MCP230xx pinmode from output to input [#11104](https://github.com/arendst/Tasmota/issues/11104)
|
||||
- Berry improvements [#11163](https://github.com/arendst/Tasmota/issues/11163)
|
||||
- Extent compile time SetOptions support [#11204](https://github.com/arendst/Tasmota/issues/11204)
|
||||
@ -93,6 +95,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
|
||||
|
||||
### Changed
|
||||
- TasmotaSerial library from v3.2.0 to v3.3.0
|
||||
- PubSubClient library from EspEasy v2.7.12 to Tasmota v2.8.12
|
||||
- ESP32 core library from v1.0.5-rc6 to v1.0.5
|
||||
- TuyaMcu dimmer timeout [#11121](https://github.com/arendst/Tasmota/issues/11121)
|
||||
- Rename epaper 42 commands [#11222](https://github.com/arendst/Tasmota/issues/11222)
|
||||
|
5
eMyloEAI90.txt
Normal file
5
eMyloEAI90.txt
Normal file
@ -0,0 +1,5 @@
|
||||
Template TuyaMCU(54)
|
||||
|
||||
Console:
|
||||
Backlog SetOption66 1; TuyaMCU 11,16; TuyaMCU 36,6; TuyaMCU 37,1; SetOption59 1; SetOption72 1
|
||||
Rule1 on System#Boot do RuleTimer1 10 endon on Rules#Timer=1 do backlog TuyaSend8; RuleTimer1 10 endon
|
@ -1 +0,0 @@
|
||||
tests/bin
|
5
lib/default/pubsubclient-2.8.12/.gitignore
vendored
Normal file
5
lib/default/pubsubclient-2.8.12/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
tests/bin
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
@ -1,3 +1,12 @@
|
||||
2.8
|
||||
* Add setBufferSize() to override MQTT_MAX_PACKET_SIZE
|
||||
* Add setKeepAlive() to override MQTT_KEEPALIVE
|
||||
* Add setSocketTimeout() to overide MQTT_SOCKET_TIMEOUT
|
||||
* Added check to prevent subscribe/unsubscribe to empty topics
|
||||
* Declare wifi mode prior to connect in ESP example
|
||||
* Use `strnlen` to avoid overruns
|
||||
* Support pre-connected Client objects
|
||||
|
||||
2.7
|
||||
* Fix remaining-length handling to prevent buffer overrun
|
||||
* Add large-payload API - beginPublish/write/publish/endPublish
|
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2008-2015 Nicholas O'Leary
|
||||
Copyright (c) 2008-2020 Nicholas O'Leary
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
@ -13,10 +13,12 @@ Full API documentation is available here: https://pubsubclient.knolleary.net
|
||||
## Limitations
|
||||
|
||||
- It can only publish QoS 0 messages. It can subscribe at QoS 0 or QoS 1.
|
||||
- The maximum message size, including header, is **128 bytes** by default. This
|
||||
is configurable via `MQTT_MAX_PACKET_SIZE` in `PubSubClient.h`.
|
||||
- The maximum message size, including header, is **256 bytes** by default. This
|
||||
is configurable via `MQTT_MAX_PACKET_SIZE` in `PubSubClient.h` or can be changed
|
||||
by calling `PubSubClient::setBufferSize(size)`.
|
||||
- The keepalive interval is set to 15 seconds by default. This is configurable
|
||||
via `MQTT_KEEPALIVE` in `PubSubClient.h`.
|
||||
via `MQTT_KEEPALIVE` in `PubSubClient.h` or can be changed by calling
|
||||
`PubSubClient::setKeepAlive(keepAlive)`.
|
||||
- The client uses MQTT 3.1.1 by default. It can be changed to use MQTT 3.1 by
|
||||
changing value of `MQTT_VERSION` in `PubSubClient.h`.
|
||||
|
@ -27,9 +27,9 @@ void setup()
|
||||
{
|
||||
Ethernet.begin(mac, ip);
|
||||
// Note - the default maximum packet size is 128 bytes. If the
|
||||
// combined length of clientId, username and password exceed this,
|
||||
// you will need to increase the value of MQTT_MAX_PACKET_SIZE in
|
||||
// PubSubClient.h
|
||||
// combined length of clientId, username and password exceed this use the
|
||||
// following to increase the buffer size:
|
||||
// client.setBufferSize(255);
|
||||
|
||||
if (client.connect("arduinoClient", "testuser", "testpass")) {
|
||||
client.publish("outTopic","hello world");
|
@ -1,26 +1,21 @@
|
||||
/*
|
||||
Basic ESP8266 MQTT example
|
||||
|
||||
This sketch demonstrates the capabilities of the pubsub library in combination
|
||||
with the ESP8266 board/library.
|
||||
|
||||
It connects to an MQTT server then:
|
||||
- publishes "hello world" to the topic "outTopic" every two seconds
|
||||
- subscribes to the topic "inTopic", printing out any messages
|
||||
it receives. NB - it assumes the received payloads are strings not binary
|
||||
- If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
|
||||
else switch it off
|
||||
|
||||
It will reconnect to the server if the connection is lost using a blocking
|
||||
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
|
||||
achieve the same result without blocking the main loop.
|
||||
|
||||
To install the ESP8266 board, (using Arduino 1.6.4+):
|
||||
- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
|
||||
http://arduino.esp8266.com/stable/package_esp8266com_index.json
|
||||
- Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
|
||||
- Select your ESP8266 in "Tools -> Board"
|
||||
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
@ -34,8 +29,9 @@ const char* mqtt_server = "broker.mqtt-dashboard.com";
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
long lastMsg = 0;
|
||||
char msg[50];
|
||||
unsigned long lastMsg = 0;
|
||||
#define MSG_BUFFER_SIZE (50)
|
||||
char msg[MSG_BUFFER_SIZE];
|
||||
int value = 0;
|
||||
|
||||
void setup_wifi() {
|
||||
@ -46,6 +42,7 @@ void setup_wifi() {
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
@ -120,11 +117,11 @@ void loop() {
|
||||
}
|
||||
client.loop();
|
||||
|
||||
long now = millis();
|
||||
unsigned long now = millis();
|
||||
if (now - lastMsg > 2000) {
|
||||
lastMsg = now;
|
||||
++value;
|
||||
snprintf (msg, 50, "hello world #%ld", value);
|
||||
snprintf (msg, MSG_BUFFER_SIZE, "hello world #%ld", value);
|
||||
Serial.print("Publish message: ");
|
||||
Serial.println(msg);
|
||||
client.publish("outTopic", msg);
|
@ -27,6 +27,9 @@ setServer KEYWORD2
|
||||
setCallback KEYWORD2
|
||||
setClient KEYWORD2
|
||||
setStream KEYWORD2
|
||||
setKeepAlive KEYWORD2
|
||||
setBufferSize KEYWORD2
|
||||
setSocketTimeout KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
@ -6,9 +6,13 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/knolleary/pubsubclient.git"
|
||||
},
|
||||
"version": "2.7",
|
||||
"version": "2.8",
|
||||
"exclude": "tests",
|
||||
"examples": "examples/*/*.ino",
|
||||
"frameworks": "arduino",
|
||||
"platforms": ["espressif8266", "espressif32"]
|
||||
"platforms": [
|
||||
"atmelavr",
|
||||
"espressif8266",
|
||||
"espressif32"
|
||||
]
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
name=PubSubClient
|
||||
version=2.7
|
||||
version=2.8
|
||||
author=Nick O'Leary <nick.oleary@gmail.com>
|
||||
maintainer=Nick O'Leary <nick.oleary@gmail.com>
|
||||
sentence=A client library for MQTT messaging.
|
@ -12,12 +12,20 @@ PubSubClient::PubSubClient() {
|
||||
this->_client = NULL;
|
||||
this->stream = NULL;
|
||||
setCallback(NULL);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
|
||||
PubSubClient::PubSubClient(Client& client) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client) {
|
||||
@ -25,12 +33,20 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client) {
|
||||
setServer(addr, port);
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, Client& client, Stream& stream) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
setServer(addr,port);
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@ -38,6 +54,10 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATUR
|
||||
setCallback(callback);
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@ -45,6 +65,10 @@ PubSubClient::PubSubClient(IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATUR
|
||||
setCallback(callback);
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client) {
|
||||
@ -52,12 +76,20 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client) {
|
||||
setServer(ip, port);
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, Client& client, Stream& stream) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
setServer(ip,port);
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@ -65,6 +97,10 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE,
|
||||
setCallback(callback);
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@ -72,6 +108,10 @@ PubSubClient::PubSubClient(uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE,
|
||||
setCallback(callback);
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client) {
|
||||
@ -79,12 +119,20 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client) {
|
||||
setServer(domain,port);
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, Client& client, Stream& stream) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
setServer(domain,port);
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@ -92,6 +140,10 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGN
|
||||
setCallback(callback);
|
||||
setClient(client);
|
||||
this->stream = NULL;
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client& client, Stream& stream) {
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
@ -99,6 +151,14 @@ PubSubClient::PubSubClient(const char* domain, uint16_t port, MQTT_CALLBACK_SIGN
|
||||
setCallback(callback);
|
||||
setClient(client);
|
||||
setStream(stream);
|
||||
this->bufferSize = 0;
|
||||
setBufferSize(MQTT_MAX_PACKET_SIZE);
|
||||
setKeepAlive(MQTT_KEEPALIVE);
|
||||
setSocketTimeout(MQTT_SOCKET_TIMEOUT);
|
||||
}
|
||||
|
||||
PubSubClient::~PubSubClient() {
|
||||
free(this->buffer);
|
||||
}
|
||||
|
||||
boolean PubSubClient::connect(const char *id) {
|
||||
@ -121,18 +181,29 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass
|
||||
if (!connected()) {
|
||||
int result = 0;
|
||||
|
||||
// Start Tasmota patch
|
||||
if (_client == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (_client->connected()) {
|
||||
// End Tasmota patch
|
||||
|
||||
if(_client->connected()) {
|
||||
result = 1;
|
||||
} else {
|
||||
|
||||
// Start Tasmota patch
|
||||
// if (domain != NULL) {
|
||||
// result = _client->connect(this->domain, this->port);
|
||||
|
||||
if (domain.length() != 0) {
|
||||
result = _client->connect(this->domain.c_str(), this->port);
|
||||
// End Tasmota patch
|
||||
|
||||
} else {
|
||||
result = _client->connect(this->ip, this->port);
|
||||
}
|
||||
}
|
||||
|
||||
if (result == 1) {
|
||||
nextMsgId = 1;
|
||||
// Leave room in the buffer for header and variable length field
|
||||
@ -147,7 +218,7 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass
|
||||
#define MQTT_HEADER_VERSION_LENGTH 7
|
||||
#endif
|
||||
for (j = 0;j<MQTT_HEADER_VERSION_LENGTH;j++) {
|
||||
buffer[length++] = d[j];
|
||||
this->buffer[length++] = d[j];
|
||||
}
|
||||
|
||||
uint8_t v;
|
||||
@ -167,45 +238,48 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass
|
||||
v = v|(0x80>>1);
|
||||
}
|
||||
}
|
||||
this->buffer[length++] = v;
|
||||
|
||||
buffer[length++] = v;
|
||||
|
||||
buffer[length++] = ((MQTT_KEEPALIVE) >> 8);
|
||||
buffer[length++] = ((MQTT_KEEPALIVE) & 0xFF);
|
||||
this->buffer[length++] = ((this->keepAlive) >> 8);
|
||||
this->buffer[length++] = ((this->keepAlive) & 0xFF);
|
||||
|
||||
CHECK_STRING_LENGTH(length,id)
|
||||
length = writeString(id,buffer,length);
|
||||
length = writeString(id,this->buffer,length);
|
||||
if (willTopic) {
|
||||
CHECK_STRING_LENGTH(length,willTopic)
|
||||
length = writeString(willTopic,buffer,length);
|
||||
length = writeString(willTopic,this->buffer,length);
|
||||
CHECK_STRING_LENGTH(length,willMessage)
|
||||
length = writeString(willMessage,buffer,length);
|
||||
length = writeString(willMessage,this->buffer,length);
|
||||
}
|
||||
|
||||
if(user != NULL) {
|
||||
CHECK_STRING_LENGTH(length,user)
|
||||
length = writeString(user,buffer,length);
|
||||
length = writeString(user,this->buffer,length);
|
||||
if(pass != NULL) {
|
||||
CHECK_STRING_LENGTH(length,pass)
|
||||
length = writeString(pass,buffer,length);
|
||||
length = writeString(pass,this->buffer,length);
|
||||
}
|
||||
}
|
||||
|
||||
write(MQTTCONNECT,buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
write(MQTTCONNECT,this->buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
|
||||
lastInActivity = lastOutActivity = millis();
|
||||
|
||||
while (!_client->available()) {
|
||||
|
||||
// Start Tasmota patch
|
||||
delay(0); // Prevent watchdog crashes
|
||||
// End Tasmota patch
|
||||
|
||||
unsigned long t = millis();
|
||||
if (t-lastInActivity >= ((int32_t) MQTT_SOCKET_TIMEOUT*1000UL)) {
|
||||
if (t-lastInActivity >= ((int32_t) this->socketTimeout*1000UL)) {
|
||||
_state = MQTT_CONNECTION_TIMEOUT;
|
||||
_client->stop();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
uint8_t llen;
|
||||
uint16_t len = readPacket(&llen);
|
||||
uint32_t len = readPacket(&llen);
|
||||
|
||||
if (len == 4) {
|
||||
if (buffer[3] == 0) {
|
||||
@ -228,14 +302,24 @@ boolean PubSubClient::connect(const char *id, const char *user, const char *pass
|
||||
|
||||
// reads a byte into result
|
||||
boolean PubSubClient::readByte(uint8_t * result) {
|
||||
|
||||
// Start Tasmota patch
|
||||
if (_client == nullptr) {
|
||||
return false;
|
||||
}
|
||||
// End Tasmota patch
|
||||
|
||||
uint32_t previousMillis = millis();
|
||||
while(!_client->available()) {
|
||||
|
||||
// Start Tasmota patch
|
||||
// yield();
|
||||
|
||||
delay(1); // Prevent watchdog crashes
|
||||
// End Tasmota patch
|
||||
|
||||
uint32_t currentMillis = millis();
|
||||
if(currentMillis - previousMillis >= ((int32_t) MQTT_SOCKET_TIMEOUT * 1000)){
|
||||
if(currentMillis - previousMillis >= ((int32_t) this->socketTimeout * 1000)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -254,15 +338,15 @@ boolean PubSubClient::readByte(uint8_t * result, uint16_t * index){
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
|
||||
uint32_t PubSubClient::readPacket(uint8_t* lengthLength) {
|
||||
uint16_t len = 0;
|
||||
if(!readByte(buffer, &len)) return 0;
|
||||
bool isPublish = (buffer[0]&0xF0) == MQTTPUBLISH;
|
||||
if(!readByte(this->buffer, &len)) return 0;
|
||||
bool isPublish = (this->buffer[0]&0xF0) == MQTTPUBLISH;
|
||||
uint32_t multiplier = 1;
|
||||
uint16_t length = 0;
|
||||
uint32_t length = 0;
|
||||
uint8_t digit = 0;
|
||||
uint16_t skip = 0;
|
||||
uint8_t start = 0;
|
||||
uint32_t start = 0;
|
||||
|
||||
do {
|
||||
if (len == 5) {
|
||||
@ -272,59 +356,75 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
|
||||
return 0;
|
||||
}
|
||||
if(!readByte(&digit)) return 0;
|
||||
buffer[len++] = digit;
|
||||
this->buffer[len++] = digit;
|
||||
length += (digit & 127) * multiplier;
|
||||
multiplier *= 128;
|
||||
} while ((digit & 128) != 0 && len < (MQTT_MAX_PACKET_SIZE -2));
|
||||
multiplier <<=7; //multiplier *= 128
|
||||
|
||||
// Start Tasmota patch
|
||||
// } while ((digit & 128) != 0);
|
||||
|
||||
} while ((digit & 128) != 0 && len < (this->bufferSize -2));
|
||||
// End Tasmota patch
|
||||
|
||||
*lengthLength = len-1;
|
||||
|
||||
if (isPublish) {
|
||||
// Read in topic length to calculate bytes to skip over for Stream writing
|
||||
if(!readByte(buffer, &len)) return 0;
|
||||
if(!readByte(buffer, &len)) return 0;
|
||||
skip = (buffer[*lengthLength+1]<<8)+buffer[*lengthLength+2];
|
||||
if(!readByte(this->buffer, &len)) return 0;
|
||||
if(!readByte(this->buffer, &len)) return 0;
|
||||
skip = (this->buffer[*lengthLength+1]<<8)+this->buffer[*lengthLength+2];
|
||||
start = 2;
|
||||
if (buffer[0]&MQTTQOS1) {
|
||||
if (this->buffer[0]&MQTTQOS1) {
|
||||
// skip message id
|
||||
skip += 2;
|
||||
}
|
||||
}
|
||||
uint32_t idx = len;
|
||||
|
||||
for (uint16_t i = start;i<length;i++) {
|
||||
for (uint32_t i = start;i<length;i++) {
|
||||
if(!readByte(&digit)) return 0;
|
||||
if (this->stream) {
|
||||
if (isPublish && len-*lengthLength-2>skip) {
|
||||
if (isPublish && idx-*lengthLength-2>skip) {
|
||||
this->stream->write(digit);
|
||||
}
|
||||
}
|
||||
if (len < MQTT_MAX_PACKET_SIZE) {
|
||||
buffer[len] = digit;
|
||||
|
||||
if (len < this->bufferSize) {
|
||||
this->buffer[len] = digit;
|
||||
len++;
|
||||
}
|
||||
len++;
|
||||
idx++;
|
||||
}
|
||||
|
||||
if (!this->stream && len > MQTT_MAX_PACKET_SIZE) {
|
||||
if (!this->stream && idx > this->bufferSize) {
|
||||
len = 0; // This will cause the packet to be ignored.
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
boolean PubSubClient::loop() {
|
||||
if (connected()) {
|
||||
unsigned long t = millis();
|
||||
if ((t - lastInActivity > MQTT_KEEPALIVE*1000UL) || (t - lastOutActivity > MQTT_KEEPALIVE*1000UL)) {
|
||||
if ((t - lastInActivity > this->keepAlive*1000UL) || (t - lastOutActivity > this->keepAlive*1000UL)) {
|
||||
if (pingOutstanding) {
|
||||
this->_state = MQTT_CONNECTION_TIMEOUT;
|
||||
_client->stop();
|
||||
return false;
|
||||
} else {
|
||||
buffer[0] = MQTTPINGREQ;
|
||||
buffer[1] = 0;
|
||||
if (_client->write(buffer,2) != 0) {
|
||||
this->buffer[0] = MQTTPINGREQ;
|
||||
this->buffer[1] = 0;
|
||||
|
||||
// Start Tasmota patch
|
||||
// _client->write(this->buffer,2);
|
||||
// lastOutActivity = t;
|
||||
// lastInActivity = t;
|
||||
|
||||
if (_client->write(this->buffer,2) != 0) {
|
||||
lastOutActivity = t;
|
||||
lastInActivity = t;
|
||||
}
|
||||
// End Tasmota patch
|
||||
|
||||
pingOutstanding = true;
|
||||
}
|
||||
}
|
||||
@ -335,35 +435,42 @@ boolean PubSubClient::loop() {
|
||||
uint8_t *payload;
|
||||
if (len > 0) {
|
||||
lastInActivity = t;
|
||||
uint8_t type = buffer[0]&0xF0;
|
||||
uint8_t type = this->buffer[0]&0xF0;
|
||||
if (type == MQTTPUBLISH) {
|
||||
if (callback) {
|
||||
uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2]; /* topic length in bytes */
|
||||
memmove(buffer+llen+2,buffer+llen+3,tl); /* move topic inside buffer 1 byte to front */
|
||||
buffer[llen+2+tl] = 0; /* end the topic as a 'C' string with \x00 */
|
||||
char *topic = (char*) buffer+llen+2;
|
||||
uint16_t tl = (this->buffer[llen+1]<<8)+this->buffer[llen+2]; /* topic length in bytes */
|
||||
memmove(this->buffer+llen+2,this->buffer+llen+3,tl); /* move topic inside buffer 1 byte to front */
|
||||
this->buffer[llen+2+tl] = 0; /* end the topic as a 'C' string with \x00 */
|
||||
char *topic = (char*) this->buffer+llen+2;
|
||||
// msgId only present for QOS>0
|
||||
if ((buffer[0]&0x06) == MQTTQOS1) {
|
||||
msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1];
|
||||
payload = buffer+llen+3+tl+2;
|
||||
if ((this->buffer[0]&0x06) == MQTTQOS1) {
|
||||
msgId = (this->buffer[llen+3+tl]<<8)+this->buffer[llen+3+tl+1];
|
||||
payload = this->buffer+llen+3+tl+2;
|
||||
callback(topic,payload,len-llen-3-tl-2);
|
||||
|
||||
buffer[0] = MQTTPUBACK;
|
||||
buffer[1] = 2;
|
||||
buffer[2] = (msgId >> 8);
|
||||
buffer[3] = (msgId & 0xFF);
|
||||
if (_client->write(buffer,4) != 0) {
|
||||
this->buffer[0] = MQTTPUBACK;
|
||||
this->buffer[1] = 2;
|
||||
this->buffer[2] = (msgId >> 8);
|
||||
this->buffer[3] = (msgId & 0xFF);
|
||||
|
||||
// Start Tasmota patch
|
||||
// _client->write(this->buffer,4);
|
||||
// lastOutActivity = t;
|
||||
|
||||
if (_client->write(this->buffer,4) != 0) {
|
||||
lastOutActivity = t;
|
||||
}
|
||||
// End Tasmota patch
|
||||
|
||||
} else {
|
||||
payload = buffer+llen+3+tl;
|
||||
payload = this->buffer+llen+3+tl;
|
||||
callback(topic,payload,len-llen-3-tl);
|
||||
}
|
||||
}
|
||||
} else if (type == MQTTPINGREQ) {
|
||||
buffer[0] = MQTTPINGRESP;
|
||||
buffer[1] = 0;
|
||||
_client->write(buffer,2);
|
||||
this->buffer[0] = MQTTPINGRESP;
|
||||
this->buffer[1] = 0;
|
||||
_client->write(this->buffer,2);
|
||||
} else if (type == MQTTPINGRESP) {
|
||||
pingOutstanding = false;
|
||||
}
|
||||
@ -378,13 +485,11 @@ boolean PubSubClient::loop() {
|
||||
}
|
||||
|
||||
boolean PubSubClient::publish(const char* topic, const char* payload) {
|
||||
size_t plength = (payload != nullptr) ? strlen(payload) : 0;
|
||||
return publish(topic,(const uint8_t*)payload,plength,false);
|
||||
return publish(topic,(const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0,false);
|
||||
}
|
||||
|
||||
boolean PubSubClient::publish(const char* topic, const char* payload, boolean retained) {
|
||||
size_t plength = (payload != nullptr) ? strlen(payload) : 0;
|
||||
return publish(topic,(const uint8_t*)payload,plength,retained);
|
||||
return publish(topic,(const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0,retained);
|
||||
}
|
||||
|
||||
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength) {
|
||||
@ -393,29 +498,32 @@ boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigne
|
||||
|
||||
boolean PubSubClient::publish(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
|
||||
if (connected()) {
|
||||
if (MQTT_MAX_PACKET_SIZE < MQTT_MAX_HEADER_SIZE + 2+strlen(topic) + plength) {
|
||||
if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2+strnlen(topic, this->bufferSize) + plength) {
|
||||
// Too long
|
||||
return false;
|
||||
}
|
||||
// Leave room in the buffer for header and variable length field
|
||||
uint16_t length = MQTT_MAX_HEADER_SIZE;
|
||||
length = writeString(topic,buffer,length);
|
||||
length = writeString(topic,this->buffer,length);
|
||||
|
||||
// Add payload
|
||||
uint16_t i;
|
||||
for (i=0;i<plength;i++) {
|
||||
buffer[length++] = payload[i];
|
||||
this->buffer[length++] = payload[i];
|
||||
}
|
||||
|
||||
// Write the header
|
||||
uint8_t header = MQTTPUBLISH;
|
||||
if (retained) {
|
||||
header |= 1;
|
||||
}
|
||||
return write(header,buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
return write(header,this->buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean PubSubClient::publish_P(const char* topic, const char* payload, boolean retained) {
|
||||
size_t plength = (payload != nullptr) ? strlen(payload) : 0;
|
||||
return publish_P(topic, (const uint8_t*)payload, plength, retained);
|
||||
return publish_P(topic, (const uint8_t*)payload, payload ? strnlen(payload, this->bufferSize) : 0, retained);
|
||||
}
|
||||
|
||||
boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsigned int plength, boolean retained) {
|
||||
@ -427,42 +535,48 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig
|
||||
unsigned int i;
|
||||
uint8_t header;
|
||||
unsigned int len;
|
||||
int expectedLength;
|
||||
|
||||
if (!connected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tlen = strlen(topic);
|
||||
tlen = strnlen(topic, this->bufferSize);
|
||||
|
||||
header = MQTTPUBLISH;
|
||||
if (retained) {
|
||||
header |= 1;
|
||||
}
|
||||
buffer[pos++] = header;
|
||||
this->buffer[pos++] = header;
|
||||
len = plength + 2 + tlen;
|
||||
do {
|
||||
digit = len % 128;
|
||||
len = len / 128;
|
||||
digit = len & 127; //digit = len %128
|
||||
len >>= 7; //len = len / 128
|
||||
if (len > 0) {
|
||||
digit |= 0x80;
|
||||
}
|
||||
buffer[pos++] = digit;
|
||||
this->buffer[pos++] = digit;
|
||||
llen++;
|
||||
} while(len>0);
|
||||
|
||||
pos = writeString(topic,buffer,pos);
|
||||
pos = writeString(topic,this->buffer,pos);
|
||||
|
||||
rc += _client->write(buffer,pos);
|
||||
rc += _client->write(this->buffer,pos);
|
||||
|
||||
for (i=0;i<plength;i++) {
|
||||
rc += _client->write((char)pgm_read_byte_near(payload + i));
|
||||
}
|
||||
|
||||
// Start Tasmota patch
|
||||
// lastOutActivity = millis();
|
||||
|
||||
if (rc > 0) {
|
||||
lastOutActivity = millis();
|
||||
}
|
||||
// End Tasmota patch
|
||||
|
||||
expectedLength = 1 + llen + 2 + tlen + plength;
|
||||
|
||||
// Header (1 byte) + llen + identifier (2 bytes) + topic len + payload len
|
||||
const unsigned int expectedLength = 1 + llen + 2 + tlen + plength;
|
||||
return (rc == expectedLength);
|
||||
}
|
||||
|
||||
@ -470,16 +584,22 @@ boolean PubSubClient::beginPublish(const char* topic, unsigned int plength, bool
|
||||
if (connected()) {
|
||||
// Send the header and variable length field
|
||||
uint16_t length = MQTT_MAX_HEADER_SIZE;
|
||||
length = writeString(topic,buffer,length);
|
||||
length = writeString(topic,this->buffer,length);
|
||||
uint8_t header = MQTTPUBLISH;
|
||||
if (retained) {
|
||||
header |= 1;
|
||||
}
|
||||
size_t hlen = buildHeader(header, buffer, plength+length-MQTT_MAX_HEADER_SIZE);
|
||||
uint16_t rc = _client->write(buffer+(MQTT_MAX_HEADER_SIZE-hlen),length-(MQTT_MAX_HEADER_SIZE-hlen));
|
||||
size_t hlen = buildHeader(header, this->buffer, plength+length-MQTT_MAX_HEADER_SIZE);
|
||||
uint16_t rc = _client->write(this->buffer+(MQTT_MAX_HEADER_SIZE-hlen),length-(MQTT_MAX_HEADER_SIZE-hlen));
|
||||
|
||||
// Start Tasmota patch
|
||||
// lastOutActivity = millis();
|
||||
|
||||
if (rc > 0) {
|
||||
lastOutActivity = millis();
|
||||
}
|
||||
// End Tasmota patch
|
||||
|
||||
return (rc == (length-(MQTT_MAX_HEADER_SIZE-hlen)));
|
||||
}
|
||||
return false;
|
||||
@ -490,6 +610,11 @@ int PubSubClient::endPublish() {
|
||||
}
|
||||
|
||||
size_t PubSubClient::write(uint8_t data) {
|
||||
|
||||
// Start Tasmota patch
|
||||
// lastOutActivity = millis();
|
||||
// return _client->write(data);
|
||||
|
||||
if (_client == nullptr) {
|
||||
lastOutActivity = millis();
|
||||
return 0;
|
||||
@ -499,9 +624,16 @@ size_t PubSubClient::write(uint8_t data) {
|
||||
lastOutActivity = millis();
|
||||
}
|
||||
return rc;
|
||||
// End Tasmota patch
|
||||
|
||||
}
|
||||
|
||||
size_t PubSubClient::write(const uint8_t *buffer, size_t size) {
|
||||
|
||||
// Start Tasmota patch
|
||||
// lastOutActivity = millis();
|
||||
// return _client->write(buffer,size);
|
||||
|
||||
if (_client == nullptr) {
|
||||
lastOutActivity = millis();
|
||||
return 0;
|
||||
@ -511,6 +643,8 @@ size_t PubSubClient::write(const uint8_t *buffer, size_t size) {
|
||||
lastOutActivity = millis();
|
||||
}
|
||||
return rc;
|
||||
// End Tasmota patch
|
||||
|
||||
}
|
||||
|
||||
size_t PubSubClient::buildHeader(uint8_t header, uint8_t* buf, uint16_t length) {
|
||||
@ -520,8 +654,9 @@ size_t PubSubClient::buildHeader(uint8_t header, uint8_t* buf, uint16_t length)
|
||||
uint8_t pos = 0;
|
||||
uint16_t len = length;
|
||||
do {
|
||||
digit = len % 128;
|
||||
len = len / 128;
|
||||
|
||||
digit = len & 127; //digit = len %128
|
||||
len >>= 7; //len = len / 128
|
||||
if (len > 0) {
|
||||
digit |= 0x80;
|
||||
}
|
||||
@ -546,7 +681,6 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
|
||||
uint8_t bytesToWrite;
|
||||
boolean result = true;
|
||||
while((bytesRemaining > 0) && result) {
|
||||
delay(0); // Prevent watchdog crashes
|
||||
bytesToWrite = (bytesRemaining > MQTT_MAX_TRANSFER_SIZE)?MQTT_MAX_TRANSFER_SIZE:bytesRemaining;
|
||||
rc = _client->write(writeBuf,bytesToWrite);
|
||||
result = (rc == bytesToWrite);
|
||||
@ -556,9 +690,15 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
|
||||
return result;
|
||||
#else
|
||||
rc = _client->write(buf+(MQTT_MAX_HEADER_SIZE-hlen),length+hlen);
|
||||
|
||||
// Start Tasmota patch
|
||||
// lastOutActivity = millis();
|
||||
|
||||
if (rc != 0) {
|
||||
lastOutActivity = millis();
|
||||
}
|
||||
// End Tasmota patch
|
||||
|
||||
return (rc == hlen+length);
|
||||
#endif
|
||||
}
|
||||
@ -568,10 +708,14 @@ boolean PubSubClient::subscribe(const char* topic) {
|
||||
}
|
||||
|
||||
boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
|
||||
size_t topicLength = strnlen(topic, this->bufferSize);
|
||||
if (topic == 0) {
|
||||
return false;
|
||||
}
|
||||
if (qos > 1) {
|
||||
return false;
|
||||
}
|
||||
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
|
||||
if (this->bufferSize < 9 + topicLength) {
|
||||
// Too long
|
||||
return false;
|
||||
}
|
||||
@ -582,17 +726,21 @@ boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
|
||||
if (nextMsgId == 0) {
|
||||
nextMsgId = 1;
|
||||
}
|
||||
buffer[length++] = (nextMsgId >> 8);
|
||||
buffer[length++] = (nextMsgId & 0xFF);
|
||||
length = writeString((char*)topic, buffer,length);
|
||||
buffer[length++] = qos;
|
||||
return write(MQTTSUBSCRIBE|MQTTQOS1,buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
this->buffer[length++] = (nextMsgId >> 8);
|
||||
this->buffer[length++] = (nextMsgId & 0xFF);
|
||||
length = writeString((char*)topic, this->buffer,length);
|
||||
this->buffer[length++] = qos;
|
||||
return write(MQTTSUBSCRIBE|MQTTQOS1,this->buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean PubSubClient::unsubscribe(const char* topic) {
|
||||
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
|
||||
size_t topicLength = strnlen(topic, this->bufferSize);
|
||||
if (topic == 0) {
|
||||
return false;
|
||||
}
|
||||
if (this->bufferSize < 9 + topicLength) {
|
||||
// Too long
|
||||
return false;
|
||||
}
|
||||
@ -602,25 +750,34 @@ boolean PubSubClient::unsubscribe(const char* topic) {
|
||||
if (nextMsgId == 0) {
|
||||
nextMsgId = 1;
|
||||
}
|
||||
buffer[length++] = (nextMsgId >> 8);
|
||||
buffer[length++] = (nextMsgId & 0xFF);
|
||||
length = writeString(topic, buffer,length);
|
||||
return write(MQTTUNSUBSCRIBE|MQTTQOS1,buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
this->buffer[length++] = (nextMsgId >> 8);
|
||||
this->buffer[length++] = (nextMsgId & 0xFF);
|
||||
length = writeString(topic, this->buffer,length);
|
||||
return write(MQTTUNSUBSCRIBE|MQTTQOS1,this->buffer,length-MQTT_MAX_HEADER_SIZE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PubSubClient::disconnect(bool disconnect_package) {
|
||||
buffer[0] = MQTTDISCONNECT;
|
||||
buffer[1] = 0;
|
||||
this->buffer[0] = MQTTDISCONNECT;
|
||||
this->buffer[1] = 0;
|
||||
|
||||
// Start Tasmota patch
|
||||
// _client->write(this->buffer,2);
|
||||
// _state = MQTT_DISCONNECTED;
|
||||
// _client->flush();
|
||||
// _client->stop();
|
||||
|
||||
if (_client != nullptr) {
|
||||
if (disconnect_package) {
|
||||
_client->write(buffer,2);
|
||||
_client->write(this->buffer,2);
|
||||
}
|
||||
_client->flush();
|
||||
_client->stop();
|
||||
}
|
||||
_state = MQTT_DISCONNECTED;
|
||||
// End Tasmota patch
|
||||
|
||||
lastInActivity = lastOutActivity = millis();
|
||||
}
|
||||
|
||||
@ -628,7 +785,7 @@ uint16_t PubSubClient::writeString(const char* string, uint8_t* buf, uint16_t po
|
||||
const char* idp = string;
|
||||
uint16_t i = 0;
|
||||
pos += 2;
|
||||
while (*idp && pos < (MQTT_MAX_PACKET_SIZE - 2)) {
|
||||
while (*idp) {
|
||||
buf[pos++] = *idp++;
|
||||
i++;
|
||||
}
|
||||
@ -639,19 +796,27 @@ uint16_t PubSubClient::writeString(const char* string, uint8_t* buf, uint16_t po
|
||||
|
||||
|
||||
boolean PubSubClient::connected() {
|
||||
boolean rc;
|
||||
if (_client == NULL ) {
|
||||
|
||||
// Start Tasmota patch
|
||||
this->_state = MQTT_DISCONNECTED;
|
||||
return false;
|
||||
}
|
||||
if (_client->connected() == 0) {
|
||||
bool lastStateConnected = this->_state == MQTT_CONNECTED;
|
||||
this->disconnect();
|
||||
if (lastStateConnected) {
|
||||
this->_state = MQTT_CONNECTION_LOST;
|
||||
// End Tasmota patch
|
||||
|
||||
rc = false;
|
||||
} else {
|
||||
rc = (int)_client->connected();
|
||||
if (!rc) {
|
||||
if (this->_state == MQTT_CONNECTED) {
|
||||
this->_state = MQTT_CONNECTION_LOST;
|
||||
_client->flush();
|
||||
_client->stop();
|
||||
}
|
||||
} else {
|
||||
return this->_state == MQTT_CONNECTED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return this->_state == MQTT_CONNECTED;
|
||||
return rc;
|
||||
}
|
||||
|
||||
PubSubClient& PubSubClient::setServer(uint8_t * ip, uint16_t port) {
|
||||
@ -662,7 +827,13 @@ PubSubClient& PubSubClient::setServer(uint8_t * ip, uint16_t port) {
|
||||
PubSubClient& PubSubClient::setServer(IPAddress ip, uint16_t port) {
|
||||
this->ip = ip;
|
||||
this->port = port;
|
||||
|
||||
// Start Tasmota patch
|
||||
// this->domain = NULL;
|
||||
|
||||
this->domain = "";
|
||||
// End Tasmota patch
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -690,3 +861,34 @@ PubSubClient& PubSubClient::setStream(Stream& stream){
|
||||
int PubSubClient::state() {
|
||||
return this->_state;
|
||||
}
|
||||
|
||||
boolean PubSubClient::setBufferSize(uint16_t size) {
|
||||
if (size == 0) {
|
||||
// Cannot set it back to 0
|
||||
return false;
|
||||
}
|
||||
if (this->bufferSize == 0) {
|
||||
this->buffer = (uint8_t*)malloc(size);
|
||||
} else {
|
||||
uint8_t* newBuffer = (uint8_t*)realloc(this->buffer, size);
|
||||
if (newBuffer != NULL) {
|
||||
this->buffer = newBuffer;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this->bufferSize = size;
|
||||
return (this->buffer != NULL);
|
||||
}
|
||||
|
||||
uint16_t PubSubClient::getBufferSize() {
|
||||
return this->bufferSize;
|
||||
}
|
||||
PubSubClient& PubSubClient::setKeepAlive(uint16_t keepAlive) {
|
||||
this->keepAlive = keepAlive;
|
||||
return *this;
|
||||
}
|
||||
PubSubClient& PubSubClient::setSocketTimeout(uint16_t timeout) {
|
||||
this->socketTimeout = timeout;
|
||||
return *this;
|
||||
}
|
@ -21,24 +21,20 @@
|
||||
#define MQTT_VERSION MQTT_VERSION_3_1_1
|
||||
#endif
|
||||
|
||||
// MQTT_MAX_PACKET_SIZE : Maximum packet size
|
||||
// MQTT_MAX_PACKET_SIZE : Maximum packet size. Override with setBufferSize().
|
||||
#ifndef MQTT_MAX_PACKET_SIZE
|
||||
//#define MQTT_MAX_PACKET_SIZE 128
|
||||
//#define MQTT_MAX_PACKET_SIZE 1000 // Tasmota v5.11.1c
|
||||
//#define MQTT_MAX_PACKET_SIZE 256
|
||||
#define MQTT_MAX_PACKET_SIZE 1200 // Tasmota v8.1.0.8
|
||||
#endif
|
||||
|
||||
// MQTT_KEEPALIVE : keepAlive interval in Seconds
|
||||
// Keepalive timeout for default MQTT Broker is 10s
|
||||
// MQTT_KEEPALIVE : keepAlive interval in Seconds. Override with setKeepAlive()
|
||||
#ifndef MQTT_KEEPALIVE
|
||||
//#define MQTT_KEEPALIVE 10
|
||||
#define MQTT_KEEPALIVE 30 // Tasmota v6.5.0.14 enabling AWS-iot
|
||||
#define MQTT_KEEPALIVE 15
|
||||
#endif
|
||||
|
||||
// MQTT_SOCKET_TIMEOUT: socket timeout interval in Seconds
|
||||
// MQTT_SOCKET_TIMEOUT: socket timeout interval in Seconds. Override with setSocketTimeout()
|
||||
#ifndef MQTT_SOCKET_TIMEOUT
|
||||
//#define MQTT_SOCKET_TIMEOUT 15
|
||||
#define MQTT_SOCKET_TIMEOUT 4 // Tasmota 20210120
|
||||
#define MQTT_SOCKET_TIMEOUT 15
|
||||
#endif
|
||||
|
||||
// MQTT_MAX_TRANSFER_SIZE : limit how much data is passed to the network client
|
||||
@ -88,18 +84,21 @@
|
||||
#define MQTT_CALLBACK_SIGNATURE void (*callback)(char*, uint8_t*, unsigned int)
|
||||
#endif
|
||||
|
||||
#define CHECK_STRING_LENGTH(l,s) if (l+2+strlen(s) > MQTT_MAX_PACKET_SIZE) {_client->stop();return false;}
|
||||
#define CHECK_STRING_LENGTH(l,s) if (l+2+strnlen(s, this->bufferSize) > this->bufferSize) {_client->stop();return false;}
|
||||
|
||||
class PubSubClient : public Print {
|
||||
private:
|
||||
Client* _client;
|
||||
uint8_t buffer[MQTT_MAX_PACKET_SIZE];
|
||||
uint8_t* buffer;
|
||||
uint16_t bufferSize;
|
||||
uint16_t keepAlive;
|
||||
uint16_t socketTimeout;
|
||||
uint16_t nextMsgId;
|
||||
unsigned long lastOutActivity;
|
||||
unsigned long lastInActivity;
|
||||
bool pingOutstanding;
|
||||
MQTT_CALLBACK_SIGNATURE;
|
||||
uint16_t readPacket(uint8_t*);
|
||||
uint32_t readPacket(uint8_t*);
|
||||
boolean readByte(uint8_t * result);
|
||||
boolean readByte(uint8_t * result, uint16_t * index);
|
||||
boolean write(uint8_t header, uint8_t* buf, uint16_t length);
|
||||
@ -110,7 +109,13 @@ private:
|
||||
// (MQTT_MAX_HEADER_SIZE - <returned size>) bytes into the buffer
|
||||
size_t buildHeader(uint8_t header, uint8_t* buf, uint16_t length);
|
||||
IPAddress ip;
|
||||
|
||||
// Start Tasmota patch
|
||||
// const char* domain;
|
||||
|
||||
String domain;
|
||||
// End Tasmota patch
|
||||
|
||||
uint16_t port;
|
||||
Stream* stream;
|
||||
int _state;
|
||||
@ -129,7 +134,8 @@ public:
|
||||
PubSubClient(const char*, uint16_t, Client& client, Stream&);
|
||||
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);
|
||||
PubSubClient(const char*, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client, Stream&);
|
||||
virtual ~PubSubClient() {}
|
||||
|
||||
~PubSubClient();
|
||||
|
||||
PubSubClient& setServer(IPAddress ip, uint16_t port);
|
||||
PubSubClient& setServer(uint8_t * ip, uint16_t port);
|
||||
@ -137,13 +143,24 @@ public:
|
||||
PubSubClient& setCallback(MQTT_CALLBACK_SIGNATURE);
|
||||
PubSubClient& setClient(Client& client);
|
||||
PubSubClient& setStream(Stream& stream);
|
||||
PubSubClient& setKeepAlive(uint16_t keepAlive);
|
||||
PubSubClient& setSocketTimeout(uint16_t timeout);
|
||||
|
||||
boolean setBufferSize(uint16_t size);
|
||||
uint16_t getBufferSize();
|
||||
|
||||
boolean connect(const char* id);
|
||||
boolean connect(const char* id, const char* user, const char* pass);
|
||||
boolean connect(const char* id, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
|
||||
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage);
|
||||
boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const char* willMessage, boolean cleanSession);
|
||||
|
||||
// Start Tasmota patch
|
||||
// void disconnect();
|
||||
|
||||
void disconnect(bool disconnect_package = false);
|
||||
// End Tasmota patch
|
||||
|
||||
boolean publish(const char* topic, const char* payload);
|
||||
boolean publish(const char* topic, const char* payload, boolean retained);
|
||||
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
|
||||
@ -173,6 +190,7 @@ public:
|
||||
boolean loop();
|
||||
boolean connected();
|
||||
int state();
|
||||
|
||||
};
|
||||
|
||||
|
@ -280,6 +280,38 @@ int test_connect_disconnect_connect() {
|
||||
END_IT
|
||||
}
|
||||
|
||||
int test_connect_custom_keepalive() {
|
||||
IT("sends a properly formatted connect packet with custom keepalive value");
|
||||
ShimClient shimClient;
|
||||
|
||||
shimClient.setAllowConnect(true);
|
||||
byte expectServer[] = { 172, 16, 0, 2 };
|
||||
shimClient.expectConnect(expectServer,1883);
|
||||
|
||||
// Set keepalive to 300secs == 0x01 0x2c
|
||||
byte connect[] = {0x10,0x18,0x0,0x4,0x4d,0x51,0x54,0x54,0x4,0x2,0x01,0x2c,0x0,0xc,0x63,0x6c,0x69,0x65,0x6e,0x74,0x5f,0x74,0x65,0x73,0x74,0x31};
|
||||
byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
|
||||
|
||||
shimClient.expect(connect,26);
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient);
|
||||
int state = client.state();
|
||||
IS_TRUE(state == MQTT_DISCONNECTED);
|
||||
|
||||
client.setKeepAlive(300);
|
||||
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
IS_FALSE(shimClient.error());
|
||||
|
||||
state = client.state();
|
||||
IS_TRUE(state == MQTT_CONNECTED);
|
||||
|
||||
END_IT
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
SUITE("Connect");
|
||||
@ -298,5 +330,7 @@ int main()
|
||||
test_connect_with_will();
|
||||
test_connect_with_will_username_password();
|
||||
test_connect_disconnect_connect();
|
||||
|
||||
test_connect_custom_keepalive();
|
||||
FINISH
|
||||
}
|
@ -5,18 +5,18 @@
|
||||
|
||||
class Buffer {
|
||||
private:
|
||||
uint8_t buffer[1024];
|
||||
uint8_t buffer[2048];
|
||||
uint16_t pos;
|
||||
uint16_t length;
|
||||
|
||||
|
||||
public:
|
||||
Buffer();
|
||||
Buffer(uint8_t* buf, size_t size);
|
||||
|
||||
|
||||
virtual bool available();
|
||||
virtual uint8_t next();
|
||||
virtual void reset();
|
||||
|
||||
|
||||
virtual void add(uint8_t* buf, size_t size);
|
||||
};
|
||||
|
@ -134,6 +134,7 @@ int test_publish_too_long() {
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient);
|
||||
client.setBufferSize(128);
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
|
@ -20,6 +20,7 @@ void reset_callback() {
|
||||
}
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
TRACE("Callback received topic=[" << topic << "] length=" << length << "\n")
|
||||
callback_called = true;
|
||||
strcpy(lastTopic,topic);
|
||||
memcpy(lastPayload,payload,length);
|
||||
@ -102,10 +103,15 @@ int test_receive_max_sized_message() {
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient);
|
||||
int length = 80; // If this is changed to > 128 then the publish packet below
|
||||
// is no longer valid as it assumes the remaining length
|
||||
// is a single-byte. Don't make that mistake like I just
|
||||
// did and lose a whole evening tracking down the issue.
|
||||
client.setBufferSize(length);
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
|
||||
int length = MQTT_MAX_PACKET_SIZE;
|
||||
|
||||
byte publish[] = {0x30,length-2,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
|
||||
byte bigPublish[length];
|
||||
memset(bigPublish,'A',length);
|
||||
@ -137,11 +143,13 @@ int test_receive_oversized_message() {
|
||||
byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
int length = 80; // See comment in test_receive_max_sized_message before changing this value
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient);
|
||||
client.setBufferSize(length-1);
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
|
||||
int length = MQTT_MAX_PACKET_SIZE+1;
|
||||
byte publish[] = {0x30,length-2,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
|
||||
byte bigPublish[length];
|
||||
memset(bigPublish,'A',length);
|
||||
@ -188,9 +196,58 @@ int test_drop_invalid_remaining_length_message() {
|
||||
END_IT
|
||||
}
|
||||
|
||||
int test_resize_buffer() {
|
||||
IT("receives a message larger than the default maximum");
|
||||
reset_callback();
|
||||
|
||||
ShimClient shimClient;
|
||||
shimClient.setAllowConnect(true);
|
||||
|
||||
byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
int length = 80; // See comment in test_receive_max_sized_message before changing this value
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient);
|
||||
client.setBufferSize(length-1);
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
|
||||
byte publish[] = {0x30,length-2,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
|
||||
byte bigPublish[length];
|
||||
memset(bigPublish,'A',length);
|
||||
bigPublish[length] = 'B';
|
||||
memcpy(bigPublish,publish,16);
|
||||
// Send it twice
|
||||
shimClient.respond(bigPublish,length);
|
||||
shimClient.respond(bigPublish,length);
|
||||
|
||||
rc = client.loop();
|
||||
IS_TRUE(rc);
|
||||
|
||||
// First message fails as it is too big
|
||||
IS_FALSE(callback_called);
|
||||
|
||||
// Resize the buffer
|
||||
client.setBufferSize(length);
|
||||
|
||||
rc = client.loop();
|
||||
IS_TRUE(rc);
|
||||
|
||||
IS_TRUE(callback_called);
|
||||
|
||||
IS_TRUE(strcmp(lastTopic,"topic")==0);
|
||||
IS_TRUE(lastLength == length-9);
|
||||
IS_TRUE(memcmp(lastPayload,bigPublish+9,lastLength)==0);
|
||||
|
||||
IS_FALSE(shimClient.error());
|
||||
|
||||
END_IT
|
||||
}
|
||||
|
||||
|
||||
int test_receive_oversized_stream_message() {
|
||||
IT("drops an oversized message");
|
||||
IT("receive an oversized streamed message");
|
||||
reset_callback();
|
||||
|
||||
Stream stream;
|
||||
@ -201,11 +258,13 @@ int test_receive_oversized_stream_message() {
|
||||
byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
int length = 80; // See comment in test_receive_max_sized_message before changing this value
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient, stream);
|
||||
client.setBufferSize(length-1);
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
|
||||
int length = MQTT_MAX_PACKET_SIZE+1;
|
||||
byte publish[] = {0x30,length-2,0x0,0x5,0x74,0x6f,0x70,0x69,0x63,0x70,0x61,0x79,0x6c,0x6f,0x61,0x64};
|
||||
|
||||
byte bigPublish[length];
|
||||
@ -222,7 +281,8 @@ int test_receive_oversized_stream_message() {
|
||||
|
||||
IS_TRUE(callback_called);
|
||||
IS_TRUE(strcmp(lastTopic,"topic")==0);
|
||||
IS_TRUE(lastLength == length-9);
|
||||
|
||||
IS_TRUE(lastLength == length-10);
|
||||
|
||||
IS_FALSE(stream.error());
|
||||
IS_FALSE(shimClient.error());
|
||||
@ -272,6 +332,7 @@ int main()
|
||||
test_receive_max_sized_message();
|
||||
test_drop_invalid_remaining_length_message();
|
||||
test_receive_oversized_message();
|
||||
test_resize_buffer();
|
||||
test_receive_oversized_stream_message();
|
||||
test_receive_qos1();
|
||||
|
@ -106,6 +106,7 @@ int test_subscribe_too_long() {
|
||||
shimClient.respond(connack,4);
|
||||
|
||||
PubSubClient client(server, 1883, callback, shimClient);
|
||||
client.setBufferSize(128);
|
||||
int rc = client.connect((char*)"client_test1");
|
||||
IS_TRUE(rc);
|
||||
|
276
lib/lib_display/TM1638plus/README.md
Normal file
276
lib/lib_display/TM1638plus/README.md
Normal file
@ -0,0 +1,276 @@
|
||||

|
||||
|
||||
Table of contents
|
||||
---------------------------
|
||||
|
||||
* [Overview](#overview)
|
||||
* [Installation](#installation)
|
||||
* [Features](#features)
|
||||
* [Model One](#model-one)
|
||||
* [Model Two](#model-two)
|
||||
* [Model Three](#model-three)
|
||||
* [Notes](#notes)
|
||||
* [Memory](#memory)
|
||||
* [Pic Ports](#pic-port)
|
||||
|
||||
|
||||
Overview
|
||||
--------------------------------------------
|
||||
* Name: TM1638plus
|
||||
* Description:
|
||||
An Arduino library to display data on a 8-digit TM1638 seven segment module.
|
||||
This library supports 3 different models, pictured above from left to right.
|
||||
|
||||
1. Model 1, The (8 KEY & 8 LED) variant which has 8 LED's and 8 Push buttons.
|
||||
2. Model 2, The (QYF 16 KEY) variant which has 16 pushbuttons.
|
||||
3. Model 3, The (LKM1638) variant which has 8 bi-colour LED's and 8 Push buttons.
|
||||
|
||||
|
||||
* Main Author: Gavin Lyons.
|
||||
|
||||
* Tested on Development platforms:
|
||||
|
||||
1. Arduino UNO & NANO v3 .
|
||||
2. ATtiny85 .
|
||||
3. ESP32.
|
||||
4. STM32 STM32F103C8T6 "the blue pill".
|
||||
5. ESP8266.
|
||||
6. Teensy 4.0. (may not work at highest frequency see notes section)
|
||||
|
||||
* History: see CHANGELOG.md in extra folder
|
||||
* Contributors: [gabormay](https://github.com/gabormay) [centic9](https://github.com/centic9) [wunderbaum](https://github.com/wunderbaum)
|
||||
|
||||
|
||||
Installation
|
||||
------------------------------
|
||||
|
||||
The library is included in the official Arduino library manger and the optimum way to install it
|
||||
is using the library manager which can be opened by the *manage libraries* option in Arduino IDE.
|
||||
Search "tm1638" in search bar of library manager to find it.
|
||||
|
||||
See link below for instruction for this and for the other methods too.
|
||||
|
||||
[Installing Additional Arduino Libraries guide](https://www.arduino.cc/en/Guide/Libraries)
|
||||
|
||||
|
||||
Features
|
||||
----------------------
|
||||
|
||||
Connections to MCU:
|
||||
|
||||
1. GPIO = STB = Strobe
|
||||
2. GPIO = CLK = Clock
|
||||
3. GPIO = DIO = Data input / output
|
||||
4. GND
|
||||
5. VCC 5V.
|
||||
|
||||
This device is 5V if using 3.3V MCU, level shift.
|
||||
|
||||
This library supports three variants of the TM1638, which for purposes of this documentation,
|
||||
will be named Model 1 ,Model 2 and Model 3.
|
||||
|
||||
| Model No | Module Name | LEDS | Push buttons |
|
||||
| ------ | ------ | ------ | ------ |
|
||||
| 1 | TM1638 LED & KEY | 8 red only | 8 |
|
||||
| 2 | TM1638 KEYS, QYF | 0 | 16 |
|
||||
| 3 | TM1638 V1.3 or LKM1638 | 8 bi color, red and green | 8 |
|
||||
|
||||
There are two sets of files to support model 1 & 2 . I kept them separate as the models are wired quite different, Model 1 address by digit, while Model 2 address by segment. So the code is quite different for most functions. Model 3 uses same code as Model 1, just different example file and different use of LED functions. Common settings, data and functions are in the TM1638plus_common.x files.
|
||||
|
||||
| Model | Header | Code file | TEST files |
|
||||
| ------ | ------ | ------ | ------ |
|
||||
| 1 | TM1638plus.h | TM1638plus.cpp | TM1638plus_HELLOWORLD_Model1.ino TM1638plus_TEST_Model1.ino |
|
||||
| 3 | Same as model 1 | Same as model 1 | TM1638plus_TEST_Model3.ino |
|
||||
| 2 | TM1638plus_Model2.h | TM1638plus_Model2.cpp | TM1638plus_HELLOWORLD_Model2 TM1638plus_TEST_Model2.ino |
|
||||
|
||||
Model One
|
||||
--------------------------------------
|
||||
|
||||
TM1638 Module 8 Push buttons 8 LEDS (LED & KEY)
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
This variant consist of an 8-digit seven segment display with decimal points,
|
||||
8 Leds and 8 Push buttons. Two 4 digit 3461AS-1 (.34 inch, 4 digit ,common Cathode, decimal point, RED) are used in this module giving a total of 8 digits. A TM1638 controller chip drives the unit.
|
||||
The unit is marked (LED & KEY).
|
||||
|
||||
**Model 1 Library Functions**
|
||||
|
||||
The commented functions can be found in library header file TM1638plus.h.
|
||||
The library support ASCII ,text ,Hex and allows for setting individual segments,
|
||||
and the decimal point of segment.
|
||||
The TM1638plus_TEST.ino contains a set of tests demonstrating library functions.
|
||||
For more information see the commented headers in header file.
|
||||
|
||||
1. Print an ASCII character.
|
||||
2. Print an ASCII character with a dot/decimal point.
|
||||
3. Print a Hexadecimal digit(0-15).
|
||||
4. Print a long integer number with or without leading zeros.
|
||||
5. Print two integer numbers (0-9999) to each nibble with or without leading zeros.
|
||||
6. Print a text string(dots are replaced and dot is turned on preceding digit),
|
||||
"abc.def" becomes "abcdef" with c decimal point segment switched on.
|
||||
7. Read buttons status. User may have to debounce buttons depending on application.
|
||||
debouncing left out to minimise library size.
|
||||
See [URL LINK](https://github.com/gavinlyonsrepo/Arduino_Clock_3)
|
||||
for a practical real world example of using this library,
|
||||
including a example of debouncing the key presses. It is also possible to read multiple key presses.
|
||||
8. Reset and init module functions.
|
||||
9. Adjust brightness of module. Support 8 degree brightness adjustment.
|
||||
If user wishes to change the default brightness at start-up change,
|
||||
The DEFAULT_BRIGHTNESS define in header file.
|
||||
10. Manually set segments to create custom patterns.
|
||||
11. Switch the 8 LEDS on and off, both a set one LED and set all LEDS methods available.
|
||||
|
||||
|
||||
Model Two
|
||||
-----------------------------------------
|
||||
|
||||
TM1638 Module 16 Push buttons (16 KEY) (QYF).
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
They consist of an 8-digit seven segment display with decimal points,
|
||||
and 16 Push buttons.Two 4 digit 3461BS-1 (.34 inch, 4 digit ,common Anode, decimal point, RED)are used in this module giving a total of 8 digits. A TM1638 controller chip drives the unit.
|
||||
NB : If your display shows "56781234" for "12345678" see Notes section. Note A.
|
||||
|
||||
**Model 2 Library Functions**
|
||||
|
||||
The commented functions can be found in library header file TM1638plus_Model2.h.
|
||||
The library support Strings,decimal ,Hex ,raw ASCII data, setting individual segments,
|
||||
and the decimal point. For more detailed information on functions see commented headers in header file(.h).
|
||||
|
||||
1. Print a Hexadecimal number with or without leading zeros
|
||||
2. Print a decimal number with or without leading zeros
|
||||
3. Manually set segments to create custom patterns.
|
||||
4. Print two 4 digit decimal number(0-9999) to each nibble with or without leading zeros.
|
||||
5. Print a text string, dot function supported.
|
||||
6. Read buttons status. User may want to debounce buttons depending on application.
|
||||
See TM1638plus_ADC_TEST_Model2.ino for debounce button example.
|
||||
Two different functions to read buttons.
|
||||
7. Reset and init module functions.
|
||||
8. Adjust brightness of module. Support 8 degree brightness adjustment.
|
||||
If user wishes to change the default brightness at start-up change,
|
||||
The "DEFAULT_BRIGHTNESS" define in header file.
|
||||
9. Print raw ASCII data without reference to font file.
|
||||
|
||||
Model Three
|
||||
-----------------------------------------
|
||||
|
||||
There are different PCB's of these modules on market,
|
||||
This library was tested on no 3 below. I think this software will work for all of them
|
||||
and the differences in PCB are related to connectors, layout and component placement.
|
||||
This module is a variant of Model 1. The differences are the LEDs are bigger and bi-color
|
||||
both red and green, The seven segment display is larger and extra connectors are added for Daisy chaining.
|
||||
Two 4 digit KYX-5461AS-7.3 (.54 inch, 4 digit ,common cathode, decimal point, RED)are used in this module
|
||||
giving a total of 8 digits.
|
||||
|
||||
1. LKM1638 v1.1
|
||||
2. LKM1638 v1.2
|
||||
3. TM1638 V1.3
|
||||
|
||||

|
||||
|
||||
**Model 3 Library Functions**
|
||||
|
||||
The code is the same as model 1 and there is one unique model 3 example file.
|
||||
setLED and setLEDs functions behaviour is the only difference in code base between 1 and 3.
|
||||
SetLED: The difference is when you call the setLED function you pass the following to get LEDs to change colour. For more detailed information on functions see commented headers in header file(.h).
|
||||
|
||||
| Model | setLED Value | result |
|
||||
| ---- | ---- | ---- |
|
||||
| 1 & 3 | 0 | LED off |
|
||||
| 3 | 1 | Led green on |
|
||||
| 3 | 2 | LED red on |
|
||||
| 1 | 1 | LED on |
|
||||
|
||||
SetLEDs: When you pass call the setLEDs function you can pass a word pattern where upper byte is turns LEDs green on and lower byte turns LEDs red on . Model one ignores lower byte, Set to 0x00 always.
|
||||
|
||||
1. Model 3 setLEDs(word) = 0xGGRR
|
||||
3. Model 1 setLEDs(word) = 0xRR00
|
||||
|
||||
Notes
|
||||
--------------------------
|
||||
|
||||
1. Swapped data on Display issue on some Model 2 modules
|
||||
2. Anomaly's on High frequency micro-controllers.
|
||||
3. Driving multiple displays.
|
||||
4. Detecting multiple buttons pressed together.
|
||||
|
||||
*Note A* : Swapped display Issue: Model 2 only
|
||||
|
||||
For Some users using this library the nibbles in information display byte
|
||||
where swapped around. This is because there are different versions of modules on market with different wiring. See issue #3 on github called Swapped display :: "12345678" becomes "56781234".
|
||||
If you test library and you see this issue, in order to fix this when you declare the
|
||||
Object, set the fourth parameter "swap_nibbles" to True, The default is false.
|
||||
|
||||
| PCB Model noted Label | Operation | Object constructor 4th parameter |
|
||||
| ------ | ------ | ------ |
|
||||
| QYF-TM1638 | default operation | false |
|
||||
| QYF-TM1638 -Ver 1.0 | Swapped display Fix | true |
|
||||
|
||||
*Note B* : High frequency micro-controllers.
|
||||
|
||||
This library uses a software SPI-like protocol and may not work fully on
|
||||
micro-controllers running at a very high frequency, without some adjustments to timing.
|
||||
Its a SPI-like interface with a single bidirectional data wire DIO.
|
||||
The TM1638 is basically a slow SPI device (< 500kHz) in DIO mode. The clock uses the equivalent of SPI mode 3 (normally high, clocks data on the rising edge). The problem is that the native Arduino shiftIn()/shiftOut() wire functions are simply too fast for this device (technically the clock signalling for the TM1638 is inverted but as it triggers on a rising edge still it is tolerant of that).
|
||||
To make this work with fast devices, the shift clocking is slowed with a small delay (on the order of a microsecond). As of version 1.6 a new parameter *(_HIGH_FREQ)* has been introduced to constructor it is false by default. Set to true for high frequency MCU ~> 100Mhz. This will fix the issue of HF MCU not reading buttons correctly(ESP-Xs). The High_Freq parameter causes a custom shift-in function to be used.
|
||||
The Teensy results have been sent to me, I don't have these MCU's them at time of writing.
|
||||
|
||||
| IC | frequency | Status |
|
||||
| ------ | ------ | ------ |
|
||||
| ATtiny85 | 1Mhz internal | Working |
|
||||
| Arduino UNO | 16 MHz | Working |
|
||||
| Arduino Nano | 16 MHz | Working |
|
||||
| STM32 "blue pill" STM32F103C8T6 | 72Mhz | Working |
|
||||
| ESP8266 | 160Mhz | Working |
|
||||
| ESP 32 | 240 MHz | Working, with high_freq set to true |
|
||||
| Teensy 4.0| 150Mhz | Working model 1, no Data rest of models |
|
||||
| Teensy 4.0| 396Mhz | Not working on model1 , no Data rest of models |
|
||||
|
||||
*Note C* : Driving multiple displays.
|
||||
|
||||
It is possible to drive multiple modules. Share the DIO and CLK lines and use a unique
|
||||
STB line for each device. see issue number 10 at github for example code.
|
||||
|
||||
*Note D* : Detecting multiple buttons pressed together.
|
||||
|
||||
Model 1 and Model 3 CAN detect multiple buttons pressed.
|
||||
|
||||
Model 3 has two different functions:
|
||||
|
||||
1. ReadKey16 returns a byte with decimal value 1-16 this function cannot
|
||||
detect multiple buttons pressed.
|
||||
|
||||
2. ReadKey16Two returns a 16 bit integer where each bit corresponds to the 16 switch's.
|
||||
However due to the wiring of the module, see SG-X lines on schematic,
|
||||
Pressing Certain combinations of buttons will cause the data on Seven Segments to
|
||||
change. So the simultaneous use of multiple key presses and the seven segments display
|
||||
is problematic. See issue 12 on github for more details.
|
||||
|
||||
Memory
|
||||
-------------------------------
|
||||
|
||||
Version 1.4.
|
||||
|
||||
1. Model 1 memory usage NANO, basic hello world sketch.
|
||||
|
||||
Sketch uses 1488 bytes (4%) of program storage space.
|
||||
Global variables use 22 bytes (1%) of dynamic memory.
|
||||
|
||||
2. Model 2 memory usage NANO, basic hello world sketch.
|
||||
|
||||
Sketch uses 1536 bytes (5%) of program storage space.
|
||||
Global variables use 23 bytes (1%) of dynamic memory.
|
||||
|
||||
|
||||
Pic Port
|
||||
-------------------
|
||||
|
||||
MicroChip PIC XC8 port.
|
||||
I have ported this library to the PIC for the XC8 compiler:
|
||||
[ Link ](https://github.com/gavinlyonsrepo/pic_16F18446_projects)
|
35
lib/lib_display/TM1638plus/keywords.txt
Normal file
35
lib/lib_display/TM1638plus/keywords.txt
Normal file
@ -0,0 +1,35 @@
|
||||
# -----------------------------------------
|
||||
# Syntax coloring for TM1638plus library
|
||||
# -----------------------------------------
|
||||
|
||||
# Datatypes (such as objects)
|
||||
TM1638plus KEYWORD1
|
||||
TM1638plus_Model2 KEYWORD1
|
||||
|
||||
# Methods / functions
|
||||
displayBegin KEYWORD2
|
||||
reset KEYWORD2
|
||||
brightness KEYWORD2
|
||||
DisplayDecNumNibble KEYWORD2
|
||||
|
||||
readButtons KEYWORD2
|
||||
setLED KEYWORD2
|
||||
setLEDs KEYWORD2
|
||||
displayText KEYWORD2
|
||||
displayASCIIwDot KEYWORD2
|
||||
displayASCII KEYWORD2
|
||||
display7Seg KEYWORD2
|
||||
displayHex KEYWORD2
|
||||
displayIntNum KEYWORD2
|
||||
|
||||
DisplaySegments KEYWORD2
|
||||
DisplayHexNum KEYWORD2
|
||||
DisplayDecNum KEYWORD2
|
||||
DisplayStr KEYWORD2
|
||||
ASCIItoSegment KEYWORD2
|
||||
ReadKey16 KEYWORD2
|
||||
ReadKey16Two KEYWORD2
|
||||
|
||||
# Constants
|
||||
|
||||
|
9
lib/lib_display/TM1638plus/library.properties
Normal file
9
lib/lib_display/TM1638plus/library.properties
Normal file
@ -0,0 +1,9 @@
|
||||
name=TM1638plus
|
||||
version=1.7.0
|
||||
author=Gavin Lyons <glyons66@hotmail.com>
|
||||
maintainer=Gavin Lyons <glyons66@hotmail.com>
|
||||
sentence=TM1638plus is an Arduino library to control TM1638 seven segment modules.
|
||||
paragraph=It supports Push Buttons, LEDs, ASCII, Decimal, Hexadecimal,text strings and the decimal point. Small Memory footprint.
|
||||
category=Display
|
||||
url=https://github.com/gavinlyonsrepo/TM1638plus
|
||||
architectures=*
|
191
lib/lib_display/TM1638plus/src/TM1638plus.cpp
Normal file
191
lib/lib_display/TM1638plus/src/TM1638plus.cpp
Normal file
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Project Name: TM1638
|
||||
* File: TM1638plus.cpp
|
||||
* Description: source file arduino library for TM1638 module(LED & KEY). Model 1 & Model 3
|
||||
* Author: Gavin Lyons.
|
||||
* Created May 2019
|
||||
* URL: https://github.com/gavinlyonsrepo/TM1638plus
|
||||
*/
|
||||
|
||||
#include "TM1638plus.h"
|
||||
|
||||
|
||||
TM1638plus::TM1638plus(uint8_t strobe, uint8_t clock, uint8_t data, bool highfreq) {
|
||||
_STROBE_IO = strobe;
|
||||
_DATA_IO = data;
|
||||
_CLOCK_IO = clock;
|
||||
_HIGH_FREQ = highfreq;
|
||||
}
|
||||
|
||||
void TM1638plus::displayBegin() {
|
||||
pinMode(_STROBE_IO , OUTPUT);
|
||||
pinMode(_DATA_IO, OUTPUT);
|
||||
pinMode(_CLOCK_IO , OUTPUT);
|
||||
sendCommand(TM_ACTIVATE);
|
||||
brightness(TM_DEFAULT_BRIGHTNESS);
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
void TM1638plus::sendCommand(uint8_t value)
|
||||
{
|
||||
digitalWrite(_STROBE_IO, LOW);
|
||||
sendData(value);
|
||||
digitalWrite(_STROBE_IO, HIGH);
|
||||
}
|
||||
|
||||
void TM1638plus::sendData(uint8_t data)
|
||||
{
|
||||
if (_HIGH_FREQ == false)
|
||||
shiftOut(_DATA_IO, _CLOCK_IO, LSBFIRST, data);
|
||||
else
|
||||
TM_common.HighFreqshiftOut(_DATA_IO, _CLOCK_IO, LSBFIRST, data);
|
||||
}
|
||||
|
||||
void TM1638plus::reset() {
|
||||
sendCommand(TM_WRITE_INC); // set auto increment mode
|
||||
digitalWrite(_STROBE_IO, LOW);
|
||||
sendData(TM_SEG_ADR); // set starting address to
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
{
|
||||
sendData(0x00);
|
||||
}
|
||||
digitalWrite(_STROBE_IO, HIGH);
|
||||
}
|
||||
|
||||
void TM1638plus::setLED(uint8_t position, uint8_t value)
|
||||
{
|
||||
pinMode(_DATA_IO, OUTPUT);
|
||||
sendCommand(TM_WRITE_LOC);
|
||||
digitalWrite(_STROBE_IO, LOW);
|
||||
sendData(TM_LEDS_ADR + (position << 1));
|
||||
sendData(value);
|
||||
digitalWrite(_STROBE_IO, HIGH);
|
||||
}
|
||||
|
||||
void TM1638plus::setLEDs(uint16_t ledvalues)
|
||||
{
|
||||
for (uint8_t LEDposition = 0; LEDposition < 8; LEDposition++) {
|
||||
uint8_t colour = 0;
|
||||
|
||||
if ((ledvalues & (1 << LEDposition)) != 0) {
|
||||
colour |= TM_RED_LED; //scan lower byte, set Red if one
|
||||
}
|
||||
|
||||
if ((ledvalues & (1 << (LEDposition + 8))) != 0) {
|
||||
colour |= TM_GREEN_LED; //scan upper byte, set green if one
|
||||
}
|
||||
|
||||
setLED(LEDposition, colour);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TM1638plus::displayIntNum(unsigned long number, boolean leadingZeros)
|
||||
{
|
||||
char values[TM_DISPLAY_SIZE + 1];
|
||||
snprintf(values, TM_DISPLAY_SIZE + 1, leadingZeros ? "%08ld" : "%ld", number);
|
||||
displayText(values);
|
||||
}
|
||||
|
||||
|
||||
void TM1638plus::DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, boolean leadingZeros)
|
||||
{
|
||||
char valuesUpper[TM_DISPLAY_SIZE + 1];
|
||||
char valuesLower[TM_DISPLAY_SIZE/2 + 1];
|
||||
snprintf(valuesUpper, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : "%d", numberUpper);
|
||||
snprintf(valuesLower, TM_DISPLAY_SIZE/2 + 1, leadingZeros ? "%04d" : "%d", numberLower);
|
||||
strcat(valuesUpper ,valuesLower);
|
||||
displayText(valuesUpper);
|
||||
}
|
||||
|
||||
void TM1638plus::displayText(const char *text) {
|
||||
char c, pos;
|
||||
pos = 0;
|
||||
while ((c = (*text++)) && pos < TM_DISPLAY_SIZE) {
|
||||
if (*text == '.' && c != '.') {
|
||||
displayASCIIwDot(pos++, c);
|
||||
|
||||
text++;
|
||||
} else {
|
||||
displayASCII(pos++, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TM1638plus::displayASCIIwDot(uint8_t position, uint8_t ascii) {
|
||||
// add 128 or 0x080 0b1000000 to turn on decimal point/dot in seven seg
|
||||
display7Seg(position, pgm_read_byte(&SevenSeg[ascii- TM_ASCII_OFFSET]) + TM_DOT_MASK_DEC);
|
||||
}
|
||||
|
||||
void TM1638plus::display7Seg(uint8_t position, uint8_t value) { // call 7-segment
|
||||
sendCommand(TM_WRITE_LOC);
|
||||
digitalWrite(_STROBE_IO, LOW);
|
||||
sendData(TM_SEG_ADR + (position << 1));
|
||||
sendData(value);
|
||||
digitalWrite(_STROBE_IO, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void TM1638plus::displayASCII(uint8_t position, uint8_t ascii) {
|
||||
display7Seg(position, pgm_read_byte(&SevenSeg[ascii - TM_ASCII_OFFSET]));
|
||||
}
|
||||
|
||||
void TM1638plus::displayHex(uint8_t position, uint8_t hex)
|
||||
{
|
||||
uint8_t offset = 0;
|
||||
if (hex <= 9)
|
||||
{
|
||||
display7Seg(position, pgm_read_byte(&SevenSeg[hex + TM_HEX_OFFSET]));
|
||||
// 16 is offset in reduced ASCII table for 0
|
||||
}else if ((hex >= 10) && (hex <=15))
|
||||
{
|
||||
// Calculate offset in reduced ASCII table for AbCDeF
|
||||
switch(hex)
|
||||
{
|
||||
case 10: offset = 'A'; break;
|
||||
case 11: offset = 'b'; break;
|
||||
case 12: offset = 'C'; break;
|
||||
case 13: offset = 'd'; break;
|
||||
case 14: offset = 'E'; break;
|
||||
case 15: offset = 'F'; break;
|
||||
}
|
||||
display7Seg(position, pgm_read_byte(&SevenSeg[offset-TM_ASCII_OFFSET]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t TM1638plus::readButtons()
|
||||
{
|
||||
uint8_t buttons = 0;
|
||||
uint8_t v =0;
|
||||
|
||||
digitalWrite(_STROBE_IO, LOW);
|
||||
sendData(TM_BUTTONS_MODE);
|
||||
pinMode(_DATA_IO, INPUT);
|
||||
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
|
||||
if (_HIGH_FREQ == false)
|
||||
v = shiftIn(_DATA_IO, _CLOCK_IO, LSBFIRST) << i;
|
||||
else
|
||||
v = TM_common.HighFreqshiftin(_DATA_IO, _CLOCK_IO, LSBFIRST) << i;
|
||||
|
||||
buttons |= v;
|
||||
}
|
||||
|
||||
pinMode(_DATA_IO, OUTPUT);
|
||||
digitalWrite(_STROBE_IO, HIGH);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
|
||||
void TM1638plus::brightness(uint8_t brightness)
|
||||
{
|
||||
uint8_t value = 0;
|
||||
value = TM_BRIGHT_ADR + (TM_BRIGHT_MASK & brightness);
|
||||
sendCommand(value);
|
||||
}
|
104
lib/lib_display/TM1638plus/src/TM1638plus.h
Normal file
104
lib/lib_display/TM1638plus/src/TM1638plus.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Project Name: TM1638plus
|
||||
* File: TM1638plus.h
|
||||
* Description: TM1638plus.h header file arduino library for TM1638 module(LED & KEY). Model 1 & Model 3
|
||||
* Author: Gavin Lyons.
|
||||
* Created May 2019
|
||||
* URL: https://github.com/gavinlyonsrepo/TM1638plus
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TM1638PLUS_H
|
||||
#define TM1638PLUS_H
|
||||
|
||||
#if (ARDUINO >=100)
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include "TM1638plus_common.h"
|
||||
|
||||
class TM1638plus {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
//Parameters
|
||||
// 1. strobe = GPIO STB pin
|
||||
// 2. clock = GPIO CLK pin
|
||||
// 3. data = GPIO DIO pin
|
||||
// 4. higfreq Changes the value of parameter _HIGH_FREQ which is default false
|
||||
// This is used when running high freq MCU CPU (~>100Mhz) because of issues with button function.
|
||||
// Pass true when running high freq MCU CPU (~>100Mhz).
|
||||
TM1638plus(uint8_t strobe, uint8_t clock, uint8_t data, bool highfreq = false);
|
||||
|
||||
// Methods
|
||||
|
||||
void displayBegin(); // Begin method , sets pinmodes , Call in setup
|
||||
|
||||
void reset(void); // Reset / Clear module
|
||||
|
||||
//Sets the brightness level on a scale of brightness = 0 to 7.
|
||||
//0 is not turned off, it's just the lowest brightness.
|
||||
//If user wishes to change the default brightness at start-up change.
|
||||
//The DEFAULT_BRIGHTNESS define in header file.
|
||||
void brightness(uint8_t brightness);
|
||||
|
||||
//Read buttons returns a byte with value of buttons 1-8 b7b6b5b4b3b2b1b0
|
||||
// 1 pressed, zero not pressed.
|
||||
//User may have to debounce buttons depending on application.
|
||||
//See [URL LINK](https://github.com/gavinlyonsrepo/Arduino_Clock_3)
|
||||
// for de-bonce example.
|
||||
uint8_t readButtons(void);
|
||||
|
||||
// Send Text to Seven segments, passed char array pointer
|
||||
// dots are removed from string and dot on preceding digit switched on
|
||||
// "abc.def" will be shown as "abcdef" with c decimal point turned on.
|
||||
void displayText(const char *text);
|
||||
|
||||
// Send ASCII value to seven segment, pass position 0-7 and ASCII value byte
|
||||
void displayASCII(uint8_t position, uint8_t ascii);
|
||||
|
||||
// Same as displayASCII function but turns on dot/decimal point as well
|
||||
void displayASCIIwDot(uint8_t position, uint8_t ascii) ;
|
||||
|
||||
// Send HEX value to seven segment, pass position 0-7 and hex value(DEC) 0-15
|
||||
void displayHex(uint8_t position, uint8_t hex);
|
||||
|
||||
// Send seven segment value to seven segment
|
||||
// pass position 0-7 byte of data corresponding to segments (dp)gfedcba
|
||||
// i.e 0b01000001 will set g and a on.
|
||||
void display7Seg(uint8_t position, uint8_t value);
|
||||
|
||||
//Display an integer and leading zeros optional
|
||||
void displayIntNum(unsigned long number, boolean leadingZeros = true);
|
||||
|
||||
//Divides the display into two nibbles and displays a Decimal number in each.
|
||||
//takes in two numbers 0-9999 for each nibble , and byte for decimal point display,
|
||||
//and leading zeros optional
|
||||
void DisplayDecNumNibble(uint16_t numberUpper, uint16_t numberLower, boolean leadingZeros = true);
|
||||
|
||||
// Set the LEDs. passed one 16bit integer.
|
||||
// MODEL 3:
|
||||
//MSB byte for the green LEDs, LS byte for the red LEDs (0xgreenred)
|
||||
//ie. 0xE007 1110 0000 0000 0111 results in L8-L0 GGGX XRRR, NOTE L8 is RHS on display
|
||||
// MODEL 1:
|
||||
// MSB byte 1 for red LED , LSB byte n/a set to 0x00 (0xleds, 0xXX)
|
||||
//i.e 0xF100 1111 0000 L8-L0 RRRRXXX0 NOTE L8 is RHS on display
|
||||
void setLEDs(uint16_t greenred);
|
||||
|
||||
// Set an LED, pass it LED position 0-7 and value 0 or 1 , L1-L8
|
||||
void setLED(uint8_t position, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t _STROBE_IO;
|
||||
uint8_t _DATA_IO;
|
||||
uint8_t _CLOCK_IO;
|
||||
void sendCommand(uint8_t value);
|
||||
void sendData(uint8_t data);
|
||||
//This is used when running high freq CPU
|
||||
bool _HIGH_FREQ = false;
|
||||
TM1638plus_common TM_common;
|
||||
};
|
||||
|
||||
#endif
|
52
lib/lib_display/TM1638plus/src/TM1638plus_common.cpp
Normal file
52
lib/lib_display/TM1638plus/src/TM1638plus_common.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Project Name: TM1638plus
|
||||
* File: TM1638plus_common
|
||||
* Description: cpp file for common data and functions between model 1 and 2 classes
|
||||
* Arduino library TM1638plus
|
||||
* Author: Gavin Lyons.
|
||||
* URL: https://github.com/gavinlyonsrepo/TM1638plus
|
||||
*/
|
||||
|
||||
#include "TM1638plus_common.h"
|
||||
|
||||
|
||||
TM1638plus_common::TM1638plus_common()
|
||||
{
|
||||
// Blank constructor
|
||||
}
|
||||
|
||||
uint8_t TM1638plus_common::HighFreqshiftin(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
|
||||
{
|
||||
uint8_t value = 0;
|
||||
uint8_t i = 0;
|
||||
|
||||
for(i = 0; i < 8; ++i) {
|
||||
if(bitOrder == LSBFIRST)
|
||||
value |= digitalRead(dataPin) << i;
|
||||
else
|
||||
value |= digitalRead(dataPin) << (7 - i);
|
||||
|
||||
digitalWrite(clockPin, HIGH);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(clockPin, LOW);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void TM1638plus_common::HighFreqshiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (bitOrder == LSBFIRST)
|
||||
digitalWrite(dataPin, !!(val & (1 << i)));
|
||||
else
|
||||
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
|
||||
|
||||
digitalWrite(clockPin, HIGH);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(clockPin, LOW);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
}
|
152
lib/lib_display/TM1638plus/src/TM1638plus_common.h
Normal file
152
lib/lib_display/TM1638plus/src/TM1638plus_common.h
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Project Name: TM1638plus
|
||||
* File: TM1638plus_common.h
|
||||
* Description: header file for common data and functions between model 1 and 2 classes
|
||||
* Arduino library TM1638plus
|
||||
* Author: Gavin Lyons.
|
||||
* URL: https://github.com/gavinlyonsrepo/TM1638plus
|
||||
*/
|
||||
|
||||
#ifndef TM1638PLUS_COMMON_H
|
||||
#define TM1638PLUS_COMMON_H
|
||||
|
||||
#if (ARDUINO >=100)
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define TM_ACTIVATE 0x8F // Start up
|
||||
#define TM_BUTTONS_MODE 0x42 // Buttons mode
|
||||
#define TM_WRITE_LOC 0x44 // Write to a location
|
||||
#define TM_WRITE_INC 0x40 // Incremental write
|
||||
#define TM_SEG_ADR 0xC0 // leftmost segment Address C0 C2 C4 C6 C8 CA CC CE
|
||||
#define TM_LEDS_ADR 0xC1 // Leftmost LED address C1 C3 C5 C7 C9 CB CD CF
|
||||
#define TM_BRIGHT_ADR 0x88 // Brightness address
|
||||
#define TM_BRIGHT_MASK 0x07 // Brightness mask
|
||||
#define TM_DEFAULT_BRIGHTNESS 0x02 //can be 0x00 to 0x07
|
||||
#define TM_DISPLAY_SIZE 8 //size of display
|
||||
|
||||
#define TM_ASCII_OFFSET 32 // Ascii table offset to jump over first missing 32 chars
|
||||
#define TM_HEX_OFFSET 16 // Ascii table offset to reach number position
|
||||
#define TM_DOT_MASK_DEC 128 // 0x80 Mask to switch on decimal point in seven seg.
|
||||
|
||||
#define TM_RED_LED 0x02 // Model 3
|
||||
#define TM_GREEN_LED 0x01 // Model 3
|
||||
#define TM_OFF_LED 0x00
|
||||
|
||||
// font , map of ASCII values/table to 7-segment, offset to position 32.
|
||||
const PROGMEM unsigned char SevenSeg[] = {
|
||||
0x00, /* (space) */
|
||||
0x86, /* ! */
|
||||
0x22, /* " */
|
||||
0x7E, /* # */
|
||||
0x6D, /* $ */
|
||||
0xD2, /* % */
|
||||
0x46, /* & */
|
||||
0x20, /* ' */
|
||||
0x29, /* ( */
|
||||
0x0B, /* ) */
|
||||
0x21, /* * */
|
||||
0x70, /* + */
|
||||
0x10, /* , */
|
||||
0x40, /* - */
|
||||
0x80, /* . */
|
||||
0x52, /* / */
|
||||
0x3F, /* 0 */
|
||||
0x06, /* 1 */
|
||||
0x5B, /* 2 */
|
||||
0x4F, /* 3 */
|
||||
0x66, /* 4 */
|
||||
0x6D, /* 5 */
|
||||
0x7D, /* 6 */
|
||||
0x07, /* 7 */
|
||||
0x7F, /* 8 */
|
||||
0x6F, /* 9 */
|
||||
0x09, /* : */
|
||||
0x0D, /* ; */
|
||||
0x61, /* < */
|
||||
0x48, /* = */
|
||||
0x43, /* > */
|
||||
0xD3, /* ? */
|
||||
0x5F, /* @ */
|
||||
0x77, /* A */
|
||||
0x7C, /* B */
|
||||
0x39, /* C */
|
||||
0x5E, /* D */
|
||||
0x79, /* E */
|
||||
0x71, /* F */
|
||||
0x3D, /* G */
|
||||
0x76, /* H */
|
||||
0x30, /* I */
|
||||
0x1E, /* J */
|
||||
0x75, /* K */
|
||||
0x38, /* L */
|
||||
0x15, /* M */
|
||||
0x37, /* N */
|
||||
0x3F, /* O */
|
||||
0x73, /* P */
|
||||
0x6B, /* Q */
|
||||
0x33, /* R */
|
||||
0x6D, /* S */
|
||||
0x78, /* T */
|
||||
0x3E, /* U */
|
||||
0x3E, /* V */
|
||||
0x2A, /* W */
|
||||
0x76, /* X */
|
||||
0x6E, /* Y */
|
||||
0x5B, /* Z */
|
||||
0x39, /* [ */
|
||||
0x64, /* \ */
|
||||
0x0F, /* ] */
|
||||
0x23, /* ^ */
|
||||
0x08, /* _ */
|
||||
0x02, /* ` */
|
||||
0x5F, /* a */
|
||||
0x7C, /* b */
|
||||
0x58, /* c */
|
||||
0x5E, /* d */
|
||||
0x7B, /* e */
|
||||
0x71, /* f */
|
||||
0x6F, /* g */
|
||||
0x74, /* h */
|
||||
0x10, /* i */
|
||||
0x0C, /* j */
|
||||
0x75, /* k */
|
||||
0x30, /* l */
|
||||
0x14, /* m */
|
||||
0x54, /* n */
|
||||
0x5C, /* o */
|
||||
0x73, /* p */
|
||||
0x67, /* q */
|
||||
0x50, /* r */
|
||||
0x6D, /* s */
|
||||
0x78, /* t */
|
||||
0x1C, /* u */
|
||||
0x1C, /* v */
|
||||
0x14, /* w */
|
||||
0x76, /* x */
|
||||
0x6E, /* y */
|
||||
0x5B, /* z */
|
||||
// Note : Removed last 4 characters to reduce program size as of v 1.3.0
|
||||
// 0x46, /* { */
|
||||
// 0x30, /* | */
|
||||
// 0x70, /* } */
|
||||
// 0x01, /* ~ */
|
||||
};
|
||||
|
||||
// Class for some common functions
|
||||
class TM1638plus_common{
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
TM1638plus_common();
|
||||
|
||||
// Used instead of arduino function "shiftin" when _HIGH_FREQ is set to true
|
||||
uint8_t HighFreqshiftin(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) ;
|
||||
// Used instead of arduino function "shiftOut" when _HIGH_FREQ is set to true
|
||||
void HighFreqshiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
9
lib/lib_i2c/MPU6886/library.properties
Normal file
9
lib/lib_i2c/MPU6886/library.properties
Normal file
@ -0,0 +1,9 @@
|
||||
name=MPU6886
|
||||
version=
|
||||
author=M5StickC
|
||||
maintainer=Stephan Hadinger
|
||||
sentence=Support for MPU6886
|
||||
paragraph=Support for MPU6886
|
||||
category=
|
||||
url=https://github.com/m5stack/M5StickC/blob/master/src/utility/
|
||||
architectures=esp32,esp8266
|
@ -2,39 +2,33 @@
|
||||
#include <math.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
MPU6886::MPU6886(){
|
||||
|
||||
}
|
||||
|
||||
void MPU6886::I2C_Read_NBytes(uint8_t driver_Addr, uint8_t start_Addr, uint8_t number_Bytes, uint8_t *read_Buffer){
|
||||
|
||||
Wire1.beginTransmission(driver_Addr);
|
||||
Wire1.write(start_Addr);
|
||||
Wire1.endTransmission(false);
|
||||
myWire.beginTransmission(driver_Addr);
|
||||
myWire.write(start_Addr);
|
||||
myWire.endTransmission(false);
|
||||
uint8_t i = 0;
|
||||
Wire1.requestFrom(driver_Addr,number_Bytes);
|
||||
myWire.requestFrom(driver_Addr,number_Bytes);
|
||||
|
||||
//! Put read results in the Rx buffer
|
||||
while (Wire1.available()) {
|
||||
read_Buffer[i++] = Wire1.read();
|
||||
while (myWire.available()) {
|
||||
read_Buffer[i++] = myWire.read();
|
||||
}
|
||||
}
|
||||
|
||||
void MPU6886::I2C_Write_NBytes(uint8_t driver_Addr, uint8_t start_Addr, uint8_t number_Bytes, uint8_t *write_Buffer){
|
||||
|
||||
Wire1.beginTransmission(driver_Addr);
|
||||
Wire1.write(start_Addr);
|
||||
Wire1.write(*write_Buffer);
|
||||
Wire1.endTransmission();
|
||||
myWire.beginTransmission(driver_Addr);
|
||||
myWire.write(start_Addr);
|
||||
myWire.write(*write_Buffer);
|
||||
myWire.endTransmission();
|
||||
|
||||
}
|
||||
|
||||
int MPU6886::Init(void){
|
||||
unsigned char tempdata[1];
|
||||
unsigned char regdata;
|
||||
|
||||
Wire1.begin(21,22);
|
||||
|
||||
|
||||
I2C_Read_NBytes(MPU6886_ADDRESS, MPU6886_WHOAMI, 1, tempdata);
|
||||
if(tempdata[0] != 0x19)
|
||||
return -1;
|
||||
@ -52,11 +46,11 @@ int MPU6886::Init(void){
|
||||
I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_PWR_MGMT_1, 1, ®data);
|
||||
delay(10);
|
||||
|
||||
regdata = 0x10;
|
||||
regdata = 0x10; // AFS_8G
|
||||
I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_ACCEL_CONFIG, 1, ®data);
|
||||
delay(1);
|
||||
|
||||
regdata = 0x18;
|
||||
regdata = 0x18; // GFS_2000DPS
|
||||
I2C_Write_NBytes(MPU6886_ADDRESS, MPU6886_GYRO_CONFIG, 1, ®data);
|
||||
delay(1);
|
||||
|
||||
@ -128,24 +122,24 @@ void MPU6886::getTempAdc(int16_t *t){
|
||||
|
||||
|
||||
|
||||
//!俯仰,航向,横滚:pitch,yaw,roll,指三维空间中飞行器的旋转状态。
|
||||
void MPU6886::getAhrsData(float *pitch,float *roll,float *yaw){
|
||||
// //!俯仰,航向,横滚:pitch,yaw,roll,指三维空间中飞行器的旋转状态。
|
||||
// void MPU6886::getAhrsData(float *pitch,float *roll,float *yaw){
|
||||
|
||||
float accX = 0;
|
||||
float accY = 0;
|
||||
float accZ = 0;
|
||||
// float accX = 0;
|
||||
// float accY = 0;
|
||||
// float accZ = 0;
|
||||
|
||||
float gyroX = 0;
|
||||
float gyroY = 0;
|
||||
float gyroZ = 0;
|
||||
// float gyroX = 0;
|
||||
// float gyroY = 0;
|
||||
// float gyroZ = 0;
|
||||
|
||||
|
||||
getGyroData(&gyroX,&gyroY,&gyroZ);
|
||||
getAccelData(&accX,&accY,&accZ);
|
||||
// getGyroData(&gyroX,&gyroY,&gyroZ);
|
||||
// getAccelData(&accX,&accY,&accZ);
|
||||
|
||||
MahonyAHRSupdateIMU(gyroX * DEG_TO_RAD, gyroY * DEG_TO_RAD, gyroZ * DEG_TO_RAD, accX, accY, accZ,pitch,roll,yaw);
|
||||
// MahonyAHRSupdateIMU(gyroX * DEG_TO_RAD, gyroY * DEG_TO_RAD, gyroZ * DEG_TO_RAD, accX, accY, accZ,pitch,roll,yaw);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
void MPU6886::getGres(){
|
||||
|
||||
@ -153,16 +147,20 @@ void MPU6886::getGres(){
|
||||
{
|
||||
// Possible gyro scales (and their register bit settings) are:
|
||||
case GFS_250DPS:
|
||||
gRes = 250.0/32768.0;
|
||||
gRes = 250.0f/32768.0f;
|
||||
gyRange = 250;
|
||||
break;
|
||||
case GFS_500DPS:
|
||||
gRes = 500.0/32768.0;
|
||||
gRes = 500.0f/32768.0f;
|
||||
gyRange = 500;
|
||||
break;
|
||||
case GFS_1000DPS:
|
||||
gRes = 1000.0/32768.0;
|
||||
gRes = 1000.0f/32768.0f;
|
||||
gyRange = 1000;
|
||||
break;
|
||||
case GFS_2000DPS:
|
||||
gRes = 2000.0/32768.0;
|
||||
gRes = 2000.0f/32768.0f;
|
||||
gyRange = 2000;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -177,15 +175,19 @@ void MPU6886::getAres(){
|
||||
// Here's a bit of an algorith to calculate DPS/(ADC tick) based on that 2-bit value:
|
||||
case AFS_2G:
|
||||
aRes = 2.0/32768.0;
|
||||
acRange = 2000;
|
||||
break;
|
||||
case AFS_4G:
|
||||
aRes = 4.0/32768.0;
|
||||
acRange = 4000;
|
||||
break;
|
||||
case AFS_8G:
|
||||
aRes = 8.0/32768.0;
|
||||
acRange = 8000;
|
||||
break;
|
||||
case AFS_16G:
|
||||
aRes = 16.0/32768.0;
|
||||
acRange = 16000;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -215,7 +217,19 @@ void MPU6886::SetAccelFsr(Ascale scale)
|
||||
}
|
||||
|
||||
|
||||
// x/y/z are in 1/1000 if g
|
||||
// avoiding costly float calculations
|
||||
void MPU6886::getAccelDataInt(int16_t* ax, int16_t* ay, int16_t* az) {
|
||||
int16_t accX = 0;
|
||||
int16_t accY = 0;
|
||||
int16_t accZ = 0;
|
||||
getAccelAdc(&accX, &accY, &accZ);
|
||||
|
||||
if (ax != nullptr) { *ax = ((int32_t)accX * acRange) / 0x7FFFL; }
|
||||
if (ay != nullptr) { *ay = ((int32_t)accY * acRange) / 0x7FFFL; }
|
||||
if (az != nullptr) { *az = ((int32_t)accZ * acRange) / 0x7FFFL; }
|
||||
|
||||
}
|
||||
|
||||
void MPU6886::getAccelData(float* ax, float* ay, float* az){
|
||||
|
||||
@ -232,6 +246,20 @@ void MPU6886::getAccelData(float* ax, float* ay, float* az){
|
||||
|
||||
}
|
||||
|
||||
// x/y/z are in dps - degrees per second
|
||||
// avoiding costly float calculations
|
||||
void MPU6886::getGyroDataInt(int16_t* ax, int16_t* ay, int16_t* az) {
|
||||
int16_t gyX = 0;
|
||||
int16_t gyY = 0;
|
||||
int16_t gyZ = 0;
|
||||
getGyroAdc(&gyX, &gyY, &gyZ);
|
||||
|
||||
if (ax != nullptr) { *ax = ((int32_t)gyX * gyRange) / 0x7FFFL; }
|
||||
if (ay != nullptr) { *ay = ((int32_t)gyY * gyRange) / 0x7FFFL; }
|
||||
if (az != nullptr) { *az = ((int32_t)gyZ * gyRange) / 0x7FFFL; }
|
||||
|
||||
}
|
||||
|
||||
void MPU6886::getGyroData(float* gx, float* gy, float* gz){
|
||||
int16_t gyroX = 0;
|
||||
int16_t gyroY = 0;
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
#include "MahonyAHRS.h"
|
||||
|
||||
#define MPU6886_ADDRESS 0x68
|
||||
#define MPU6886_WHOAMI 0x75
|
||||
@ -67,8 +66,15 @@ class MPU6886 {
|
||||
|
||||
Gscale Gyscale = GFS_2000DPS;
|
||||
Ascale Acscale = AFS_8G;
|
||||
int16_t acRange = 8000; // 1/1000 of g
|
||||
int16_t gyRange = 2000; // dps - degree per second
|
||||
public:
|
||||
MPU6886();
|
||||
MPU6886(void) {};
|
||||
#ifdef ESP32
|
||||
void setBus(uint32_t _bus) { myWire = _bus ? Wire1 : Wire; };
|
||||
#else
|
||||
void setBus(uint32_t _bus) { myWire = Wire; };
|
||||
#endif
|
||||
int Init(void);
|
||||
void getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az);
|
||||
void getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz);
|
||||
@ -77,13 +83,17 @@ class MPU6886 {
|
||||
void getAccelData(float* ax, float* ay, float* az);
|
||||
void getGyroData(float* gx, float* gy, float* gz);
|
||||
void getTempData(float *t);
|
||||
// int variants
|
||||
void getAccelDataInt(int16_t* ax, int16_t* ay, int16_t* az);
|
||||
void getGyroDataInt(int16_t* gx, int16_t* gy, int16_t* gz);
|
||||
|
||||
void SetGyroFsr(Gscale scale);
|
||||
void SetAccelFsr(Ascale scale);
|
||||
|
||||
void getAhrsData(float *pitch,float *roll,float *yaw);
|
||||
// void getAhrsData(float *pitch,float *roll,float *yaw);
|
||||
|
||||
public:
|
||||
TwoWire & myWire = Wire; // default to Wire (bus 0)
|
||||
float aRes, gRes;
|
||||
|
||||
private:
|
@ -1,111 +1,116 @@
|
||||
extern const bcstring be_const_str_remove;
|
||||
extern const bcstring be_const_str_false;
|
||||
extern const bcstring be_const_str_raise;
|
||||
extern const bcstring be_const_str_opt_connect;
|
||||
extern const bcstring be_const_str_dot_p;
|
||||
extern const bcstring be_const_str_calldepth;
|
||||
extern const bcstring be_const_str_toupper;
|
||||
extern const bcstring be_const_str_break;
|
||||
extern const bcstring be_const_str_map;
|
||||
extern const bcstring be_const_str_bytes;
|
||||
extern const bcstring be_const_str_tanh;
|
||||
extern const bcstring be_const_str_real;
|
||||
extern const bcstring be_const_str_count;
|
||||
extern const bcstring be_const_str_setitem;
|
||||
extern const bcstring be_const_str_split;
|
||||
extern const bcstring be_const_str_if;
|
||||
extern const bcstring be_const_str_format;
|
||||
extern const bcstring be_const_str_pow;
|
||||
extern const bcstring be_const_str_tostring;
|
||||
extern const bcstring be_const_str_load;
|
||||
extern const bcstring be_const_str_setrange;
|
||||
extern const bcstring be_const_str_char;
|
||||
extern const bcstring be_const_str_acos;
|
||||
extern const bcstring be_const_str_deinit;
|
||||
extern const bcstring be_const_str_dump;
|
||||
extern const bcstring be_const_str_sqrt;
|
||||
extern const bcstring be_const_str_fromstring;
|
||||
extern const bcstring be_const_str_opt_eq;
|
||||
extern const bcstring be_const_str_asin;
|
||||
extern const bcstring be_const_str_byte;
|
||||
extern const bcstring be_const_str_copy;
|
||||
extern const bcstring be_const_str_floor;
|
||||
extern const bcstring be_const_str_find;
|
||||
extern const bcstring be_const_str_var;
|
||||
extern const bcstring be_const_str_opt_add;
|
||||
extern const bcstring be_const_str___lower__;
|
||||
extern const bcstring be_const_str_rand;
|
||||
extern const bcstring be_const_str_sin;
|
||||
extern const bcstring be_const_str_deg;
|
||||
extern const bcstring be_const_str_imin;
|
||||
extern const bcstring be_const_str_class;
|
||||
extern const bcstring be_const_str_try;
|
||||
extern const bcstring be_const_str_allocated;
|
||||
extern const bcstring be_const_str_asstring;
|
||||
extern const bcstring be_const_str_classname;
|
||||
extern const bcstring be_const_str_reverse;
|
||||
extern const bcstring be_const_str_assert;
|
||||
extern const bcstring be_const_str_str;
|
||||
extern const bcstring be_const_str_imax;
|
||||
extern const bcstring be_const_str_init;
|
||||
extern const bcstring be_const_str_except;
|
||||
extern const bcstring be_const_str_return;
|
||||
extern const bcstring be_const_str_opt_neq;
|
||||
extern const bcstring be_const_str_hex;
|
||||
extern const bcstring be_const_str_resize;
|
||||
extern const bcstring be_const_str_as;
|
||||
extern const bcstring be_const_str___upper__;
|
||||
extern const bcstring be_const_str_codedump;
|
||||
extern const bcstring be_const_str_cosh;
|
||||
extern const bcstring be_const_str_abs;
|
||||
extern const bcstring be_const_str_collect;
|
||||
extern const bcstring be_const_str_atan;
|
||||
extern const bcstring be_const_str_attrdump;
|
||||
extern const bcstring be_const_str_input;
|
||||
extern const bcstring be_const_str_;
|
||||
extern const bcstring be_const_str_compile;
|
||||
extern const bcstring be_const_str_iter;
|
||||
extern const bcstring be_const_str_lower;
|
||||
extern const bcstring be_const_str_number;
|
||||
extern const bcstring be_const_str_print;
|
||||
extern const bcstring be_const_str_exp;
|
||||
extern const bcstring be_const_str_pi;
|
||||
extern const bcstring be_const_str___iterator__;
|
||||
extern const bcstring be_const_str_log;
|
||||
extern const bcstring be_const_str_log10;
|
||||
extern const bcstring be_const_str_ceil;
|
||||
extern const bcstring be_const_str_get;
|
||||
extern const bcstring be_const_str_tolower;
|
||||
extern const bcstring be_const_str_while;
|
||||
extern const bcstring be_const_str_import;
|
||||
extern const bcstring be_const_str_size;
|
||||
extern const bcstring be_const_str_list;
|
||||
extern const bcstring be_const_str_rad;
|
||||
extern const bcstring be_const_str_tan;
|
||||
extern const bcstring be_const_str_type;
|
||||
extern const bcstring be_const_str_insert;
|
||||
extern const bcstring be_const_str_module;
|
||||
extern const bcstring be_const_str_range;
|
||||
extern const bcstring be_const_str_super;
|
||||
extern const bcstring be_const_str_issubclass;
|
||||
extern const bcstring be_const_str_def;
|
||||
extern const bcstring be_const_str_classof;
|
||||
extern const bcstring be_const_str_sinh;
|
||||
extern const bcstring be_const_str_srand;
|
||||
extern const bcstring be_const_str_end;
|
||||
extern const bcstring be_const_str_clear;
|
||||
extern const bcstring be_const_str_top;
|
||||
extern const bcstring be_const_str_nil;
|
||||
extern const bcstring be_const_str_open;
|
||||
extern const bcstring be_const_str_do;
|
||||
extern const bcstring be_const_str_add;
|
||||
extern const bcstring be_const_str_isinstance;
|
||||
extern const bcstring be_const_str_pop;
|
||||
extern const bcstring be_const_str_int;
|
||||
extern const bcstring be_const_str_push;
|
||||
extern const bcstring be_const_str_setrange;
|
||||
extern const bcstring be_const_str_sinh;
|
||||
extern const bcstring be_const_str_elif;
|
||||
extern const bcstring be_const_str_iter;
|
||||
extern const bcstring be_const_str_load;
|
||||
extern const bcstring be_const_str_class;
|
||||
extern const bcstring be_const_str_if;
|
||||
extern const bcstring be_const_str_opt_eq;
|
||||
extern const bcstring be_const_str_ceil;
|
||||
extern const bcstring be_const_str_floor;
|
||||
extern const bcstring be_const_str_map;
|
||||
extern const bcstring be_const_str_print;
|
||||
extern const bcstring be_const_str_else;
|
||||
extern const bcstring be_const_str_find;
|
||||
extern const bcstring be_const_str_str;
|
||||
extern const bcstring be_const_str___upper__;
|
||||
extern const bcstring be_const_str_dump;
|
||||
extern const bcstring be_const_str_atan;
|
||||
extern const bcstring be_const_str_size;
|
||||
extern const bcstring be_const_str_tolower;
|
||||
extern const bcstring be_const_str_opt_add;
|
||||
extern const bcstring be_const_str_abs;
|
||||
extern const bcstring be_const_str_lower;
|
||||
extern const bcstring be_const_str_end;
|
||||
extern const bcstring be_const_str_import;
|
||||
extern const bcstring be_const_str_classof;
|
||||
extern const bcstring be_const_str_concat;
|
||||
extern const bcstring be_const_str_byte;
|
||||
extern const bcstring be_const_str_top;
|
||||
extern const bcstring be_const_str_clear;
|
||||
extern const bcstring be_const_str_opt_connect;
|
||||
extern const bcstring be_const_str_collect;
|
||||
extern const bcstring be_const_str_init;
|
||||
extern const bcstring be_const_str_log10;
|
||||
extern const bcstring be_const_str_nil;
|
||||
extern const bcstring be_const_str_;
|
||||
extern const bcstring be_const_str_real;
|
||||
extern const bcstring be_const_str_calldepth;
|
||||
extern const bcstring be_const_str_format;
|
||||
extern const bcstring be_const_str_pi;
|
||||
extern const bcstring be_const_str_do;
|
||||
extern const bcstring be_const_str___iterator__;
|
||||
extern const bcstring be_const_str_number;
|
||||
extern const bcstring be_const_str_type;
|
||||
extern const bcstring be_const_str_dot_p;
|
||||
extern const bcstring be_const_str_traceback;
|
||||
extern const bcstring be_const_str_as;
|
||||
extern const bcstring be_const_str___lower__;
|
||||
extern const bcstring be_const_str_exp;
|
||||
extern const bcstring be_const_str_hex;
|
||||
extern const bcstring be_const_str_char;
|
||||
extern const bcstring be_const_str_split;
|
||||
extern const bcstring be_const_str_toupper;
|
||||
extern const bcstring be_const_str_deinit;
|
||||
extern const bcstring be_const_str_tan;
|
||||
extern const bcstring be_const_str_srand;
|
||||
extern const bcstring be_const_str_imin;
|
||||
extern const bcstring be_const_str_input;
|
||||
extern const bcstring be_const_str_issubclass;
|
||||
extern const bcstring be_const_str_tostring;
|
||||
extern const bcstring be_const_str_break;
|
||||
extern const bcstring be_const_str_insert;
|
||||
extern const bcstring be_const_str_var;
|
||||
extern const bcstring be_const_str_open;
|
||||
extern const bcstring be_const_str_tanh;
|
||||
extern const bcstring be_const_str_upper;
|
||||
extern const bcstring be_const_str_allocated;
|
||||
extern const bcstring be_const_str_rad;
|
||||
extern const bcstring be_const_str_attrdump;
|
||||
extern const bcstring be_const_str_copy;
|
||||
extern const bcstring be_const_str_sqrt;
|
||||
extern const bcstring be_const_str_for;
|
||||
extern const bcstring be_const_str_raise;
|
||||
extern const bcstring be_const_str_opt_neq;
|
||||
extern const bcstring be_const_str_assert;
|
||||
extern const bcstring be_const_str_item;
|
||||
extern const bcstring be_const_str_reverse;
|
||||
extern const bcstring be_const_str_sin;
|
||||
extern const bcstring be_const_str_super;
|
||||
extern const bcstring be_const_str_try;
|
||||
extern const bcstring be_const_str_range;
|
||||
extern const bcstring be_const_str_return;
|
||||
extern const bcstring be_const_str_compile;
|
||||
extern const bcstring be_const_str_false;
|
||||
extern const bcstring be_const_str_resize;
|
||||
extern const bcstring be_const_str_continue;
|
||||
extern const bcstring be_const_str_log;
|
||||
extern const bcstring be_const_str_true;
|
||||
extern const bcstring be_const_str_while;
|
||||
extern const bcstring be_const_str_pow;
|
||||
extern const bcstring be_const_str_cos;
|
||||
extern const bcstring be_const_str_count;
|
||||
extern const bcstring be_const_str_remove;
|
||||
extern const bcstring be_const_str_imax;
|
||||
extern const bcstring be_const_str_rand;
|
||||
extern const bcstring be_const_str_codedump;
|
||||
extern const bcstring be_const_str_deg;
|
||||
extern const bcstring be_const_str_keys;
|
||||
extern const bcstring be_const_str_setitem;
|
||||
extern const bcstring be_const_str_def;
|
||||
extern const bcstring be_const_str_except;
|
||||
extern const bcstring be_const_str_classname;
|
||||
extern const bcstring be_const_str_isinstance;
|
||||
extern const bcstring be_const_str_cosh;
|
||||
extern const bcstring be_const_str_elif;
|
||||
extern const bcstring be_const_str_item;
|
||||
extern const bcstring be_const_str_push;
|
||||
extern const bcstring be_const_str_concat;
|
||||
extern const bcstring be_const_str_traceback;
|
||||
extern const bcstring be_const_str_upper;
|
||||
extern const bcstring be_const_str_true;
|
||||
extern const bcstring be_const_str_continue;
|
||||
extern const bcstring be_const_str_else;
|
||||
extern const bcstring be_const_str_cos;
|
||||
extern const bcstring be_const_str_for;
|
||||
|
@ -1,165 +1,172 @@
|
||||
be_define_const_str(acos, "acos", 1006755615u, 0, 4, &be_const_str_asin);
|
||||
be_define_const_str(asin, "asin", 4272848550u, 0, 4, &be_const_str_list);
|
||||
be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_module);
|
||||
be_define_const_str(module, "module", 3617558685u, 0, 6, &be_const_str_pop);
|
||||
be_define_const_str(pop, "pop", 1362321360u, 0, 3, NULL);
|
||||
be_define_const_str(int, "int", 2515107422u, 0, 3, &be_const_str_push);
|
||||
be_define_const_str(push, "push", 2272264157u, 0, 4, &be_const_str_setrange);
|
||||
be_define_const_str(setrange, "setrange", 3794019032u, 0, 8, &be_const_str_sinh);
|
||||
be_define_const_str(sinh, "sinh", 282220607u, 0, 4, &be_const_str_elif);
|
||||
be_define_const_str(elif, "elif", 3232090307u, 51, 4, NULL);
|
||||
be_define_const_str(iter, "iter", 3124256359u, 0, 4, &be_const_str_load);
|
||||
be_define_const_str(load, "load", 3859241449u, 0, 4, &be_const_str_class);
|
||||
be_define_const_str(class, "class", 2872970239u, 57, 5, &be_const_str_if);
|
||||
be_define_const_str(if, "if", 959999494u, 50, 2, NULL);
|
||||
be_define_const_str(opt_eq, "==", 2431966415u, 0, 2, &be_const_str_ceil);
|
||||
be_define_const_str(ceil, "ceil", 1659167240u, 0, 4, NULL);
|
||||
be_define_const_str(floor, "floor", 3102149661u, 0, 5, &be_const_str_map);
|
||||
be_define_const_str(map, "map", 3751997361u, 0, 3, &be_const_str_print);
|
||||
be_define_const_str(print, "print", 372738696u, 0, 5, &be_const_str_else);
|
||||
be_define_const_str(else, "else", 3183434736u, 52, 4, NULL);
|
||||
be_define_const_str(find, "find", 3186656602u, 0, 4, &be_const_str_str);
|
||||
be_define_const_str(str, "str", 3259748752u, 0, 3, NULL);
|
||||
be_define_const_str(__upper__, "__upper__", 3612202883u, 0, 9, &be_const_str_dump);
|
||||
be_define_const_str(dump, "dump", 3663001223u, 0, 4, NULL);
|
||||
be_define_const_str(atan, "atan", 108579519u, 0, 4, &be_const_str_size);
|
||||
be_define_const_str(size, "size", 597743964u, 0, 4, &be_const_str_tolower);
|
||||
be_define_const_str(tolower, "tolower", 1042520049u, 0, 7, NULL);
|
||||
be_define_const_str(opt_add, "+", 772578730u, 0, 1, &be_const_str_abs);
|
||||
be_define_const_str(abs, "abs", 709362235u, 0, 3, &be_const_str_lower);
|
||||
be_define_const_str(lower, "lower", 3038577850u, 0, 5, &be_const_str_end);
|
||||
be_define_const_str(end, "end", 1787721130u, 56, 3, &be_const_str_import);
|
||||
be_define_const_str(import, "import", 288002260u, 66, 6, NULL);
|
||||
be_define_const_str(classof, "classof", 1796577762u, 0, 7, &be_const_str_concat);
|
||||
be_define_const_str(concat, "concat", 4124019837u, 0, 6, NULL);
|
||||
be_define_const_str(byte, "byte", 1683620383u, 0, 4, &be_const_str_top);
|
||||
be_define_const_str(top, "top", 2802900028u, 0, 3, NULL);
|
||||
be_define_const_str(clear, "clear", 1550717474u, 0, 5, NULL);
|
||||
be_define_const_str(opt_connect, "..", 2748622605u, 0, 2, &be_const_str_collect);
|
||||
be_define_const_str(collect, "collect", 2399039025u, 0, 7, &be_const_str_init);
|
||||
be_define_const_str(init, "init", 380752755u, 0, 4, &be_const_str_log10);
|
||||
be_define_const_str(log10, "log10", 2346846000u, 0, 5, &be_const_str_nil);
|
||||
be_define_const_str(nil, "nil", 228849900u, 63, 3, NULL);
|
||||
be_define_const_str(, "", 2166136261u, 0, 0, &be_const_str_real);
|
||||
be_define_const_str(real, "real", 3604983901u, 0, 4, NULL);
|
||||
be_define_const_str(calldepth, "calldepth", 3122364302u, 0, 9, &be_const_str_format);
|
||||
be_define_const_str(format, "format", 3114108242u, 0, 6, &be_const_str_pi);
|
||||
be_define_const_str(pi, "pi", 1213090802u, 0, 2, &be_const_str_do);
|
||||
be_define_const_str(do, "do", 1646057492u, 65, 2, NULL);
|
||||
be_define_const_str(__iterator__, "__iterator__", 3884039703u, 0, 12, &be_const_str_number);
|
||||
be_define_const_str(number, "number", 467038368u, 0, 6, &be_const_str_type);
|
||||
be_define_const_str(type, "type", 1361572173u, 0, 4, NULL);
|
||||
be_define_const_str(dot_p, ".p", 1171526419u, 0, 2, &be_const_str_traceback);
|
||||
be_define_const_str(traceback, "traceback", 3385188109u, 0, 9, &be_const_str_as);
|
||||
be_define_const_str(as, "as", 1579491469u, 67, 2, NULL);
|
||||
be_define_const_str(__lower__, "__lower__", 123855590u, 0, 9, &be_const_str_exp);
|
||||
be_define_const_str(exp, "exp", 1923516200u, 0, 3, &be_const_str_hex);
|
||||
be_define_const_str(hex, "hex", 4273249610u, 0, 3, NULL);
|
||||
be_define_const_str(char, "char", 2823553821u, 0, 4, &be_const_str_split);
|
||||
be_define_const_str(split, "split", 2276994531u, 0, 5, &be_const_str_toupper);
|
||||
be_define_const_str(toupper, "toupper", 3691983576u, 0, 7, NULL);
|
||||
be_define_const_str(deinit, "deinit", 2345559592u, 0, 6, &be_const_str_tan);
|
||||
be_define_const_str(tan, "tan", 2633446552u, 0, 3, NULL);
|
||||
be_define_const_str(srand, "srand", 465518633u, 0, 5, NULL);
|
||||
be_define_const_str(imin, "imin", 2714127864u, 0, 4, &be_const_str_input);
|
||||
be_define_const_str(input, "input", 4191711099u, 0, 5, &be_const_str_issubclass);
|
||||
be_define_const_str(issubclass, "issubclass", 4078395519u, 0, 10, NULL);
|
||||
be_define_const_str(tostring, "tostring", 2299708645u, 0, 8, &be_const_str_break);
|
||||
be_define_const_str(break, "break", 3378807160u, 58, 5, NULL);
|
||||
be_define_const_str(insert, "insert", 3332609576u, 0, 6, &be_const_str_var);
|
||||
be_define_const_str(var, "var", 2317739966u, 64, 3, NULL);
|
||||
be_define_const_str(open, "open", 3546203337u, 0, 4, &be_const_str_tanh);
|
||||
be_define_const_str(tanh, "tanh", 153638352u, 0, 4, &be_const_str_upper);
|
||||
be_define_const_str(upper, "upper", 176974407u, 0, 5, NULL);
|
||||
be_define_const_str(allocated, "allocated", 429986098u, 0, 9, &be_const_str_rad);
|
||||
be_define_const_str(rad, "rad", 1358899048u, 0, 3, NULL);
|
||||
be_define_const_str(attrdump, "attrdump", 1521571304u, 0, 8, &be_const_str_copy);
|
||||
be_define_const_str(copy, "copy", 3848464964u, 0, 4, &be_const_str_sqrt);
|
||||
be_define_const_str(sqrt, "sqrt", 2112764879u, 0, 4, NULL);
|
||||
be_define_const_str(for, "for", 2901640080u, 54, 3, &be_const_str_raise);
|
||||
be_define_const_str(remove, "remove", 3683784189u, 0, 6, &be_const_str_false);
|
||||
be_define_const_str(false, "false", 184981848u, 62, 5, &be_const_str_raise);
|
||||
be_define_const_str(raise, "raise", 1593437475u, 70, 5, NULL);
|
||||
be_define_const_str(opt_neq, "!=", 2428715011u, 0, 2, &be_const_str_assert);
|
||||
be_define_const_str(assert, "assert", 2774883451u, 0, 6, &be_const_str_item);
|
||||
be_define_const_str(item, "item", 2671260646u, 0, 4, &be_const_str_reverse);
|
||||
be_define_const_str(reverse, "reverse", 558918661u, 0, 7, &be_const_str_sin);
|
||||
be_define_const_str(sin, "sin", 3761252941u, 0, 3, &be_const_str_super);
|
||||
be_define_const_str(super, "super", 4152230356u, 0, 5, &be_const_str_try);
|
||||
be_define_const_str(opt_connect, "..", 2748622605u, 0, 2, &be_const_str_dot_p);
|
||||
be_define_const_str(dot_p, ".p", 1171526419u, 0, 2, &be_const_str_calldepth);
|
||||
be_define_const_str(calldepth, "calldepth", 3122364302u, 0, 9, NULL);
|
||||
be_define_const_str(toupper, "toupper", 3691983576u, 0, 7, &be_const_str_break);
|
||||
be_define_const_str(break, "break", 3378807160u, 58, 5, NULL);
|
||||
be_define_const_str(map, "map", 3751997361u, 0, 3, NULL);
|
||||
be_define_const_str(bytes, "bytes", 1706151940u, 0, 5, &be_const_str_tanh);
|
||||
be_define_const_str(tanh, "tanh", 153638352u, 0, 4, NULL);
|
||||
be_define_const_str(real, "real", 3604983901u, 0, 4, NULL);
|
||||
be_define_const_str(count, "count", 967958004u, 0, 5, &be_const_str_setitem);
|
||||
be_define_const_str(setitem, "setitem", 1554834596u, 0, 7, &be_const_str_split);
|
||||
be_define_const_str(split, "split", 2276994531u, 0, 5, &be_const_str_if);
|
||||
be_define_const_str(if, "if", 959999494u, 50, 2, NULL);
|
||||
be_define_const_str(format, "format", 3114108242u, 0, 6, &be_const_str_pow);
|
||||
be_define_const_str(pow, "pow", 1479764693u, 0, 3, &be_const_str_tostring);
|
||||
be_define_const_str(tostring, "tostring", 2299708645u, 0, 8, NULL);
|
||||
be_define_const_str(load, "load", 3859241449u, 0, 4, &be_const_str_setrange);
|
||||
be_define_const_str(setrange, "setrange", 3794019032u, 0, 8, NULL);
|
||||
be_define_const_str(char, "char", 2823553821u, 0, 4, NULL);
|
||||
be_define_const_str(acos, "acos", 1006755615u, 0, 4, &be_const_str_deinit);
|
||||
be_define_const_str(deinit, "deinit", 2345559592u, 0, 6, &be_const_str_dump);
|
||||
be_define_const_str(dump, "dump", 3663001223u, 0, 4, &be_const_str_sqrt);
|
||||
be_define_const_str(sqrt, "sqrt", 2112764879u, 0, 4, NULL);
|
||||
be_define_const_str(fromstring, "fromstring", 610302344u, 0, 10, NULL);
|
||||
be_define_const_str(opt_eq, "==", 2431966415u, 0, 2, &be_const_str_asin);
|
||||
be_define_const_str(asin, "asin", 4272848550u, 0, 4, &be_const_str_byte);
|
||||
be_define_const_str(byte, "byte", 1683620383u, 0, 4, &be_const_str_copy);
|
||||
be_define_const_str(copy, "copy", 3848464964u, 0, 4, &be_const_str_floor);
|
||||
be_define_const_str(floor, "floor", 3102149661u, 0, 5, NULL);
|
||||
be_define_const_str(find, "find", 3186656602u, 0, 4, &be_const_str_var);
|
||||
be_define_const_str(var, "var", 2317739966u, 64, 3, NULL);
|
||||
be_define_const_str(opt_add, "+", 772578730u, 0, 1, &be_const_str___lower__);
|
||||
be_define_const_str(__lower__, "__lower__", 123855590u, 0, 9, &be_const_str_rand);
|
||||
be_define_const_str(rand, "rand", 2711325910u, 0, 4, &be_const_str_sin);
|
||||
be_define_const_str(sin, "sin", 3761252941u, 0, 3, NULL);
|
||||
be_define_const_str(deg, "deg", 3327754271u, 0, 3, &be_const_str_imin);
|
||||
be_define_const_str(imin, "imin", 2714127864u, 0, 4, &be_const_str_class);
|
||||
be_define_const_str(class, "class", 2872970239u, 57, 5, &be_const_str_try);
|
||||
be_define_const_str(try, "try", 2887626766u, 68, 3, NULL);
|
||||
be_define_const_str(range, "range", 4208725202u, 0, 5, &be_const_str_return);
|
||||
be_define_const_str(allocated, "allocated", 429986098u, 0, 9, &be_const_str_asstring);
|
||||
be_define_const_str(asstring, "asstring", 1298225088u, 0, 8, &be_const_str_classname);
|
||||
be_define_const_str(classname, "classname", 1998589948u, 0, 9, NULL);
|
||||
be_define_const_str(reverse, "reverse", 558918661u, 0, 7, NULL);
|
||||
be_define_const_str(assert, "assert", 2774883451u, 0, 6, &be_const_str_str);
|
||||
be_define_const_str(str, "str", 3259748752u, 0, 3, NULL);
|
||||
be_define_const_str(imax, "imax", 3084515410u, 0, 4, &be_const_str_init);
|
||||
be_define_const_str(init, "init", 380752755u, 0, 4, &be_const_str_except);
|
||||
be_define_const_str(except, "except", 950914032u, 69, 6, &be_const_str_return);
|
||||
be_define_const_str(return, "return", 2246981567u, 60, 6, NULL);
|
||||
be_define_const_str(compile, "compile", 1000265118u, 0, 7, &be_const_str_false);
|
||||
be_define_const_str(false, "false", 184981848u, 62, 5, NULL);
|
||||
be_define_const_str(resize, "resize", 3514612129u, 0, 6, NULL);
|
||||
be_define_const_str(continue, "continue", 2977070660u, 59, 8, NULL);
|
||||
be_define_const_str(log, "log", 1062293841u, 0, 3, &be_const_str_true);
|
||||
be_define_const_str(true, "true", 1303515621u, 61, 4, NULL);
|
||||
be_define_const_str(while, "while", 231090382u, 53, 5, NULL);
|
||||
be_define_const_str(pow, "pow", 1479764693u, 0, 3, NULL);
|
||||
be_define_const_str(cos, "cos", 4220379804u, 0, 3, &be_const_str_count);
|
||||
be_define_const_str(count, "count", 967958004u, 0, 5, &be_const_str_remove);
|
||||
be_define_const_str(remove, "remove", 3683784189u, 0, 6, NULL);
|
||||
be_define_const_str(imax, "imax", 3084515410u, 0, 4, &be_const_str_rand);
|
||||
be_define_const_str(rand, "rand", 2711325910u, 0, 4, NULL);
|
||||
be_define_const_str(codedump, "codedump", 1786337906u, 0, 8, &be_const_str_deg);
|
||||
be_define_const_str(deg, "deg", 3327754271u, 0, 3, &be_const_str_keys);
|
||||
be_define_const_str(keys, "keys", 4182378701u, 0, 4, &be_const_str_setitem);
|
||||
be_define_const_str(setitem, "setitem", 1554834596u, 0, 7, NULL);
|
||||
be_define_const_str(def, "def", 3310976652u, 55, 3, &be_const_str_except);
|
||||
be_define_const_str(except, "except", 950914032u, 69, 6, NULL);
|
||||
be_define_const_str(classname, "classname", 1998589948u, 0, 9, &be_const_str_isinstance);
|
||||
be_define_const_str(isinstance, "isinstance", 3669352738u, 0, 10, NULL);
|
||||
be_define_const_str(opt_neq, "!=", 2428715011u, 0, 2, &be_const_str_hex);
|
||||
be_define_const_str(hex, "hex", 4273249610u, 0, 3, &be_const_str_resize);
|
||||
be_define_const_str(resize, "resize", 3514612129u, 0, 6, &be_const_str_as);
|
||||
be_define_const_str(as, "as", 1579491469u, 67, 2, NULL);
|
||||
be_define_const_str(__upper__, "__upper__", 3612202883u, 0, 9, &be_const_str_codedump);
|
||||
be_define_const_str(codedump, "codedump", 1786337906u, 0, 8, &be_const_str_cosh);
|
||||
be_define_const_str(cosh, "cosh", 4099687964u, 0, 4, NULL);
|
||||
be_define_const_str(abs, "abs", 709362235u, 0, 3, &be_const_str_collect);
|
||||
be_define_const_str(collect, "collect", 2399039025u, 0, 7, NULL);
|
||||
be_define_const_str(atan, "atan", 108579519u, 0, 4, &be_const_str_attrdump);
|
||||
be_define_const_str(attrdump, "attrdump", 1521571304u, 0, 8, &be_const_str_input);
|
||||
be_define_const_str(input, "input", 4191711099u, 0, 5, NULL);
|
||||
be_define_const_str(, "", 2166136261u, 0, 0, &be_const_str_compile);
|
||||
be_define_const_str(compile, "compile", 1000265118u, 0, 7, &be_const_str_iter);
|
||||
be_define_const_str(iter, "iter", 3124256359u, 0, 4, &be_const_str_lower);
|
||||
be_define_const_str(lower, "lower", 3038577850u, 0, 5, &be_const_str_number);
|
||||
be_define_const_str(number, "number", 467038368u, 0, 6, &be_const_str_print);
|
||||
be_define_const_str(print, "print", 372738696u, 0, 5, NULL);
|
||||
be_define_const_str(exp, "exp", 1923516200u, 0, 3, &be_const_str_pi);
|
||||
be_define_const_str(pi, "pi", 1213090802u, 0, 2, NULL);
|
||||
be_define_const_str(__iterator__, "__iterator__", 3884039703u, 0, 12, &be_const_str_log);
|
||||
be_define_const_str(log, "log", 1062293841u, 0, 3, &be_const_str_log10);
|
||||
be_define_const_str(log10, "log10", 2346846000u, 0, 5, NULL);
|
||||
be_define_const_str(ceil, "ceil", 1659167240u, 0, 4, &be_const_str_get);
|
||||
be_define_const_str(get, "get", 1410115415u, 0, 3, &be_const_str_tolower);
|
||||
be_define_const_str(tolower, "tolower", 1042520049u, 0, 7, &be_const_str_while);
|
||||
be_define_const_str(while, "while", 231090382u, 53, 5, NULL);
|
||||
be_define_const_str(import, "import", 288002260u, 66, 6, NULL);
|
||||
be_define_const_str(size, "size", 597743964u, 0, 4, NULL);
|
||||
be_define_const_str(list, "list", 217798785u, 0, 4, &be_const_str_rad);
|
||||
be_define_const_str(rad, "rad", 1358899048u, 0, 3, &be_const_str_tan);
|
||||
be_define_const_str(tan, "tan", 2633446552u, 0, 3, &be_const_str_type);
|
||||
be_define_const_str(type, "type", 1361572173u, 0, 4, NULL);
|
||||
be_define_const_str(insert, "insert", 3332609576u, 0, 6, &be_const_str_module);
|
||||
be_define_const_str(module, "module", 3617558685u, 0, 6, &be_const_str_range);
|
||||
be_define_const_str(range, "range", 4208725202u, 0, 5, &be_const_str_super);
|
||||
be_define_const_str(super, "super", 4152230356u, 0, 5, NULL);
|
||||
be_define_const_str(issubclass, "issubclass", 4078395519u, 0, 10, &be_const_str_def);
|
||||
be_define_const_str(def, "def", 3310976652u, 55, 3, NULL);
|
||||
be_define_const_str(classof, "classof", 1796577762u, 0, 7, &be_const_str_sinh);
|
||||
be_define_const_str(sinh, "sinh", 282220607u, 0, 4, &be_const_str_srand);
|
||||
be_define_const_str(srand, "srand", 465518633u, 0, 5, NULL);
|
||||
be_define_const_str(end, "end", 1787721130u, 56, 3, NULL);
|
||||
be_define_const_str(clear, "clear", 1550717474u, 0, 5, &be_const_str_top);
|
||||
be_define_const_str(top, "top", 2802900028u, 0, 3, &be_const_str_nil);
|
||||
be_define_const_str(nil, "nil", 228849900u, 63, 3, NULL);
|
||||
be_define_const_str(open, "open", 3546203337u, 0, 4, &be_const_str_do);
|
||||
be_define_const_str(do, "do", 1646057492u, 65, 2, NULL);
|
||||
be_define_const_str(add, "add", 993596020u, 0, 3, &be_const_str_isinstance);
|
||||
be_define_const_str(isinstance, "isinstance", 3669352738u, 0, 10, &be_const_str_pop);
|
||||
be_define_const_str(pop, "pop", 1362321360u, 0, 3, NULL);
|
||||
be_define_const_str(int, "int", 2515107422u, 0, 3, &be_const_str_keys);
|
||||
be_define_const_str(keys, "keys", 4182378701u, 0, 4, &be_const_str_elif);
|
||||
be_define_const_str(elif, "elif", 3232090307u, 51, 4, NULL);
|
||||
be_define_const_str(item, "item", 2671260646u, 0, 4, &be_const_str_push);
|
||||
be_define_const_str(push, "push", 2272264157u, 0, 4, NULL);
|
||||
be_define_const_str(concat, "concat", 4124019837u, 0, 6, &be_const_str_traceback);
|
||||
be_define_const_str(traceback, "traceback", 3385188109u, 0, 9, &be_const_str_upper);
|
||||
be_define_const_str(upper, "upper", 176974407u, 0, 5, &be_const_str_true);
|
||||
be_define_const_str(true, "true", 1303515621u, 61, 4, NULL);
|
||||
be_define_const_str(continue, "continue", 2977070660u, 59, 8, NULL);
|
||||
be_define_const_str(else, "else", 3183434736u, 52, 4, NULL);
|
||||
be_define_const_str(cos, "cos", 4220379804u, 0, 3, &be_const_str_for);
|
||||
be_define_const_str(for, "for", 2901640080u, 54, 3, NULL);
|
||||
|
||||
static const bstring* const m_string_table[] = {
|
||||
(const bstring *)&be_const_str_remove,
|
||||
(const bstring *)&be_const_str_opt_connect,
|
||||
(const bstring *)&be_const_str_toupper,
|
||||
NULL,
|
||||
(const bstring *)&be_const_str_map,
|
||||
(const bstring *)&be_const_str_bytes,
|
||||
(const bstring *)&be_const_str_real,
|
||||
(const bstring *)&be_const_str_count,
|
||||
(const bstring *)&be_const_str_format,
|
||||
(const bstring *)&be_const_str_load,
|
||||
(const bstring *)&be_const_str_char,
|
||||
(const bstring *)&be_const_str_acos,
|
||||
NULL,
|
||||
(const bstring *)&be_const_str_int,
|
||||
NULL,
|
||||
(const bstring *)&be_const_str_iter,
|
||||
(const bstring *)&be_const_str_fromstring,
|
||||
(const bstring *)&be_const_str_opt_eq,
|
||||
(const bstring *)&be_const_str_floor,
|
||||
(const bstring *)&be_const_str_find,
|
||||
(const bstring *)&be_const_str___upper__,
|
||||
(const bstring *)&be_const_str_atan,
|
||||
(const bstring *)&be_const_str_opt_add,
|
||||
NULL,
|
||||
(const bstring *)&be_const_str_classof,
|
||||
(const bstring *)&be_const_str_byte,
|
||||
(const bstring *)&be_const_str_clear,
|
||||
(const bstring *)&be_const_str_opt_connect,
|
||||
(const bstring *)&be_const_str_,
|
||||
(const bstring *)&be_const_str_calldepth,
|
||||
(const bstring *)&be_const_str___iterator__,
|
||||
(const bstring *)&be_const_str_dot_p,
|
||||
(const bstring *)&be_const_str___lower__,
|
||||
(const bstring *)&be_const_str_char,
|
||||
(const bstring *)&be_const_str_deinit,
|
||||
(const bstring *)&be_const_str_srand,
|
||||
(const bstring *)&be_const_str_imin,
|
||||
(const bstring *)&be_const_str_tostring,
|
||||
(const bstring *)&be_const_str_insert,
|
||||
(const bstring *)&be_const_str_open,
|
||||
(const bstring *)&be_const_str_deg,
|
||||
(const bstring *)&be_const_str_allocated,
|
||||
(const bstring *)&be_const_str_attrdump,
|
||||
(const bstring *)&be_const_str_for,
|
||||
(const bstring *)&be_const_str_opt_neq,
|
||||
(const bstring *)&be_const_str_range,
|
||||
(const bstring *)&be_const_str_compile,
|
||||
(const bstring *)&be_const_str_resize,
|
||||
(const bstring *)&be_const_str_continue,
|
||||
(const bstring *)&be_const_str_log,
|
||||
(const bstring *)&be_const_str_while,
|
||||
(const bstring *)&be_const_str_pow,
|
||||
(const bstring *)&be_const_str_cos,
|
||||
(const bstring *)&be_const_str_reverse,
|
||||
(const bstring *)&be_const_str_assert,
|
||||
(const bstring *)&be_const_str_imax,
|
||||
(const bstring *)&be_const_str_codedump,
|
||||
(const bstring *)&be_const_str_def,
|
||||
(const bstring *)&be_const_str_classname,
|
||||
(const bstring *)&be_const_str_cosh
|
||||
(const bstring *)&be_const_str_opt_neq,
|
||||
(const bstring *)&be_const_str___upper__,
|
||||
(const bstring *)&be_const_str_abs,
|
||||
(const bstring *)&be_const_str_atan,
|
||||
(const bstring *)&be_const_str_,
|
||||
NULL,
|
||||
(const bstring *)&be_const_str_exp,
|
||||
(const bstring *)&be_const_str___iterator__,
|
||||
(const bstring *)&be_const_str_ceil,
|
||||
(const bstring *)&be_const_str_import,
|
||||
(const bstring *)&be_const_str_size,
|
||||
(const bstring *)&be_const_str_list,
|
||||
(const bstring *)&be_const_str_insert,
|
||||
(const bstring *)&be_const_str_issubclass,
|
||||
(const bstring *)&be_const_str_classof,
|
||||
(const bstring *)&be_const_str_end,
|
||||
(const bstring *)&be_const_str_clear,
|
||||
(const bstring *)&be_const_str_open,
|
||||
(const bstring *)&be_const_str_add,
|
||||
(const bstring *)&be_const_str_int,
|
||||
(const bstring *)&be_const_str_item,
|
||||
(const bstring *)&be_const_str_concat,
|
||||
(const bstring *)&be_const_str_continue,
|
||||
(const bstring *)&be_const_str_else,
|
||||
(const bstring *)&be_const_str_cos
|
||||
};
|
||||
|
||||
static const struct bconststrtab m_const_string_table = {
|
||||
.size = 45,
|
||||
.count = 90,
|
||||
.size = 47,
|
||||
.count = 95,
|
||||
.table = m_string_table
|
||||
};
|
||||
|
33
lib/libesp32/Berry-0.1.10/generate/be_fixed_be_class_bytes.h
Normal file
33
lib/libesp32/Berry-0.1.10/generate/be_fixed_be_class_bytes.h
Normal file
@ -0,0 +1,33 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_bytes_map) {
|
||||
{ be_const_key(copy, -1), be_const_func(m_copy) },
|
||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
|
||||
{ be_const_key(item, -1), be_const_func(m_item) },
|
||||
{ be_const_key(init, 8), be_const_func(m_init) },
|
||||
{ be_const_key(size, 6), be_const_func(m_size) },
|
||||
{ be_const_key(opt_connect, 7), be_const_func(m_connect) },
|
||||
{ be_const_key(opt_add, -1), be_const_func(m_merge) },
|
||||
{ be_const_key(fromstring, -1), be_const_func(m_fromstring) },
|
||||
{ be_const_key(opt_eq, 14), be_const_func(m_equal) },
|
||||
{ be_const_key(get, 1), be_const_func(m_get) },
|
||||
{ be_const_key(asstring, 5), be_const_func(m_asstring) },
|
||||
{ be_const_key(add, -1), be_const_func(m_add) },
|
||||
{ be_const_key(dot_p, -1), be_const_int(0) },
|
||||
{ be_const_key(clear, -1), be_const_func(m_clear) },
|
||||
{ be_const_key(opt_neq, 4), be_const_func(m_nequal) },
|
||||
{ be_const_key(resize, 9), be_const_func(m_resize) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_bytes_map,
|
||||
17
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
be_class_bytes,
|
||||
1,
|
||||
NULL,
|
||||
bytes
|
||||
);
|
@ -1,31 +1,32 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_list_map) {
|
||||
{ be_const_key(pop, -1), be_const_func(m_pop) },
|
||||
{ be_const_key(reverse, -1), be_const_func(m_reverse) },
|
||||
{ be_const_key(concat, -1), be_const_func(m_concat) },
|
||||
{ be_const_key(push, -1), be_const_func(m_push) },
|
||||
{ be_const_key(init, -1), be_const_func(m_init) },
|
||||
{ be_const_key(copy, 8), be_const_func(m_copy) },
|
||||
{ be_const_key(opt_connect, 13), be_const_func(m_connect) },
|
||||
{ be_const_key(item, -1), be_const_func(m_item) },
|
||||
{ be_const_key(remove, -1), be_const_func(m_remove) },
|
||||
{ be_const_key(size, -1), be_const_func(m_size) },
|
||||
{ be_const_key(resize, 7), be_const_func(m_resize) },
|
||||
{ be_const_key(opt_add, -1), be_const_func(m_merge) },
|
||||
{ be_const_key(opt_neq, -1), be_const_func(m_nequal) },
|
||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||
{ be_const_key(tostring, -1), be_const_func(m_tostring) },
|
||||
{ be_const_key(insert, 1), be_const_func(m_insert) },
|
||||
{ be_const_key(find, -1), be_const_func(m_find) },
|
||||
{ be_const_key(remove, 9), be_const_func(m_remove) },
|
||||
{ be_const_key(clear, -1), be_const_func(m_clear) },
|
||||
{ be_const_key(opt_eq, 3), be_const_func(m_equal) },
|
||||
{ be_const_key(insert, 12), be_const_func(m_insert) },
|
||||
{ be_const_key(concat, 2), be_const_func(m_concat) },
|
||||
{ be_const_key(dot_p, -1), be_const_int(0) },
|
||||
{ be_const_key(iter, 18), be_const_func(m_iter) },
|
||||
{ be_const_key(size, -1), be_const_func(m_size) },
|
||||
{ be_const_key(resize, 13), be_const_func(m_resize) },
|
||||
{ be_const_key(copy, -1), be_const_func(m_copy) },
|
||||
{ be_const_key(pop, -1), be_const_func(m_pop) },
|
||||
{ be_const_key(tostring, 3), be_const_func(m_tostring) },
|
||||
{ be_const_key(opt_eq, -1), be_const_func(m_equal) },
|
||||
{ be_const_key(init, -1), be_const_func(m_init) },
|
||||
{ be_const_key(dot_p, 17), be_const_int(0) },
|
||||
{ be_const_key(setitem, -1), be_const_func(m_setitem) },
|
||||
{ be_const_key(opt_connect, 4), be_const_func(m_connect) },
|
||||
{ be_const_key(opt_neq, -1), be_const_func(m_nequal) },
|
||||
{ be_const_key(opt_add, 18), be_const_func(m_merge) },
|
||||
{ be_const_key(iter, 20), be_const_func(m_iter) },
|
||||
{ be_const_key(item, -1), be_const_func(m_item) },
|
||||
{ be_const_key(reverse, -1), be_const_func(m_reverse) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_list_map,
|
||||
20
|
||||
21
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
@ -1,37 +1,39 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(m_builtin_map) {
|
||||
{ be_const_key(map, 11), be_const_int(10) },
|
||||
{ be_const_key(str, 14), be_const_int(18) },
|
||||
{ be_const_key(int, -1), be_const_int(6) },
|
||||
{ be_const_key(type, -1), be_const_int(20) },
|
||||
{ be_const_key(assert, -1), be_const_int(1) },
|
||||
{ be_const_key(issubclass, -1), be_const_int(8) },
|
||||
{ be_const_key(number, 7), be_const_int(12) },
|
||||
{ be_const_key(compile, 8), be_const_int(4) },
|
||||
{ be_const_key(module, 18), be_const_int(11) },
|
||||
{ be_const_key(input, 5), be_const_int(5) },
|
||||
{ be_const_key(super, -1), be_const_int(19) },
|
||||
{ be_const_key(classof, -1), be_const_int(3) },
|
||||
{ be_const_key(open, 13), be_const_int(13) },
|
||||
{ be_const_key(print, 19), be_const_int(15) },
|
||||
{ be_const_key(isinstance, -1), be_const_int(8) },
|
||||
{ be_const_key(classname, -1), be_const_int(3) },
|
||||
{ be_const_key(module, -1), be_const_int(12) },
|
||||
{ be_const_key(size, -1), be_const_int(18) },
|
||||
{ be_const_key(type, 9), be_const_int(21) },
|
||||
{ be_const_key(compile, -1), be_const_int(5) },
|
||||
{ be_const_key(open, -1), be_const_int(14) },
|
||||
{ be_const_key(real, -1), be_const_int(17) },
|
||||
{ be_const_key(__iterator__, -1), be_const_int(0) },
|
||||
{ be_const_key(real, 10), be_const_int(16) },
|
||||
{ be_const_key(list, 20), be_const_int(9) },
|
||||
{ be_const_key(isinstance, -1), be_const_int(7) },
|
||||
{ be_const_key(range, -1), be_const_int(15) },
|
||||
{ be_const_key(size, -1), be_const_int(17) },
|
||||
{ be_const_key(classname, -1), be_const_int(2) },
|
||||
{ be_const_key(print, -1), be_const_int(14) },
|
||||
{ be_const_key(super, -1), be_const_int(20) },
|
||||
{ be_const_key(issubclass, -1), be_const_int(9) },
|
||||
{ be_const_key(classof, -1), be_const_int(4) },
|
||||
{ be_const_key(map, 8), be_const_int(11) },
|
||||
{ be_const_key(int, 2), be_const_int(7) },
|
||||
{ be_const_key(input, 3), be_const_int(6) },
|
||||
{ be_const_key(number, -1), be_const_int(13) },
|
||||
{ be_const_key(list, 7), be_const_int(10) },
|
||||
{ be_const_key(str, 1), be_const_int(19) },
|
||||
{ be_const_key(range, -1), be_const_int(16) },
|
||||
{ be_const_key(bytes, -1), be_const_int(2) },
|
||||
{ be_const_key(assert, -1), be_const_int(1) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
m_builtin_map,
|
||||
21
|
||||
22
|
||||
);
|
||||
|
||||
static const bvalue __vlist_array[] = {
|
||||
be_const_func(l_iterator),
|
||||
be_const_func(l_assert),
|
||||
be_const_class(be_class_bytes),
|
||||
be_const_func(l_classname),
|
||||
be_const_func(l_classof),
|
||||
be_const_func(l_compile),
|
||||
@ -56,5 +58,5 @@ static const bvalue __vlist_array[] = {
|
||||
static be_define_const_vector(
|
||||
m_builtin_vector,
|
||||
__vlist_array,
|
||||
21
|
||||
22
|
||||
);
|
||||
|
@ -1,20 +0,0 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(m_libpath_map) {
|
||||
{ be_const_key(isdir, -1), be_const_func(m_path_isdir) },
|
||||
{ be_const_key(join, 2), be_const_func(m_path_join) },
|
||||
{ be_const_key(exists, -1), be_const_func(m_path_exists) },
|
||||
{ be_const_key(split, -1), be_const_func(m_path_split) },
|
||||
{ be_const_key(splitext, -1), be_const_func(m_path_splitext) },
|
||||
{ be_const_key(isfile, -1), be_const_func(m_path_isfile) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
m_libpath_map,
|
||||
6
|
||||
);
|
||||
|
||||
static be_define_const_module(
|
||||
m_libpath,
|
||||
"path"
|
||||
);
|
@ -313,6 +313,7 @@ void be_load_baselib(bvm *vm)
|
||||
extern const bclass be_class_list;
|
||||
extern const bclass be_class_map;
|
||||
extern const bclass be_class_range;
|
||||
extern const bclass be_class_bytes;
|
||||
extern int be_nfunc_open(bvm *vm);
|
||||
/* @const_object_info_begin
|
||||
vartab m_builtin (scope: local) {
|
||||
@ -337,6 +338,7 @@ vartab m_builtin (scope: local) {
|
||||
list, class(be_class_list)
|
||||
map, class(be_class_map)
|
||||
range, class(be_class_range)
|
||||
bytes, class(be_class_bytes)
|
||||
}
|
||||
@const_object_info_end */
|
||||
#include "../generate/be_fixed_m_builtin.h"
|
||||
|
668
lib/libesp32/Berry-0.1.10/src/be_byteslib.c
Normal file
668
lib/libesp32/Berry-0.1.10/src/be_byteslib.c
Normal file
@ -0,0 +1,668 @@
|
||||
/********************************************************************
|
||||
** Copyright (c) 2018-2020 Guan Wenliang - Stephan Hadinger
|
||||
** This file is part of the Berry default interpreter.
|
||||
** skiars@qq.com, https://github.com/Skiars/berry
|
||||
** See Copyright Notice in the LICENSE file or at
|
||||
** https://github.com/Skiars/berry/blob/master/LICENSE
|
||||
********************************************************************/
|
||||
#include "be_object.h"
|
||||
#include "be_string.h"
|
||||
#include "be_strlib.h"
|
||||
#include "be_list.h"
|
||||
#include "be_func.h"
|
||||
#include "be_exec.h"
|
||||
#include "be_vm.h"
|
||||
#include "be_mem.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define BYTES_DEFAULT_SIZE 28 // default pre-reserved size for buffer (keep 4 bytes for len/size)
|
||||
#define BYTES_MAX_SIZE (32*1024) // max 32Kb
|
||||
#define BYTES_OVERHEAD 4 // bytes overhead to be added when allocating (used to store len and size)
|
||||
#define BYTES_HEADROOM 8 // keep a natural headroom of 8 bytes when resizing
|
||||
|
||||
typedef struct buf_impl {
|
||||
uint16_t size; // size in bytes of the buffer
|
||||
uint16_t len; // current size of the data in buffer. Invariant: len <= size
|
||||
uint8_t buf[]; // the actual data
|
||||
} buf_impl;
|
||||
|
||||
/********************************************************************
|
||||
** Buffer low-level implementation
|
||||
**
|
||||
** Extracted from Tasmota SBuffer lib
|
||||
********************************************************************/
|
||||
static inline uint8_t* buf_get_buf(buf_impl* buf) {
|
||||
return &buf->buf[0];
|
||||
}
|
||||
|
||||
// shrink or increase. If increase, fill with zeores. Cannot go beyond `size`
|
||||
static void buf_set_len(buf_impl* buf, const size_t len) {
|
||||
uint16_t old_len = buf->len;
|
||||
buf->len = (len <= buf->size) ? len : buf->size;
|
||||
if (old_len < buf->len) {
|
||||
memset((void*) &buf->buf[old_len], 0, buf->len - old_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void buf_set1(buf_impl* buf, const size_t offset, const uint8_t data) {
|
||||
if (offset < buf->len) {
|
||||
buf->buf[offset] = data;
|
||||
}
|
||||
}
|
||||
static size_t buf_add1(buf_impl* buf, const uint8_t data) { // append 8 bits value
|
||||
if (buf->len < buf->size) { // do we have room for 1 byte
|
||||
buf->buf[buf->len++] = data;
|
||||
}
|
||||
return buf->len;
|
||||
}
|
||||
static size_t buf_add2_le(buf_impl* buf, const uint16_t data) { // append 16 bits value
|
||||
if (buf->len < buf->size - 1) { // do we have room for 2 bytes
|
||||
buf->buf[buf->len++] = data;
|
||||
buf->buf[buf->len++] = data >> 8;
|
||||
}
|
||||
return buf->len;
|
||||
}
|
||||
static size_t buf_add2_be(buf_impl* buf, const uint16_t data) { // append 16 bits value
|
||||
if (buf->len < buf->size - 1) { // do we have room for 2 bytes
|
||||
buf->buf[buf->len++] = data >> 8;
|
||||
buf->buf[buf->len++] = data;
|
||||
}
|
||||
return buf->len;
|
||||
}
|
||||
static size_t buf_add4_le(buf_impl* buf, const uint32_t data) { // append 32 bits value
|
||||
if (buf->len < buf->size - 3) { // do we have room for 4 bytes
|
||||
buf->buf[buf->len++] = data;
|
||||
buf->buf[buf->len++] = data >> 8;
|
||||
buf->buf[buf->len++] = data >> 16;
|
||||
buf->buf[buf->len++] = data >> 24;
|
||||
}
|
||||
return buf->len;
|
||||
}
|
||||
size_t buf_add4_be(buf_impl* buf, const uint32_t data) { // append 32 bits value
|
||||
if (buf->len < buf->size - 3) { // do we have room for 4 bytes
|
||||
buf->buf[buf->len++] = data >> 24;
|
||||
buf->buf[buf->len++] = data >> 16;
|
||||
buf->buf[buf->len++] = data >> 8;
|
||||
buf->buf[buf->len++] = data;
|
||||
}
|
||||
return buf->len;
|
||||
}
|
||||
|
||||
static size_t buf_add_buf(buf_impl* buf, buf_impl* buf2) {
|
||||
if (buf->len + buf2->len <= buf->size) {
|
||||
for (uint32_t i = 0; i < buf2->len; i++) {
|
||||
buf->buf[buf->len++] = buf2->buf[i];
|
||||
}
|
||||
}
|
||||
return buf->len;
|
||||
}
|
||||
|
||||
static uint8_t buf_get1(buf_impl* buf, int offset) {
|
||||
if ((offset >= 0) && (offset < buf->len)) {
|
||||
return buf->buf[offset];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static uint16_t buf_get2_le(buf_impl* buf, int offset) {
|
||||
if ((offset >= 0) && (offset < buf->len - 1)) {
|
||||
return buf->buf[offset] | (buf->buf[offset+1] << 8);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static uint16_t buf_get2_be(buf_impl* buf, int offset) {
|
||||
if (offset < buf->len - 1) {
|
||||
return buf->buf[offset+1] | (buf->buf[offset] << 8);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static uint32_t buf_get4_le(buf_impl* buf, int offset) {
|
||||
if ((offset >= 0) && (offset < buf->len - 3)) {
|
||||
return buf->buf[offset] | (buf->buf[offset+1] << 8) |
|
||||
(buf->buf[offset+2] << 16) | (buf->buf[offset+3] << 24);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static uint32_t buf_get4_be(buf_impl* buf, int offset) {
|
||||
if (offset < buf->len - 3) {
|
||||
return buf->buf[offset+3] | (buf->buf[offset+2] << 8) |
|
||||
(buf->buf[offset+1] << 16) | (buf->buf[offset] << 24);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// nullptr accepted
|
||||
static bbool buf_equals(buf_impl* buf1, buf_impl* buf2) {
|
||||
if (buf1 == buf2) { return btrue; }
|
||||
if (!buf1 || !buf2) { return bfalse; } // at least one buf is not empty
|
||||
// we know that both buf1 and buf2 are non-null
|
||||
if (buf1->len != buf2->len) { return bfalse; }
|
||||
size_t len = buf1->len;
|
||||
for (uint32_t i=0; i<len; i++) {
|
||||
if (buf_get1(buf1, i) != buf_get1(buf2, i)) { return bfalse; }
|
||||
}
|
||||
return btrue;
|
||||
}
|
||||
|
||||
static uint8_t asc2byte(char chr) {
|
||||
uint8_t rVal = 0;
|
||||
if (isdigit(chr)) { rVal = chr - '0'; }
|
||||
else if (chr >= 'A' && chr <= 'F') { rVal = chr + 10 - 'A'; }
|
||||
else if (chr >= 'a' && chr <= 'f') { rVal = chr + 10 - 'a'; }
|
||||
return rVal;
|
||||
}
|
||||
// does not check if there is enough room before hand, truncated if buffer too small
|
||||
static void buf_add_hex(buf_impl* buf, const char *hex, size_t len) {
|
||||
uint8_t val;
|
||||
for (; len > 1; len -= 2) {
|
||||
val = asc2byte(*hex++) << 4;
|
||||
val |= asc2byte(*hex++);
|
||||
buf_add1(buf, val);
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
** Wrapping into lib
|
||||
********************************************************************/
|
||||
// typedef int (*bntvfunc)(bvm*); /* native function pointer */
|
||||
int free_bytes_buf(bvm* vm) {
|
||||
int argc = be_top(vm);
|
||||
if (argc > 0) {
|
||||
buf_impl * buf = (buf_impl*) be_tocomptr(vm, 1);
|
||||
if (buf != NULL) {
|
||||
be_os_free(buf);
|
||||
}
|
||||
}
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
buf_impl * bytes_alloc(int32_t size)
|
||||
{
|
||||
if (size < 4) { size = 4; }
|
||||
if (size > BYTES_MAX_SIZE) { size = BYTES_MAX_SIZE; }
|
||||
buf_impl * next = (buf_impl*) be_os_malloc(size + BYTES_OVERHEAD);
|
||||
next->size = size;
|
||||
next->len = 0;
|
||||
return next;
|
||||
}
|
||||
|
||||
/* allocate a new `bytes` object with pre-allocated size */
|
||||
static void bytes_new_object(bvm *vm, size_t size)
|
||||
{
|
||||
be_getglobal(vm, "bytes"); /* eventually change with be_getbuiltin */
|
||||
be_call(vm, 0); /* stack has only instance */
|
||||
be_getmember(vm, -1, "init");
|
||||
be_pushvalue(vm, -2);
|
||||
be_pushint(vm, size); /* stack: instance, init func, instance, size */
|
||||
be_call(vm, 2); /* stack: instance, ret, instance, size */
|
||||
be_pop(vm, 3); /* remove ret, instance, size */
|
||||
}
|
||||
|
||||
static int m_init(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
int size = BYTES_DEFAULT_SIZE;
|
||||
const char * hex_in = NULL;
|
||||
if (argc > 1 && be_isint(vm, 2)) {
|
||||
int new_size = be_toint(vm, 2) + BYTES_HEADROOM;
|
||||
if (new_size > size) {
|
||||
size = new_size;
|
||||
}
|
||||
} else if (argc > 1 && be_isstring(vm, 2)) {
|
||||
hex_in = be_tostring(vm, 2);
|
||||
if (hex_in) {
|
||||
size = strlen(hex_in) / 2 + BYTES_HEADROOM; // allocate headroom
|
||||
}
|
||||
}
|
||||
buf_impl * buf = bytes_alloc(size);
|
||||
if (!buf) {
|
||||
be_throw(vm, BE_MALLOC_FAIL);
|
||||
}
|
||||
|
||||
if (hex_in) {
|
||||
buf_add_hex(buf, hex_in, strlen(hex_in));
|
||||
}
|
||||
be_newcomobj(vm, buf, &free_bytes_buf);
|
||||
be_setmember(vm, 1, ".p");
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
/* grow or shrink to the exact value */
|
||||
/* stack item 1 must contain the instance */
|
||||
static buf_impl * _bytes_resize(bvm *vm, buf_impl * buf, size_t new_size) {
|
||||
buf_impl * new_buf = bytes_alloc(new_size);
|
||||
if (!new_buf) {
|
||||
be_throw(vm, BE_MALLOC_FAIL);
|
||||
}
|
||||
memmove(buf_get_buf(new_buf), buf_get_buf(buf), buf->len);
|
||||
new_buf->len = buf->len;
|
||||
/* replace the .p attribute */
|
||||
be_newcomobj(vm, new_buf, &free_bytes_buf);
|
||||
be_setmember(vm, 1, ".p");
|
||||
be_pop(vm, 1); /* remove comobj from stack */
|
||||
/* the old buffer will be garbage collected later */
|
||||
return new_buf;
|
||||
}
|
||||
|
||||
/* grow if needed but don't shrink */
|
||||
/* if grow, then add some headroom */
|
||||
/* stack item 1 must contain the instance */
|
||||
static buf_impl * bytes_resize(bvm *vm, buf_impl * buf, size_t new_size) {
|
||||
if (buf->size >= new_size) { return buf; } /* no resize needed */
|
||||
return _bytes_resize(vm, buf, new_size + BYTES_HEADROOM);
|
||||
}
|
||||
|
||||
static buf_impl * bytes_check_data(bvm *vm, size_t add_size) {
|
||||
be_getmember(vm, 1, ".p");
|
||||
buf_impl * buf = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1); /* remove member from stack */
|
||||
/* check if the `size` is big enough */
|
||||
if (buf->len + add_size > buf->size) {
|
||||
/* it does not fit so we need to realocate the buffer */
|
||||
buf = bytes_resize(vm, buf, buf->len + add_size);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static size_t tohex(char * out, size_t outsz, const uint8_t * in, size_t insz) {
|
||||
static const char * hex = "0123456789ABCDEF";
|
||||
const uint8_t * pin = in;
|
||||
char * pout = out;
|
||||
for (; pin < in + insz; pout += 2, pin++) {
|
||||
pout[0] = hex[((*pin)>>4) & 0xF];
|
||||
pout[1] = hex[ (*pin) & 0xF];
|
||||
if (pout + 3 > out + outsz) { break; } /* check overflow */
|
||||
}
|
||||
pout[0] = 0; /* terminating Nul char */
|
||||
return pout - out;
|
||||
}
|
||||
|
||||
static int m_tostring(bvm *vm)
|
||||
{
|
||||
buf_impl * buf = bytes_check_data(vm, 0);
|
||||
size_t len = buf->len;
|
||||
size_t hex_len = len * 2 + 5 + 2 + 2 + 1; /* reserve size for `bytes("")\0` - 9 chars */
|
||||
|
||||
char * hex_out = be_pushbuffer(vm, hex_len);
|
||||
size_t l = strlcpy(hex_out, "bytes('", hex_len);
|
||||
l += tohex(&hex_out[l], hex_len - l, buf_get_buf(buf), buf->len);
|
||||
l += strlcpy(&hex_out[l], "')", hex_len - l);
|
||||
|
||||
be_pushnstring(vm, hex_out, l); /* make escape string from buffer */
|
||||
be_remove(vm, -2); /* remove buffer */
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the buffer into a string without any changes
|
||||
*/
|
||||
static int m_asstring(bvm *vm)
|
||||
{
|
||||
buf_impl * buf = bytes_check_data(vm, 0);
|
||||
be_pushnstring(vm, (const char*) buf_get_buf(buf), buf->len);
|
||||
be_return(vm);
|
||||
}
|
||||
static int m_fromstring(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
if (argc >= 2 && be_isstring(vm, 2)) {
|
||||
const char *s = be_tostring(vm, 2);
|
||||
size_t len = strlen(s);
|
||||
buf_impl * buf = bytes_check_data(vm, 0);
|
||||
buf = bytes_resize(vm, buf, len); /* resize if needed */
|
||||
if (len > buf->size) { len = buf->size; } /* avoid overflow */
|
||||
memmove(buf_get_buf(buf), s, len);
|
||||
buf->len = len;
|
||||
be_pop(vm, 1); /* remove arg to leave instance */
|
||||
be_return(vm);
|
||||
}
|
||||
be_raise(vm, "type_error", "operand must be a string");
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an int made of 1, 2 or 4 bytes, in little or big endian
|
||||
* `add(value:int[, size:int = 1]) -> instance`
|
||||
*
|
||||
* size: may be 1, 2, 4 (little endian), or -1, -2, -4 (big endian)
|
||||
* obvisouly -1 is idntical to 1
|
||||
* size==0 does nothing
|
||||
*/
|
||||
static int m_add(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
buf_impl * buf = bytes_check_data(vm, 4); /* we reserve 4 bytes anyways */
|
||||
if (argc >= 2 && be_isint(vm, 2)) {
|
||||
int32_t v = be_toint(vm, 2);
|
||||
int vsize = 1;
|
||||
if (argc >= 3 && be_isint(vm, 3)) {
|
||||
vsize = be_toint(vm, 3);
|
||||
}
|
||||
switch (vsize) {
|
||||
case 0: break;
|
||||
case -1: /* fallback below */
|
||||
case 1: buf_add1(buf, v); break;
|
||||
case 2: buf_add2_le(buf, v); break;
|
||||
case 4: buf_add4_le(buf, v); break;
|
||||
case -2: buf_add2_be(buf, v); break;
|
||||
case -4: buf_add4_be(buf, v); break;
|
||||
default: be_raise(vm, "type_error", "size must be -4, -2, -1, 0, 1, 2 or 4.");
|
||||
}
|
||||
be_pop(vm, argc - 1);
|
||||
be_return(vm);
|
||||
}
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get an int made of 1, 2 or 4 bytes, in little or big endian
|
||||
* `get(index:int[, size:int = 1]) -> instance`
|
||||
*
|
||||
* size: may be 1, 2, 4 (little endian), or -1, -2, -4 (big endian)
|
||||
* obvisouly -1 is idntical to 1
|
||||
* 0 returns nil
|
||||
*/
|
||||
static int m_get(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
buf_impl * buf = bytes_check_data(vm, 0); /* we reserve 4 bytes anyways */
|
||||
if (argc >=2 && be_isint(vm, 2)) {
|
||||
int32_t idx = be_toint(vm, 2);
|
||||
int vsize = 1;
|
||||
if (argc >= 3 && be_isint(vm, 3)) {
|
||||
vsize = be_toint(vm, 3);
|
||||
}
|
||||
int ret = 0;
|
||||
switch (vsize) {
|
||||
case 0: break;
|
||||
case -1: /* fallback below */
|
||||
case 1: ret = buf_get1(buf, idx); break;
|
||||
case 2: ret = buf_get2_le(buf, idx); break;
|
||||
case 4: ret = buf_get4_le(buf, idx); break;
|
||||
case -2: ret = buf_get2_be(buf, idx); break;
|
||||
case -4: ret = buf_get4_be(buf, idx); break;
|
||||
default: be_raise(vm, "type_error", "size must be -4, -2, -1, 0, 1, 2 or 4.");
|
||||
}
|
||||
be_pop(vm, argc - 1);
|
||||
if (vsize != 0) {
|
||||
be_pushint(vm, ret);
|
||||
} else {
|
||||
be_pushnil(vm);
|
||||
}
|
||||
be_return(vm);
|
||||
}
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
|
||||
static int m_setitem(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
buf_impl * buf = bytes_check_data(vm, 0); /* we reserve 4 bytes anyways */
|
||||
if (argc >=3 && be_isint(vm, 2) && be_isint(vm, 3)) {
|
||||
int index = be_toint(vm, 2);
|
||||
int val = be_toint(vm, 3);
|
||||
if (index >= 0 && index < buf->len) {
|
||||
buf_set1(buf, index, val);
|
||||
be_return_nil(vm);
|
||||
}
|
||||
}
|
||||
be_raise(vm, "index_error", "bytes index out of range or value non int");
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
static int m_item(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
buf_impl * buf = bytes_check_data(vm, 0); /* we reserve 4 bytes anyways */
|
||||
if (argc >=2 && be_isint(vm, 2)) {
|
||||
int index = be_toint(vm,2);
|
||||
if (index >= 0 && index < buf->len) {
|
||||
be_pushint(vm, buf_get1(buf, index));
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
if (argc >= 2 && be_isinstance(vm, 2)) {
|
||||
const char *cname = be_classname(vm, 2);
|
||||
if (!strcmp(cname, "range")) {
|
||||
bint lower, upper;
|
||||
bint size = buf->len;
|
||||
/* get index range */
|
||||
be_getmember(vm, 2, "__lower__");
|
||||
lower = be_toint(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
be_getmember(vm, 2, "__upper__");
|
||||
upper = be_toint(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
/* protection scope */
|
||||
upper = upper < size ? upper : size - 1;
|
||||
lower = lower < 0 ? 0 : lower;
|
||||
/* construction result list instance */
|
||||
bytes_new_object(vm, upper > lower ? upper-lower : 0);
|
||||
be_getmember(vm, -1, ".p");
|
||||
buf_impl * buf2 = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1); /* remove .p and leave bytes instance */
|
||||
for (; lower <= upper; ++lower) {
|
||||
buf_add1(buf2, buf->buf[lower]);
|
||||
}
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
be_raise(vm, "index_error", "bytes index out of range");
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
static int m_size(bvm *vm)
|
||||
{
|
||||
buf_impl * buf = bytes_check_data(vm, 0);
|
||||
be_pushint(vm, buf->len);
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
static int m_resize(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
be_getmember(vm, 1, ".p");
|
||||
buf_impl * buf = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
|
||||
if (argc <= 1 || !be_isint(vm, 2)) {
|
||||
be_raise(vm, "type_error", "size must be of type 'int'");
|
||||
}
|
||||
int new_len = be_toint(vm, 2);
|
||||
if (new_len < 0) {
|
||||
new_len = 0;
|
||||
}
|
||||
|
||||
buf = bytes_resize(vm, buf, new_len);
|
||||
buf_set_len(buf, new_len);
|
||||
be_pop(vm, 1);
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
static int m_clear(bvm *vm)
|
||||
{
|
||||
buf_impl * buf = bytes_check_data(vm, 0);
|
||||
buf->len = 0;
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
static int m_merge(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
buf_impl * buf1 = bytes_check_data(vm, 0); /* no resize yet */
|
||||
if (argc >= 2 && be_isinstance(vm, 2)) {
|
||||
be_getglobal(vm, "bytes"); /* get the bytes class */ /* TODO eventually replace with be_getbuiltin */
|
||||
if (be_isderived(vm, 2)) {
|
||||
be_getmember(vm, 2, ".p");
|
||||
buf_impl * buf2 = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 4); /* remove class, member, and 2 operands */
|
||||
|
||||
/* allocate new object */
|
||||
bytes_new_object(vm, buf1->len + buf2->len);
|
||||
be_getmember(vm, -1, ".p");
|
||||
/* .p is on top of stack, then instance */
|
||||
buf_impl * buf3 = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
buf_add_buf(buf3, buf1);
|
||||
buf_add_buf(buf3, buf2);
|
||||
|
||||
be_return(vm); /* return self */
|
||||
}
|
||||
}
|
||||
be_raise(vm, "type_error", "operand must be bytes");
|
||||
be_return_nil(vm); /* return self */
|
||||
}
|
||||
|
||||
static int m_copy(bvm *vm)
|
||||
{
|
||||
buf_impl * buf1 = bytes_check_data(vm, 0); /* no resize */
|
||||
bytes_new_object(vm, buf1->len);
|
||||
be_getmember(vm, -1, ".p");
|
||||
buf_impl * buf2 = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
buf_add_buf(buf2, buf1);
|
||||
be_return(vm); /* return self */
|
||||
}
|
||||
|
||||
/* accept bytes or int as operand */
|
||||
static int m_connect(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
buf_impl * buf1 = bytes_check_data(vm, 0); /* don't resize yet */
|
||||
if (argc >= 2 && (be_isinstance(vm, 2) || be_isint(vm, 2))) {
|
||||
if (be_isint(vm, 2)) {
|
||||
buf1 = bytes_resize(vm, buf1, buf1->len + 1); /* resize */
|
||||
buf_add1(buf1, be_toint(vm, 2));
|
||||
be_pop(vm, 1); /* remove operand */
|
||||
be_return(vm); /* return self */
|
||||
} else {
|
||||
be_getglobal(vm, "bytes"); /* get the bytes class */ /* TODO eventually replace with be_getbuiltin */
|
||||
if (be_isderived(vm, 2)) {
|
||||
be_getmember(vm, 2, ".p");
|
||||
buf_impl * buf2 = be_tocomptr(vm, -1);
|
||||
buf1 = bytes_resize(vm, buf1, buf1->len + buf2->len); /* resize buf1 for total size */
|
||||
buf_add_buf(buf1, buf2);
|
||||
be_pop(vm, 3); /* remove class, member, and last operand */
|
||||
be_return(vm); /* return self */
|
||||
}
|
||||
}
|
||||
}
|
||||
be_raise(vm, "type_error", "operand must be bytes or int");
|
||||
be_return_nil(vm); /* return self */
|
||||
}
|
||||
|
||||
static int bytes_equal(bvm *vm, bbool iseq)
|
||||
{
|
||||
be_getmember(vm, 1, ".p");
|
||||
buf_impl * buf1 = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
|
||||
be_getmember(vm, 2, ".p");
|
||||
buf_impl * buf2 = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1);
|
||||
|
||||
bbool ret;
|
||||
if (buf_equals(buf1, buf2)) {
|
||||
ret = iseq;
|
||||
} else {
|
||||
ret = !iseq;
|
||||
}
|
||||
be_pushbool(vm, ret);
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
static int m_equal(bvm *vm)
|
||||
{
|
||||
return bytes_equal(vm, btrue);
|
||||
}
|
||||
|
||||
static int m_nequal(bvm *vm)
|
||||
{
|
||||
return bytes_equal(vm, bfalse);
|
||||
}
|
||||
|
||||
/*
|
||||
* External API
|
||||
*/
|
||||
BERRY_API void be_pushbytes(bvm *vm, const void * bytes, size_t len)
|
||||
{
|
||||
bytes_new_object(vm, len);
|
||||
be_getmember(vm, -1, ".p");
|
||||
buf_impl * buf = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 1); /* remove .p1 and leave instance */
|
||||
if (len > buf->size) { len = buf->size; } /* double check if the buffer allocated was smaller */
|
||||
memmove((void*)buf_get_buf(buf), bytes, len);
|
||||
buf->len = len;
|
||||
/* bytes instance is on top of stack */
|
||||
}
|
||||
|
||||
BERRY_API const void *be_tobytes(bvm *vm, int rel_index, size_t *len)
|
||||
{
|
||||
int index = be_absindex(vm, rel_index);
|
||||
if (be_isinstance(vm, index)) {
|
||||
be_getglobal(vm, "bytes"); /* get the bytes class */ /* TODO eventually replace with be_getbuiltin */
|
||||
if (be_isderived(vm, index)) {
|
||||
be_getmember(vm, index, ".p");
|
||||
buf_impl * buf = be_tocomptr(vm, -1);
|
||||
be_pop(vm, 2); /* class and .p */
|
||||
if (len) { *len = buf->len; }
|
||||
return (void*) buf_get_buf(buf);
|
||||
} else {
|
||||
be_pop(vm, 1); /* remove class */
|
||||
}
|
||||
}
|
||||
if (len) { *len = 0; }
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if !BE_USE_PRECOMPILED_OBJECT
|
||||
void be_load_byteslib(bvm *vm)
|
||||
{
|
||||
static const bnfuncinfo members[] = {
|
||||
{ ".p", NULL },
|
||||
{ "init", m_init },
|
||||
{ "tostring", m_tostring },
|
||||
{ "asstring", m_asstring },
|
||||
{ "fromstring", m_fromstring },
|
||||
{ "add", m_add },
|
||||
{ "get", m_get },
|
||||
{ "item", m_item },
|
||||
{ "setitem", m_setitem },
|
||||
{ "size", m_size },
|
||||
{ "resize", m_resize },
|
||||
{ "clear", m_clear },
|
||||
{ "copy", m_copy },
|
||||
{ "+", m_merge },
|
||||
{ "..", m_connect },
|
||||
{ "==", m_equal },
|
||||
{ "!=", m_nequal },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
be_regclass(vm, "bytes", members);
|
||||
}
|
||||
#else
|
||||
/* @const_object_info_begin
|
||||
class be_class_bytes (scope: global, name: bytes) {
|
||||
.p, var
|
||||
init, func(m_init)
|
||||
tostring, func(m_tostring)
|
||||
asstring, func(m_asstring)
|
||||
fromstring, func(m_fromstring)
|
||||
add, func(m_add)
|
||||
get, func(m_get)
|
||||
item, func(m_item)
|
||||
setitem, func(m_setitem)
|
||||
size, func(m_size)
|
||||
resize, func(m_resize)
|
||||
clear, func(m_clear)
|
||||
copy, func(m_copy)
|
||||
+, func(m_merge)
|
||||
.., func(m_connect)
|
||||
==, func(m_equal)
|
||||
!=, func(m_nequal)
|
||||
}
|
||||
@const_object_info_end */
|
||||
#include "../generate/be_fixed_be_class_bytes.h"
|
||||
#endif
|
@ -13,6 +13,9 @@ extern void be_load_maplib(bvm *vm);
|
||||
extern void be_load_rangelib(bvm *vm);
|
||||
extern void be_load_filelib(bvm *vm);
|
||||
|
||||
extern void be_load_tasmota_ntvlib(bvm *vm);
|
||||
extern void be_load_wirelib(bvm *vm);
|
||||
|
||||
void be_loadlibs(bvm *vm)
|
||||
{
|
||||
be_load_baselib(vm);
|
||||
@ -21,5 +24,8 @@ void be_loadlibs(bvm *vm)
|
||||
be_load_maplib(vm);
|
||||
be_load_rangelib(vm);
|
||||
be_load_filelib(vm);
|
||||
be_load_byteslib(vm);
|
||||
#endif
|
||||
be_load_tasmota_ntvlib(vm);
|
||||
be_load_wirelib(vm);
|
||||
}
|
||||
|
@ -207,6 +207,19 @@ static int m_item(bvm *vm)
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
static int m_find(bvm *vm)
|
||||
{
|
||||
be_getmember(vm, 1, ".p");
|
||||
list_check_data(vm, 2);
|
||||
if (be_isint(vm, 2)) {
|
||||
be_pushvalue(vm, 2);
|
||||
if (be_getindex(vm, -2)) {
|
||||
be_return(vm);
|
||||
}
|
||||
}
|
||||
be_return_nil(vm);
|
||||
}
|
||||
|
||||
static int m_setitem(bvm *vm)
|
||||
{
|
||||
be_getmember(vm, 1, ".p");
|
||||
@ -291,13 +304,15 @@ static int m_merge(bvm *vm)
|
||||
{
|
||||
int argc = be_top(vm);
|
||||
if (argc >= 2) {
|
||||
be_newobject(vm, "list"); /* stack contains instance and .p */
|
||||
be_getmember(vm, 1, ".p");
|
||||
be_data_merge(vm, -2);
|
||||
be_getmember(vm, 2, ".p");
|
||||
if (!be_islist(vm, -1)) {
|
||||
be_raise(vm, "type_error", "operand must be a list");
|
||||
}
|
||||
be_data_merge(vm, -2);
|
||||
be_pop(vm, argc + 1);
|
||||
be_data_merge(vm, -3);
|
||||
be_pop(vm, 3);
|
||||
}
|
||||
be_return(vm); /* return self */
|
||||
}
|
||||
@ -423,6 +438,7 @@ void be_load_listlib(bvm *vm)
|
||||
{ "insert", m_insert },
|
||||
{ "remove", m_remove },
|
||||
{ "item", m_item },
|
||||
{ "find", m_find },
|
||||
{ "setitem", m_setitem },
|
||||
{ "size", m_size },
|
||||
{ "resize", m_resize },
|
||||
@ -450,6 +466,7 @@ class be_class_list (scope: global, name: list) {
|
||||
insert, func(m_insert)
|
||||
remove, func(m_remove)
|
||||
item, func(m_item)
|
||||
find, func(m_find)
|
||||
setitem, func(m_setitem)
|
||||
size, func(m_size)
|
||||
resize, func(m_resize)
|
||||
|
@ -1060,4 +1060,4 @@ BERRY_API void be_set_obs_hook(bvm *vm, beobshook hook)
|
||||
#if BE_USE_OBSERVABILITY_HOOK
|
||||
vm->obshook = hook;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -429,6 +429,10 @@ BERRY_API int be_savecode(bvm *vm, const char *name);
|
||||
BERRY_API void be_module_path(bvm *vm);
|
||||
BERRY_API void be_module_path_set(bvm *vm, const char *path);
|
||||
|
||||
/* bytes operations */
|
||||
BERRY_API void be_pushbytes(bvm *vm, const void *buf, size_t len);
|
||||
BERRY_API const void *be_tobytes(bvm *vm, int index, size_t *len);
|
||||
|
||||
/* registry operation */
|
||||
BERRY_API int be_register(bvm *vm, int index);
|
||||
BERRY_API void be_unregister(bvm *vm, int id);
|
||||
|
26
lib/libesp32/Berry-0.1.10/src/port/be_energylib.c
Normal file
26
lib/libesp32/Berry-0.1.10/src/port/be_energylib.c
Normal file
@ -0,0 +1,26 @@
|
||||
/********************************************************************
|
||||
* Tasmota lib
|
||||
*
|
||||
* To use: `import power`
|
||||
*
|
||||
* read power values
|
||||
*******************************************************************/
|
||||
#include "be_object.h"
|
||||
|
||||
extern int b_nrg_read(bvm *vm);
|
||||
|
||||
// #if !BE_USE_PRECOMPILED_OBJECT
|
||||
#if 1 // TODO we will do pre-compiled later
|
||||
be_native_module_attr_table(energy) {
|
||||
be_native_module_function("read", b_nrg_read),
|
||||
};
|
||||
|
||||
be_define_native_module(energy, NULL);
|
||||
#else
|
||||
/* @const_object_info_begin
|
||||
module tasmota (scope: global, depend: 1) {
|
||||
getfreeheap, func(l_getFreeHeap)
|
||||
}
|
||||
@const_object_info_end */
|
||||
#include "../generate/be_fixed_tasmota.h"
|
||||
#endif
|
@ -20,8 +20,9 @@ be_extern_native_module(debug);
|
||||
be_extern_native_module(gc);
|
||||
|
||||
/* Tasmota specific */
|
||||
be_extern_native_module(tasmota_ntv);
|
||||
// be_extern_native_module(tasmota_ntv);
|
||||
be_extern_native_module(wire);
|
||||
be_extern_native_module(energy);
|
||||
|
||||
/* user-defined modules declare start */
|
||||
|
||||
@ -56,8 +57,7 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = {
|
||||
#endif
|
||||
/* user-defined modules register start */
|
||||
|
||||
&be_native_module(tasmota_ntv),
|
||||
&be_native_module(wire),
|
||||
&be_native_module(energy),
|
||||
|
||||
/* user-defined modules register end */
|
||||
NULL /* do not remove */
|
||||
|
@ -13,6 +13,7 @@ extern int l_millis(bvm *vm);
|
||||
extern int l_timereached(bvm *vm);
|
||||
extern int l_yield(bvm *vm);
|
||||
extern int l_delay(bvm *vm);
|
||||
extern int l_scaleuint(bvm *vm);
|
||||
|
||||
extern int l_respCmnd(bvm *vm);
|
||||
extern int l_respCmndStr(bvm *vm);
|
||||
@ -22,33 +23,49 @@ extern int l_respCmndFailed(bvm *vm);
|
||||
extern int l_resolveCmnd(bvm *vm);
|
||||
|
||||
extern int l_getlight(bvm *vm);
|
||||
extern int l_getpower(bvm *vm);
|
||||
extern int l_setlight(bvm *vm);
|
||||
extern int l_setpower(bvm *vm);
|
||||
|
||||
// #if !BE_USE_PRECOMPILED_OBJECT
|
||||
#if 1 // TODO we will do pre-compiled later
|
||||
// Class definition
|
||||
void be_load_tasmota_ntvlib(bvm *vm)
|
||||
{
|
||||
static const bnfuncinfo members[] = {
|
||||
{ "_op", NULL },
|
||||
{ "_opf", NULL },
|
||||
{ "_operators", NULL },
|
||||
{ "_rules", NULL },
|
||||
{ "_timers", NULL },
|
||||
{ "_cmd", NULL },
|
||||
{ "getfreeheap", l_getFreeHeap },
|
||||
{ "publish", l_publish },
|
||||
{ "cmd", l_cmd },
|
||||
{ "getoption", l_getoption },
|
||||
{ "millis", l_millis },
|
||||
{ "timereached", l_timereached },
|
||||
{ "yield", l_yield },
|
||||
{ "delay", l_delay },
|
||||
{ "scaleuint", l_scaleuint },
|
||||
|
||||
be_native_module_attr_table(tasmota_ntv) {
|
||||
be_native_module_function("getfreeheap", l_getFreeHeap),
|
||||
be_native_module_function("publish", l_publish),
|
||||
be_native_module_function("cmd", l_cmd),
|
||||
be_native_module_function("getoption", l_getoption),
|
||||
be_native_module_function("millis", l_millis),
|
||||
be_native_module_function("timereached", l_timereached),
|
||||
be_native_module_function("yield", l_yield),
|
||||
be_native_module_function("delay", l_delay),
|
||||
{ "respcmnd", l_respCmnd },
|
||||
{ "respcmndstr", l_respCmndStr },
|
||||
{ "respcmnd_done", l_respCmndDone },
|
||||
{ "respcmnd_error", l_respCmndError },
|
||||
{ "respcmnd_failed", l_respCmndFailed },
|
||||
{ "resolvecmnd", l_resolveCmnd },
|
||||
|
||||
be_native_module_function("respcmnd", l_respCmnd),
|
||||
be_native_module_function("respcmndstr", l_respCmndStr),
|
||||
be_native_module_function("respcmnd_done", l_respCmndDone),
|
||||
be_native_module_function("respcmnd_error", l_respCmndError),
|
||||
be_native_module_function("respcmnd_failed", l_respCmndFailed),
|
||||
be_native_module_function("resolvecmnd", l_resolveCmnd),
|
||||
{ "getlight", l_getlight },
|
||||
{ "getpower", l_getpower },
|
||||
{ "setlight", l_setlight },
|
||||
{ "setpower", l_setpower },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
be_regclass(vm, "Tasmota_ntv", members);
|
||||
}
|
||||
|
||||
be_native_module_function("getlight", l_getlight),
|
||||
|
||||
be_native_module_str("_operators", "=<>!|"),
|
||||
};
|
||||
|
||||
be_define_native_module(tasmota_ntv, NULL);
|
||||
#else
|
||||
/* @const_object_info_begin
|
||||
module tasmota (scope: global, depend: 1) {
|
||||
|
@ -7,6 +7,8 @@
|
||||
*******************************************************************/
|
||||
#include "be_object.h"
|
||||
|
||||
extern int b_wire_init(bvm *vm);
|
||||
|
||||
extern int b_wire_begintransmission(bvm *vm);
|
||||
extern int b_wire_endtransmission(bvm *vm);
|
||||
extern int b_wire_requestfrom(bvm *vm);
|
||||
@ -21,19 +23,25 @@ extern int b_wire_validread(bvm *vm);
|
||||
|
||||
// #if !BE_USE_PRECOMPILED_OBJECT
|
||||
#if 1 // TODO we will do pre-compiled later
|
||||
be_native_module_attr_table(wire) {
|
||||
be_native_module_function("_begintransmission", b_wire_begintransmission),
|
||||
be_native_module_function("_endtransmission", b_wire_endtransmission),
|
||||
be_native_module_function("_requestfrom", b_wire_requestfrom),
|
||||
be_native_module_function("_available", b_wire_available),
|
||||
be_native_module_function("_write", b_wire_write),
|
||||
be_native_module_function("_read", b_wire_read),
|
||||
be_native_module_function("scan", b_wire_scan),
|
||||
be_native_module_function("write", b_wire_validwrite),
|
||||
be_native_module_function("read", b_wire_validread),
|
||||
};
|
||||
|
||||
be_define_native_module(wire, NULL);
|
||||
void be_load_wirelib(bvm *vm)
|
||||
{
|
||||
static const bnfuncinfo members[] = {
|
||||
{ "_bus", NULL }, // bus number
|
||||
{ "init", b_wire_init },
|
||||
{ "_begintransmission", b_wire_begintransmission },
|
||||
{ "_endtransmission", b_wire_endtransmission },
|
||||
{ "_requestfrom", b_wire_requestfrom },
|
||||
{ "_available", b_wire_available },
|
||||
{ "_write", b_wire_write },
|
||||
{ "_read", b_wire_read },
|
||||
{ "scan", b_wire_scan },
|
||||
{ "write", b_wire_validwrite },
|
||||
{ "read", b_wire_validread },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
be_regclass(vm, "Wire", members);
|
||||
}
|
||||
#else
|
||||
/* @const_object_info_begin
|
||||
module tasmota (scope: global, depend: 1) {
|
||||
|
@ -1,254 +0,0 @@
|
||||
//=====================================================================================================
|
||||
// MahonyAHRS.c
|
||||
//=====================================================================================================
|
||||
//
|
||||
// Madgwick's implementation of Mayhony's AHRS algorithm.
|
||||
// See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms
|
||||
//
|
||||
// Date Author Notes
|
||||
// 29/09/2011 SOH Madgwick Initial release
|
||||
// 02/10/2011 SOH Madgwick Optimised for reduced CPU load
|
||||
//
|
||||
//=====================================================================================================
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// Header files
|
||||
|
||||
#include "MahonyAHRS.h"
|
||||
#include "Arduino.h"
|
||||
#include <math.h>
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// Definitions
|
||||
|
||||
#define sampleFreq 25.0f // sample frequency in Hz
|
||||
#define twoKpDef (2.0f * 1.0f) // 2 * proportional gain
|
||||
#define twoKiDef (2.0f * 0.0f) // 2 * integral gain
|
||||
|
||||
//#define twoKiDef (0.0f * 0.0f)
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// Variable definitions
|
||||
|
||||
volatile float twoKp = twoKpDef; // 2 * proportional gain (Kp)
|
||||
volatile float twoKi = twoKiDef; // 2 * integral gain (Ki)
|
||||
volatile float q0 = 1.0, q1 = 0.0, q2 = 0.0, q3 = 0.0; // quaternion of sensor frame relative to auxiliary frame
|
||||
volatile float integralFBx = 0.0f, integralFBy = 0.0f, integralFBz = 0.0f; // integral error terms scaled by Ki
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
|
||||
//float invSqrt(float x);
|
||||
|
||||
//====================================================================================================
|
||||
// Functions
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// AHRS algorithm update
|
||||
|
||||
void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz) {
|
||||
float recipNorm;
|
||||
float q0q0, q0q1, q0q2, q0q3, q1q1, q1q2, q1q3, q2q2, q2q3, q3q3;
|
||||
float hx, hy, bx, bz;
|
||||
float halfvx, halfvy, halfvz, halfwx, halfwy, halfwz;
|
||||
float halfex, halfey, halfez;
|
||||
float qa, qb, qc;
|
||||
|
||||
// Use IMU algorithm if magnetometer measurement invalid (avoids NaN in magnetometer normalisation)
|
||||
if((mx == 0.0f) && (my == 0.0f) && (mz == 0.0f)) {
|
||||
//MahonyAHRSupdateIMU(gx, gy, gz, ax, ay, az);
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation)
|
||||
if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) {
|
||||
|
||||
// Normalise accelerometer measurement
|
||||
recipNorm = sqrt(ax * ax + ay * ay + az * az);
|
||||
ax *= recipNorm;
|
||||
ay *= recipNorm;
|
||||
az *= recipNorm;
|
||||
|
||||
// Normalise magnetometer measurement
|
||||
recipNorm = sqrt(mx * mx + my * my + mz * mz);
|
||||
mx *= recipNorm;
|
||||
my *= recipNorm;
|
||||
mz *= recipNorm;
|
||||
|
||||
// Auxiliary variables to avoid repeated arithmetic
|
||||
q0q0 = q0 * q0;
|
||||
q0q1 = q0 * q1;
|
||||
q0q2 = q0 * q2;
|
||||
q0q3 = q0 * q3;
|
||||
q1q1 = q1 * q1;
|
||||
q1q2 = q1 * q2;
|
||||
q1q3 = q1 * q3;
|
||||
q2q2 = q2 * q2;
|
||||
q2q3 = q2 * q3;
|
||||
q3q3 = q3 * q3;
|
||||
|
||||
// Reference direction of Earth's magnetic field
|
||||
hx = 2.0f * (mx * (0.5f - q2q2 - q3q3) + my * (q1q2 - q0q3) + mz * (q1q3 + q0q2));
|
||||
hy = 2.0f * (mx * (q1q2 + q0q3) + my * (0.5f - q1q1 - q3q3) + mz * (q2q3 - q0q1));
|
||||
bx = sqrt(hx * hx + hy * hy);
|
||||
bz = 2.0f * (mx * (q1q3 - q0q2) + my * (q2q3 + q0q1) + mz * (0.5f - q1q1 - q2q2));
|
||||
|
||||
// Estimated direction of gravity and magnetic field
|
||||
halfvx = q1q3 - q0q2;
|
||||
halfvy = q0q1 + q2q3;
|
||||
halfvz = q0q0 - 0.5f + q3q3;
|
||||
halfwx = bx * (0.5f - q2q2 - q3q3) + bz * (q1q3 - q0q2);
|
||||
halfwy = bx * (q1q2 - q0q3) + bz * (q0q1 + q2q3);
|
||||
halfwz = bx * (q0q2 + q1q3) + bz * (0.5f - q1q1 - q2q2);
|
||||
|
||||
// Error is sum of cross product between estimated direction and measured direction of field vectors
|
||||
halfex = (ay * halfvz - az * halfvy) + (my * halfwz - mz * halfwy);
|
||||
halfey = (az * halfvx - ax * halfvz) + (mz * halfwx - mx * halfwz);
|
||||
halfez = (ax * halfvy - ay * halfvx) + (mx * halfwy - my * halfwx);
|
||||
|
||||
// Compute and apply integral feedback if enabled
|
||||
if(twoKi > 0.0f) {
|
||||
integralFBx += twoKi * halfex * (1.0f / sampleFreq); // integral error scaled by Ki
|
||||
integralFBy += twoKi * halfey * (1.0f / sampleFreq);
|
||||
integralFBz += twoKi * halfez * (1.0f / sampleFreq);
|
||||
gx += integralFBx; // apply integral feedback
|
||||
gy += integralFBy;
|
||||
gz += integralFBz;
|
||||
}
|
||||
else {
|
||||
integralFBx = 0.0f; // prevent integral windup
|
||||
integralFBy = 0.0f;
|
||||
integralFBz = 0.0f;
|
||||
}
|
||||
|
||||
// Apply proportional feedback
|
||||
gx += twoKp * halfex;
|
||||
gy += twoKp * halfey;
|
||||
gz += twoKp * halfez;
|
||||
}
|
||||
|
||||
// Integrate rate of change of quaternion
|
||||
gx *= (0.5f * (1.0f / sampleFreq)); // pre-multiply common factors
|
||||
gy *= (0.5f * (1.0f / sampleFreq));
|
||||
gz *= (0.5f * (1.0f / sampleFreq));
|
||||
qa = q0;
|
||||
qb = q1;
|
||||
qc = q2;
|
||||
q0 += (-qb * gx - qc * gy - q3 * gz);
|
||||
q1 += (qa * gx + qc * gz - q3 * gy);
|
||||
q2 += (qa * gy - qb * gz + q3 * gx);
|
||||
q3 += (qa * gz + qb * gy - qc * gx);
|
||||
|
||||
// Normalise quaternion
|
||||
recipNorm = sqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
|
||||
q0 *= recipNorm;
|
||||
q1 *= recipNorm;
|
||||
q2 *= recipNorm;
|
||||
q3 *= recipNorm;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// IMU algorithm update
|
||||
|
||||
void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az,float *pitch,float *roll,float *yaw) {
|
||||
float recipNorm;
|
||||
float halfvx, halfvy, halfvz;
|
||||
float halfex, halfey, halfez;
|
||||
float qa, qb, qc;
|
||||
|
||||
|
||||
// Compute feedback only if accelerometer measurement valid (avoids NaN in accelerometer normalisation)
|
||||
if(!((ax == 0.0f) && (ay == 0.0f) && (az == 0.0f))) {
|
||||
|
||||
// Normalise accelerometer measurement
|
||||
recipNorm = invSqrt(ax * ax + ay * ay + az * az);
|
||||
ax *= recipNorm;
|
||||
ay *= recipNorm;
|
||||
az *= recipNorm;
|
||||
|
||||
// Estimated direction of gravity and vector perpendicular to magnetic flux
|
||||
halfvx = q1 * q3 - q0 * q2;
|
||||
halfvy = q0 * q1 + q2 * q3;
|
||||
halfvz = q0 * q0 - 0.5f + q3 * q3;
|
||||
|
||||
|
||||
|
||||
// Error is sum of cross product between estimated and measured direction of gravity
|
||||
halfex = (ay * halfvz - az * halfvy);
|
||||
halfey = (az * halfvx - ax * halfvz);
|
||||
halfez = (ax * halfvy - ay * halfvx);
|
||||
|
||||
// Compute and apply integral feedback if enabled
|
||||
if(twoKi > 0.0f) {
|
||||
integralFBx += twoKi * halfex * (1.0f / sampleFreq); // integral error scaled by Ki
|
||||
integralFBy += twoKi * halfey * (1.0f / sampleFreq);
|
||||
integralFBz += twoKi * halfez * (1.0f / sampleFreq);
|
||||
gx += integralFBx; // apply integral feedback
|
||||
gy += integralFBy;
|
||||
gz += integralFBz;
|
||||
}
|
||||
else {
|
||||
integralFBx = 0.0f; // prevent integral windup
|
||||
integralFBy = 0.0f;
|
||||
integralFBz = 0.0f;
|
||||
}
|
||||
|
||||
// Apply proportional feedback
|
||||
gx += twoKp * halfex;
|
||||
gy += twoKp * halfey;
|
||||
gz += twoKp * halfez;
|
||||
}
|
||||
|
||||
// Integrate rate of change of quaternion
|
||||
gx *= (0.5f * (1.0f / sampleFreq)); // pre-multiply common factors
|
||||
gy *= (0.5f * (1.0f / sampleFreq));
|
||||
gz *= (0.5f * (1.0f / sampleFreq));
|
||||
qa = q0;
|
||||
qb = q1;
|
||||
qc = q2;
|
||||
q0 += (-qb * gx - qc * gy - q3 * gz);
|
||||
q1 += (qa * gx + qc * gz - q3 * gy);
|
||||
q2 += (qa * gy - qb * gz + q3 * gx);
|
||||
q3 += (qa * gz + qb * gy - qc * gx);
|
||||
|
||||
// Normalise quaternion
|
||||
recipNorm = invSqrt(q0 * q0 + q1 * q1 + q2 * q2 + q3 * q3);
|
||||
q0 *= recipNorm;
|
||||
q1 *= recipNorm;
|
||||
q2 *= recipNorm;
|
||||
q3 *= recipNorm;
|
||||
|
||||
|
||||
*pitch = asin(-2 * q1 * q3 + 2 * q0* q2); // pitch
|
||||
*roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1); // roll
|
||||
*yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3); //yaw
|
||||
|
||||
*pitch *= RAD_TO_DEG;
|
||||
*yaw *= RAD_TO_DEG;
|
||||
// Declination of SparkFun Electronics (40°05'26.6"N 105°11'05.9"W) is
|
||||
// 8° 30' E ± 0° 21' (or 8.5°) on 2016-07-19
|
||||
// - http://www.ngdc.noaa.gov/geomag-web/#declination
|
||||
*yaw -= 8.5;
|
||||
*roll *= RAD_TO_DEG;
|
||||
|
||||
///Serial.printf("%f %f %f \r\n", pitch, roll, yaw);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// Fast inverse square-root
|
||||
// See: http://en.wikipedia.org/wiki/Fast_inverse_square_root
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
float invSqrt(float x) {
|
||||
float halfx = 0.5f * x;
|
||||
float y = x;
|
||||
long i = *(long*)&y;
|
||||
i = 0x5f3759df - (i>>1);
|
||||
y = *(float*)&i;
|
||||
y = y * (1.5f - (halfx * y * y));
|
||||
return y;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
//====================================================================================================
|
||||
// END OF CODE
|
||||
//====================================================================================================
|
@ -1,33 +0,0 @@
|
||||
//=====================================================================================================
|
||||
// MahonyAHRS.h
|
||||
//=====================================================================================================
|
||||
//
|
||||
// Madgwick's implementation of Mayhony's AHRS algorithm.
|
||||
// See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms
|
||||
//
|
||||
// Date Author Notes
|
||||
// 29/09/2011 SOH Madgwick Initial release
|
||||
// 02/10/2011 SOH Madgwick Optimised for reduced CPU load
|
||||
//
|
||||
//=====================================================================================================
|
||||
#ifndef MahonyAHRS_h
|
||||
#define MahonyAHRS_h
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Variable declaration
|
||||
|
||||
extern volatile float twoKp; // 2 * proportional gain (Kp)
|
||||
extern volatile float twoKi; // 2 * integral gain (Ki)
|
||||
//volatile float q0, q1, q2, q3; // quaternion of sensor frame relative to auxiliary frame
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
|
||||
void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz);
|
||||
//void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az);
|
||||
void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, float az,float *pitch,float *roll,float *yaw);
|
||||
float invSqrt(float x);
|
||||
#endif
|
||||
//=====================================================================================================
|
||||
// End of file
|
||||
//=====================================================================================================
|
2
lib/libesp32_div/ESP32-HomeKit/src/_esp_hap_config.h
Normal file → Executable file
2
lib/libesp32_div/ESP32-HomeKit/src/_esp_hap_config.h
Normal file → Executable file
@ -14,7 +14,7 @@
|
||||
#define CONFIG_HAP_HTTP_STACK_SIZE 12288
|
||||
#define CONFIG_HAP_HTTP_SERVER_PORT 5556 // 80 for normal webserver
|
||||
#define CONFIG_HAP_HTTP_CONTROL_PORT 32859
|
||||
#define CONFIG_HAP_HTTP_MAX_OPEN_SOCKETS 6
|
||||
#define CONFIG_HAP_HTTP_MAX_OPEN_SOCKETS 5 // 6
|
||||
#define CONFIG_HAP_HTTP_MAX_URI_HANDLERS 16
|
||||
|
||||
#endif /* ESP_HAP_CONFIG_H_ */
|
||||
|
0
lib/libesp32_div/ESP32-HomeKit/src/hap.h
Normal file → Executable file
0
lib/libesp32_div/ESP32-HomeKit/src/hap.h
Normal file → Executable file
21
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_chars.c
Normal file → Executable file
21
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_chars.c
Normal file → Executable file
@ -39,6 +39,21 @@ hap_char_t *hap_char_brightness_create(int brightness)
|
||||
return hc;
|
||||
}
|
||||
|
||||
/* Char: Brightness */
|
||||
hap_char_t *hap_char_wattage_create(float watts)
|
||||
{
|
||||
hap_char_t *hc = hap_char_float_create(HAP_CHAR_UUID_CURRENT_AMBIENT_LIGHT_LEVEL,
|
||||
HAP_CHAR_PERM_PR | HAP_CHAR_PERM_PW | HAP_CHAR_PERM_EV, watts);
|
||||
if (!hc) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hap_char_float_set_constraints(hc, -10000.0, 10000.0, 1);
|
||||
hap_char_add_unit(hc, HAP_CHAR_UNIT_LUX);
|
||||
|
||||
return hc;
|
||||
}
|
||||
|
||||
/* Char: Cooling Threshold Temperature */
|
||||
hap_char_t *hap_char_cooling_threshold_temperature_create(float cooling_threshold_temp)
|
||||
{
|
||||
@ -1284,7 +1299,7 @@ hap_char_t *hap_char_relative_humidity_humidifier_threshold_create(float rel_hum
|
||||
}
|
||||
|
||||
hap_char_float_set_constraints(hc, 0.0, 100.0, 1.0);
|
||||
hap_char_add_unit(hc, HAP_CHAR_UNIT_PERCENTAGE);
|
||||
hap_char_add_unit(hc, HAP_CHAR_UNIT_LUX);
|
||||
|
||||
return hc;
|
||||
}
|
||||
@ -1391,7 +1406,7 @@ hap_char_t *hap_char_status_jammed_create(uint8_t status_jammed)
|
||||
hap_char_t *hap_char_administrator_only_access_create(bool administrator_only_access)
|
||||
{
|
||||
hap_char_t *hc = hap_char_bool_create(HAP_CHAR_UUID_ADMINISTRATOR_ONLY_ACCESS,
|
||||
HAP_CHAR_PERM_PR | HAP_CHAR_PERM_PW | HAP_CHAR_PERM_EV,
|
||||
HAP_CHAR_PERM_PR | HAP_CHAR_PERM_PW | HAP_CHAR_PERM_EV,
|
||||
administrator_only_access);
|
||||
if (!hc) {
|
||||
return NULL;
|
||||
@ -1430,7 +1445,7 @@ hap_char_t *hap_char_lock_last_known_action_create(uint8_t lock_last_known_actio
|
||||
hap_char_t *hap_char_lock_management_auto_security_timeout_create(uint32_t lock_management_auto_security_timeout)
|
||||
{
|
||||
hap_char_t *hc = hap_char_uint32_create(HAP_CHAR_UUID_LOCK_MANAGEMENT_AUTO_SECURITY_TIMEOUT,
|
||||
HAP_CHAR_PERM_PR | HAP_CHAR_PERM_PW | HAP_CHAR_PERM_EV,
|
||||
HAP_CHAR_PERM_PR | HAP_CHAR_PERM_PW | HAP_CHAR_PERM_EV,
|
||||
lock_management_auto_security_timeout);
|
||||
if (!hc) {
|
||||
return NULL;
|
||||
|
3
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_chars.h
Normal file → Executable file
3
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_chars.h
Normal file → Executable file
@ -142,6 +142,7 @@ extern "C" {
|
||||
#define HAP_CHAR_UUID_REMAINING_DURATION "D4"
|
||||
#define HAP_CHAR_UUID_VALVE_TYPE "D5"
|
||||
#define HAP_CHAR_UUID_IS_CONFIGURED "D6"
|
||||
#define HAP_CHAR_UUID_WATTAGE "DC"
|
||||
#define HAP_CHAR_UUID_PRODUCT_DATA "220"
|
||||
|
||||
/** Create Brightness Characteristic
|
||||
@ -1415,6 +1416,8 @@ hap_char_t *hap_char_air_particulate_density_create(float air_particulate_densit
|
||||
*/
|
||||
hap_char_t *hap_char_air_particulate_size_create(uint8_t air_particulate_size);
|
||||
|
||||
hap_char_t *hap_char_wattage_create(float watts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
17
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_servs.c
Normal file → Executable file
17
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_servs.c
Normal file → Executable file
@ -419,6 +419,22 @@ err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hap_serv_t *hap_serv_wattage_create(float curr_watts)
|
||||
{
|
||||
hap_serv_t *hs = hap_serv_create(HAP_SERV_UUID_LIGHT_SENSOR);
|
||||
if (!hs) {
|
||||
return NULL;
|
||||
}
|
||||
if (hap_serv_add_char(hs, hap_char_wattage_create(curr_watts)) != HAP_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
return hs;
|
||||
err:
|
||||
hap_serv_delete(hs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
hap_serv_t *hap_serv_temperature_sensor_create(float curr_temp)
|
||||
{
|
||||
hap_serv_t *hs = hap_serv_create(HAP_SERV_UUID_TEMPERATURE_SENSOR);
|
||||
@ -703,4 +719,3 @@ err:
|
||||
hap_serv_delete(hs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
4
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_servs.h
Normal file → Executable file
4
lib/libesp32_div/ESP32-HomeKit/src/hap_apple_servs.h
Normal file → Executable file
@ -75,6 +75,7 @@ extern "C" {
|
||||
#define HAP_SERV_UUID_VALVE "D0"
|
||||
#define HAP_SERV_UUID_FAUCET "D7"
|
||||
|
||||
|
||||
/** Create Accessory Information Service
|
||||
*
|
||||
* This API will create the Accessory Information Service with the mandatory
|
||||
@ -553,6 +554,9 @@ hap_serv_t *hap_serv_valve_create(uint8_t active, uint8_t in_use, uint8_t valve_
|
||||
*/
|
||||
hap_serv_t *hap_serv_faucet_create(uint8_t active);
|
||||
|
||||
|
||||
hap_serv_t *hap_serv_wattage_create(float curr_watts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
158
lib/libesp32_div/ESP32-HomeKit/src/hap_platform_keystore.c → lib/libesp32_div/ESP32-HomeKit/src/hap_platform_keystore.cpp
Normal file → Executable file
158
lib/libesp32_div/ESP32-HomeKit/src/hap_platform_keystore.c → lib/libesp32_div/ESP32-HomeKit/src/hap_platform_keystore.cpp
Normal file → Executable file
@ -21,25 +21,172 @@
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <nvs_flash.h>
|
||||
#include <string.h>
|
||||
#include <FS.h>
|
||||
|
||||
#define HAP_PLATFORM_DEF_NVS_PARTITION "nvs"
|
||||
#define HAP_PLATFORM_DEF_FACTORY_NVS_PARTITION "factory_nvs"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static const char *TAG = "hap_platform_keystore";
|
||||
|
||||
char * hap_platform_keystore_get_nvs_partition_name()
|
||||
{
|
||||
const char * hap_platform_keystore_get_nvs_partition_name() {
|
||||
return HAP_PLATFORM_DEF_NVS_PARTITION;
|
||||
}
|
||||
|
||||
char * hap_platform_keystore_get_factory_nvs_partition_name()
|
||||
{
|
||||
const char * hap_platform_keystore_get_factory_nvs_partition_name() {
|
||||
return HAP_PLATFORM_DEF_FACTORY_NVS_PARTITION;
|
||||
}
|
||||
|
||||
#define HAP_USE_LITTLEFS
|
||||
|
||||
#ifdef HAP_USE_LITTLEFS
|
||||
|
||||
#include <LITTLEFS.h>
|
||||
|
||||
extern FS *ffsp;
|
||||
|
||||
int hap_platform_keystore_init_partition(const char *part_name, bool read_only) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hap_platform_keystore_get(const char *part_name, const char *name_space, const char *key, uint8_t *val, size_t *val_size) {
|
||||
char path[48];
|
||||
strcpy(path, "/");
|
||||
strcat(path, part_name);
|
||||
|
||||
File fp = ffsp->open(path, "r");
|
||||
if (!fp) {
|
||||
ffsp->mkdir(path);
|
||||
return -1;
|
||||
}
|
||||
fp.close();
|
||||
|
||||
strcat(path, "/");
|
||||
strcat(path, name_space);
|
||||
fp = ffsp->open(path, "r");
|
||||
if (!fp) {
|
||||
ffsp->mkdir(path);
|
||||
return -1;
|
||||
}
|
||||
fp.close();
|
||||
|
||||
strcat(path, "/");
|
||||
strcat(path, key);
|
||||
fp = ffsp->open(path, "r");
|
||||
if (fp) {
|
||||
fp.read(val, *val_size);
|
||||
fp.close();
|
||||
} else {
|
||||
*val_size = 0;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hap_platform_keystore_set(const char *part_name, const char *name_space, const char *key, const uint8_t *val, const size_t val_len) {
|
||||
char path[48];
|
||||
strcpy(path, "/");
|
||||
strcat(path, part_name);
|
||||
|
||||
File fp = ffsp->open(path, "r");
|
||||
if (!fp) {
|
||||
ffsp->mkdir(path);
|
||||
}
|
||||
fp.close();
|
||||
|
||||
strcat(path, "/");
|
||||
strcat(path, name_space);
|
||||
fp = ffsp->open(path, "r");
|
||||
if (!fp) {
|
||||
ffsp->mkdir(path);
|
||||
}
|
||||
fp.close();
|
||||
|
||||
strcat(path, "/");
|
||||
strcat(path, key);
|
||||
fp = ffsp->open(path, "w");
|
||||
if (fp) {
|
||||
fp.write(val, val_len);
|
||||
fp.close();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hap_platform_keystore_delete(const char *part_name, const char *name_space, const char *key) {
|
||||
char path[48];
|
||||
strcpy(path, "/");
|
||||
strcat(path, part_name);
|
||||
strcat(path, "/");
|
||||
strcat(path, name_space);
|
||||
strcat(path, "/");
|
||||
strcat(path, key);
|
||||
ffsp->remove(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// should
|
||||
int hap_platform_keystore_delete_namespace(const char *part_name, const char *name_space) {
|
||||
char path[48];
|
||||
strcpy(path, "/");
|
||||
strcat(path, part_name);
|
||||
strcat(path, "/");
|
||||
strcat(path, name_space);
|
||||
File fp = ffsp->open(path, "r");
|
||||
if (fp.isDirectory()) {
|
||||
while (true) {
|
||||
File entry = fp.openNextFile();
|
||||
if (!entry) break;
|
||||
char p[48];
|
||||
strcpy(p,entry.name());
|
||||
entry.close();
|
||||
ffsp->remove(p);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// last resort only
|
||||
int hap_platfrom_keystore_erase_partition(const char *part_name) {
|
||||
char path[48];
|
||||
strcpy(path, "/");
|
||||
strcat(path, part_name);
|
||||
File fp = ffsp->open(path, "r");
|
||||
if (fp.isDirectory()) {
|
||||
while (true) {
|
||||
File entry = fp.openNextFile();
|
||||
if (!entry) break;
|
||||
const char *ep = entry.name();
|
||||
if (*ep=='/') ep++;
|
||||
char *lcp = strrchr(ep,'/');
|
||||
if (lcp) {
|
||||
ep = lcp + 1;
|
||||
}
|
||||
char p[48];
|
||||
strcpy(p,entry.name());
|
||||
if (entry.isDirectory()) {
|
||||
hap_platform_keystore_delete_namespace(part_name, ep);
|
||||
entry.close();
|
||||
ffsp->rmdir(p);
|
||||
} else {
|
||||
entry.close();
|
||||
ffsp->remove(p);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifdef CONFIG_NVS_ENCRYPTION
|
||||
int hap_platform_keystore_init_partition(const char *part_name, bool read_only)
|
||||
{
|
||||
@ -185,3 +332,6 @@ int hap_platfrom_keystore_erase_partition(const char *part_name)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif // USE_LITTLEFS
|
||||
|
||||
}
|
@ -80,7 +80,7 @@ build_flags = ${core.build_flags}
|
||||
|
||||
board_build.f_cpu = 80000000L
|
||||
board_build.f_flash = 40000000L
|
||||
monitor_speed = 74880
|
||||
monitor_speed = 115200
|
||||
monitor_port = COM5
|
||||
upload_speed = 115200
|
||||
; *** Upload Serial reset method for Wemos and NodeMCU
|
||||
|
@ -161,7 +161,7 @@ lib_extra_dirs =
|
||||
|
||||
; *** EXPERIMENTAL Tasmota version for ESP32solo1 (used in some Xiaomi devices)
|
||||
[env:tasmota32solo1]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/raw/framework-arduinoespressif32/framework-arduinoespressif32-release_v3.3-solo1-bd65eb8d1.tar.gz
|
||||
platformio/tool-mklittlefs @ ~1.203.200522
|
||||
platformio/tool-esptoolpy @ ~1.30000.0
|
||||
@ -170,7 +170,7 @@ build_flags = ${common32.build_flags}
|
||||
|
||||
; *** EXPERIMENTAL Tasmota version for ESP32-S2
|
||||
[env:tasmota32s2]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
board = esp32s2
|
||||
board_build.flash_mode = qio
|
||||
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/arduino-esp32/releases/download/s2-1.0.5-rc6/esp32-s2-1.0.5-rc6.zip
|
||||
@ -191,7 +191,7 @@ build_flags = ${esp82xx_defaults.build_flags}
|
||||
; -Wstack-usage=300
|
||||
|
||||
[env:tasmota32-debug]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
build_type = debug
|
||||
build_unflags = ${esp32_defaults.build_unflags}
|
||||
build_flags = ${esp32_defaults.build_flags}
|
||||
|
@ -11,8 +11,6 @@ default_envs = ${build_envs.default_envs}
|
||||
; tasmota32-webcam
|
||||
; tasmota32-odroidgo
|
||||
; tasmota32-core2
|
||||
; tasmota32-knx
|
||||
; tasmota32-sensors
|
||||
; tasmota32-display
|
||||
; tasmota32-ir
|
||||
; tasmota32-ircustom
|
||||
|
@ -1,4 +1,4 @@
|
||||
[env:tasmota32]
|
||||
[env:tasmota32_base]
|
||||
framework = ${common.framework}
|
||||
platform = ${common32.platform}
|
||||
platform_packages = ${common32.platform_packages}
|
||||
@ -30,8 +30,12 @@ lib_ignore =
|
||||
; Disable next if you want to use ArduinoOTA in Tasmota32 (default disabled)
|
||||
ArduinoOTA
|
||||
|
||||
[env:tasmota32]
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-webcam]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
board = esp32cam
|
||||
board_build.f_cpu = 240000000L
|
||||
board_build.flash_mode = qio
|
||||
@ -40,7 +44,7 @@ build_flags = ${common32.build_flags} -DBOARD_HAS_PSRAM -mfix-esp32-
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic
|
||||
|
||||
[env:tasmota32-odroidgo]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
board = odroid_esp32
|
||||
board_build.f_cpu = 240000000L
|
||||
board_build.flash_mode = qio
|
||||
@ -51,7 +55,7 @@ build_flags = ${common32.build_flags} -DBOARD_HAS_PSRAM -mfix-esp32-
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic, lib/lib_i2c, lib/lib_rf, lib/lib_div, lib/lib_ssl, lib/lib_display
|
||||
|
||||
[env:tasmota32-core2]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
board = odroid_esp32
|
||||
board_build.f_cpu = 240000000L
|
||||
board_build.flash_mode = qio
|
||||
@ -62,130 +66,120 @@ build_flags = ${common32.build_flags} -DBOARD_HAS_PSRAM -mfix-esp32-
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic, lib/lib_i2c, lib/lib_rf, lib/lib_div, lib/lib_ssl, lib/lib_display, lib/lib_audio
|
||||
|
||||
[env:tasmota32-bluetooth]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DFIRMWARE_BLUETOOTH
|
||||
lib_extra_dirs = lib/libesp32, lib/libesp32_div, lib/lib_basic, lib/lib_i2c, lib/lib_ssl
|
||||
|
||||
[env:tasmota32-knx]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DFIRMWARE_KNX_NO_EMULATION
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic, lib/lib_div
|
||||
|
||||
[env:tasmota32-sensors]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DFIRMWARE_SENSORS
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic, lib/lib_i2c, lib/lib_rf, lib/lib_div, lib/lib_ssl
|
||||
|
||||
[env:tasmota32-display]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DFIRMWARE_DISPLAYS
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic, lib/lib_display
|
||||
|
||||
[env:tasmota32-ir]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} ${irremoteesp_full.build_flags} -DFIRMWARE_IR
|
||||
lib_extra_dirs = lib/libesp32, lib/lib_basic
|
||||
|
||||
[env:tasmota32-ircustom]
|
||||
extends = env:tasmota32
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} ${irremoteesp_full.build_flags} -DFIRMWARE_IR_CUSTOM
|
||||
|
||||
[env:tasmota32-AF]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=af_AF
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=af_AF -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-BG]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=bg_BG
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=bg_BG -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-BR]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=pt_BR
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=pt_BR -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-CN]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=zh_CN
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=zh_CN -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-CZ]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=cs_CZ
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=cs_CZ -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-DE]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=de_DE
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=de_DE -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-ES]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=es_ES
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=es_ES -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-FR]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=fr_FR
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=fr_FR -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-FY]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=fy_NL
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=fy_NL -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-GR]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=el_GR
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=el_GR -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-HE]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=he_HE
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=he_HE -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-HU]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=hu_HU
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=hu_HU -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-IT]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=it_IT
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=it_IT -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-KO]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=ko_KO
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=ko_KO -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-NL]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=nl_NL
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=nl_NL -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-PL]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=pl_PL
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=pl_PL -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-PT]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=pt_PT
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=pt_PT -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-RO]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=ro_RO
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=ro_RO -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-RU]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=ru_RU
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=ru_RU -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-SE]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=sv_SE
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=sv_SE -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-SK]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=sk_SK
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=sk_SK -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-TR]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=tr_TR
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=tr_TR -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-TW]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=zh_TW
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=zh_TW -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-UK]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=uk_UA
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=uk_UA -DFIRMWARE_TASMOTA32
|
||||
|
||||
[env:tasmota32-VN]
|
||||
extends = env:tasmota32
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=vi_VN
|
||||
extends = env:tasmota32_base
|
||||
build_flags = ${common32.build_flags} -DMY_LANGUAGE=vi_VN -DFIRMWARE_TASMOTA32
|
||||
|
1
tasmota/berry/autoexec.be
Normal file
1
tasmota/berry/autoexec.be
Normal file
@ -0,0 +1 @@
|
||||
load('denky.be')
|
21
tasmota/berry/denky.be
Normal file
21
tasmota/berry/denky.be
Normal file
@ -0,0 +1,21 @@
|
||||
#-
|
||||
# example of using Berry script to change the led color
|
||||
# accordingly to power consumption
|
||||
# using Denky (French Teleinfo reader)
|
||||
-#
|
||||
|
||||
#- define the global symbol for reference -#
|
||||
runcolor = nil
|
||||
|
||||
def runcolor()
|
||||
var pwr = energy.read().find('activepower',0)
|
||||
print(pwr)
|
||||
var red = tasmota.scaleuint(int(pwr), 0, 2500, 0, 255)
|
||||
var green = 255 - red
|
||||
var channels = [red, green, 0]
|
||||
tasmota.setlight({"channels":channels, "bri":64, "power":true})
|
||||
tasmota.settimer(2000, runcolor)
|
||||
end
|
||||
|
||||
#- run animation -#
|
||||
runcolor()
|
@ -24,6 +24,9 @@
|
||||
/* HomeKit Smart Outlet Example
|
||||
*/
|
||||
|
||||
//#define USE_HOMEKIT
|
||||
|
||||
|
||||
#ifdef USE_HOMEKIT
|
||||
#ifdef ESP32
|
||||
|
||||
@ -49,17 +52,18 @@
|
||||
static const char *TAG = "HAP outlet";
|
||||
char *hk_desc;
|
||||
char hk_code[12];
|
||||
uint8_t hk_services;
|
||||
|
||||
extern void Ext_Replace_Cmd_Vars(char *srcbuf, uint32_t srcsize, char *dstbuf, uint32_t dstsize);
|
||||
extern uint32_t Ext_UpdVar(char *vname, float *fvar, uint32_t mode);
|
||||
|
||||
#define MAX_HAP_DEFS 16
|
||||
struct HAP_DESC {
|
||||
char hap_name[16];
|
||||
char var_name[16];
|
||||
char var2_name[16];
|
||||
char var3_name[16];
|
||||
char var4_name[16];
|
||||
char hap_name[24];
|
||||
char var_name[12];
|
||||
char var2_name[12];
|
||||
char var3_name[12];
|
||||
char var4_name[12];
|
||||
uint8_t hap_cid;
|
||||
uint8_t type;
|
||||
hap_acc_t *accessory;
|
||||
@ -144,45 +148,66 @@ static int accessory_identify(hap_acc_t *ha)
|
||||
return HAP_SUCCESS;
|
||||
}
|
||||
|
||||
const struct HAP_CHAR_TABLE {
|
||||
char stype[4];
|
||||
char ntype;
|
||||
int8_t index;
|
||||
} hap_rtab[] = {
|
||||
{HAP_CHAR_UUID_CURRENT_TEMPERATURE,'f',0},
|
||||
{HAP_CHAR_UUID_CURRENT_RELATIVE_HUMIDITY,'f',0},
|
||||
{HAP_CHAR_UUID_CURRENT_AMBIENT_LIGHT_LEVEL,'f',0},
|
||||
{HAP_CHAR_UUID_BATTERY_LEVEL,'u',0},
|
||||
{HAP_CHAR_UUID_STATUS_LOW_BATTERY,'b',1},
|
||||
{HAP_CHAR_UUID_CHARGING_STATE,'b',2},
|
||||
{HAP_CHAR_UUID_ON,'b',0},
|
||||
{HAP_CHAR_UUID_HUE,'f',1},
|
||||
{HAP_CHAR_UUID_SATURATION,'f',2},
|
||||
{HAP_CHAR_UUID_BRIGHTNESS,'u',3},
|
||||
{HAP_CHAR_UUID_COLOR_TEMPERATURE,'u',0},
|
||||
{HAP_CHAR_UUID_CONTACT_SENSOR_STATE,'u',0},
|
||||
{HAP_CHAR_UUID_WATTAGE,'f',0}
|
||||
};
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/* A dummy callback for handling a write on the "On" characteristic of Outlet.
|
||||
* In an actual accessory, this should control the hardware
|
||||
*/
|
||||
static int sensor_write(hap_write_data_t write_data[], int count, void *serv_priv, void *write_priv, uint32_t index) {
|
||||
int i, ret = HAP_SUCCESS;
|
||||
float fvar;
|
||||
hap_write_data_t *write;
|
||||
for (i = 0; i < count; i++) {
|
||||
write = &write_data[i];
|
||||
bool found = false;
|
||||
const char *hcp = hap_char_get_type_uuid(write->hc);
|
||||
if (!strcmp(hcp, HAP_CHAR_UUID_ON)) {
|
||||
//ESP_LOGI(TAG, "Received Write. Outlet %s", write->val.b ? "On" : "Off");
|
||||
ESP_LOG_LEVEL(ESP_LOG_INFO, TAG, "Received Write. Outlet %s", write->val.b ? "On" : "Off");
|
||||
hap_char_update_val(write->hc, &(write->val));
|
||||
float fvar = write->val.b;
|
||||
Ext_UpdVar(hap_devs[index].var_name, &fvar, 1);
|
||||
*(write->status) = HAP_STATUS_SUCCESS;
|
||||
} else if (!strcmp(hcp, HAP_CHAR_UUID_HUE)) {
|
||||
hap_char_update_val(write->hc, &(write->val));
|
||||
float fvar = write->val.f;
|
||||
Ext_UpdVar(hap_devs[index].var2_name, &fvar, 1);
|
||||
*(write->status) = HAP_STATUS_SUCCESS;
|
||||
} else if (!strcmp(hcp, HAP_CHAR_UUID_SATURATION)) {
|
||||
hap_char_update_val(write->hc, &(write->val));
|
||||
float fvar = write->val.f;
|
||||
Ext_UpdVar(hap_devs[index].var3_name, &fvar, 1);
|
||||
*(write->status) = HAP_STATUS_SUCCESS;
|
||||
} else if (!strcmp(hcp, HAP_CHAR_UUID_BRIGHTNESS)) {
|
||||
hap_char_update_val(write->hc, &(write->val));
|
||||
float fvar = write->val.u;
|
||||
Ext_UpdVar(hap_devs[index].var4_name, &fvar, 1);
|
||||
*(write->status) = HAP_STATUS_SUCCESS;
|
||||
} else {
|
||||
for (uint32_t cnt = 0; cnt < ARRAY_SIZE(hap_rtab); cnt++ ) {
|
||||
if (!strcmp(hcp, hap_rtab[cnt].stype)) {
|
||||
hap_char_update_val(write->hc, &(write->val));
|
||||
switch (hap_rtab[cnt].ntype) {
|
||||
case 'f': fvar = write->val.f; break;
|
||||
case 'u': fvar = write->val.u; break;
|
||||
case 'b': fvar = write->val.b; break;
|
||||
}
|
||||
switch (hap_rtab[cnt].index) {
|
||||
case 0: Ext_UpdVar(hap_devs[index].var_name, &fvar, 1);break;
|
||||
case 1: Ext_UpdVar(hap_devs[index].var2_name, &fvar, 1);break;
|
||||
case 2: Ext_UpdVar(hap_devs[index].var3_name, &fvar, 1);break;
|
||||
case 3: Ext_UpdVar(hap_devs[index].var4_name, &fvar, 1);break;
|
||||
}
|
||||
*(write->status) = HAP_STATUS_SUCCESS;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
*(write->status) = HAP_STATUS_RES_ABSENT;
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// common read routine
|
||||
static int sensor_read(hap_char_t *hc, hap_status_t *status_code, void *serv_priv, void *read_priv, uint32_t index) {
|
||||
hap_val_t new_val;
|
||||
@ -194,43 +219,125 @@ static int sensor_read(hap_char_t *hc, hap_status_t *status_code, void *serv_pri
|
||||
|
||||
const char *hcp = hap_char_get_type_uuid(hc);
|
||||
|
||||
if (!strcmp(hcp, HAP_CHAR_UUID_CURRENT_TEMPERATURE)
|
||||
|| !strcmp(hcp, HAP_CHAR_UUID_CURRENT_RELATIVE_HUMIDITY)
|
||||
|| !strcmp(hcp, HAP_CHAR_UUID_CURRENT_AMBIENT_LIGHT_LEVEL)
|
||||
) {
|
||||
printf("read values %s\n", hcp );
|
||||
|
||||
Ext_UpdVar(hap_devs[index].var_name, &fvar, 0);
|
||||
new_val.f = fvar;
|
||||
for (uint32_t cnt = 0; cnt < ARRAY_SIZE(hap_rtab); cnt++ ) {
|
||||
if (!strcmp(hcp, hap_rtab[cnt].stype)) {
|
||||
switch (hap_rtab[cnt].index) {
|
||||
case 0: Ext_UpdVar(hap_devs[index].var_name, &fvar, 0);break;
|
||||
case 1: Ext_UpdVar(hap_devs[index].var2_name, &fvar, 0);break;
|
||||
case 2: Ext_UpdVar(hap_devs[index].var3_name, &fvar, 0);break;
|
||||
case 3: Ext_UpdVar(hap_devs[index].var4_name, &fvar, 0);break;
|
||||
}
|
||||
switch (hap_rtab[cnt].ntype) {
|
||||
case 'f': new_val.f = fvar; break;
|
||||
case 'u': new_val.u = fvar; break;
|
||||
case 'b': new_val.b = fvar; break;
|
||||
}
|
||||
hap_char_update_val(hc, &new_val);
|
||||
*status_code = HAP_STATUS_SUCCESS;
|
||||
}
|
||||
if (!strcmp(hcp, HAP_CHAR_UUID_ON)) {
|
||||
Ext_UpdVar(hap_devs[index].var_name, &fvar, 0);
|
||||
new_val.b = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
*status_code = HAP_STATUS_SUCCESS;
|
||||
}
|
||||
if (!strcmp(hcp, HAP_CHAR_UUID_HUE)) {
|
||||
Ext_UpdVar(hap_devs[index].var2_name, &fvar, 0);
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
*status_code = HAP_STATUS_SUCCESS;
|
||||
}
|
||||
if (!strcmp(hcp, HAP_CHAR_UUID_SATURATION)) {
|
||||
Ext_UpdVar(hap_devs[index].var3_name, &fvar, 0);
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
*status_code = HAP_STATUS_SUCCESS;
|
||||
}
|
||||
if (!strcmp(hcp, HAP_CHAR_UUID_BRIGHTNESS)) {
|
||||
Ext_UpdVar(hap_devs[index].var4_name, &fvar, 0);
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
*status_code = HAP_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return HAP_SUCCESS;
|
||||
}
|
||||
|
||||
// update values every 500 ms
|
||||
void hap_update_from_vars(void) {
|
||||
float fvar;
|
||||
hap_char_t *hc;
|
||||
hap_val_t new_val;
|
||||
for (uint32_t cnt = 0; cnt < hk_services; cnt++) {
|
||||
switch (hap_devs[cnt].hap_cid) {
|
||||
case HAP_CID_SENSOR:
|
||||
switch (hap_devs[cnt].type) {
|
||||
case 0:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_CURRENT_TEMPERATURE);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_CURRENT_RELATIVE_HUMIDITY);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_CURRENT_AMBIENT_LIGHT_LEVEL);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_BATTERY_LEVEL);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_STATUS_LOW_BATTERY);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var2_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_STATUS_LOW_BATTERY);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var3_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_CURRENT_AMBIENT_LIGHT_LEVEL);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_CONTACT_SENSOR_STATE);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case HAP_CID_OUTLET:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_ON);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.b = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
case HAP_CID_LIGHTING:
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_ON);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var_name, &fvar, 0)) {
|
||||
new_val.b = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_HUE);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var2_name, &fvar, 0)) {
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_SATURATION);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var3_name, &fvar, 0)) {
|
||||
new_val.f = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_BRIGHTNESS);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var4_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define HAP_READ hap_char_t *hc, hap_status_t *status_code, void *serv_priv, void *read_priv) { return sensor_read(hc, status_code, serv_priv, read_priv
|
||||
|
||||
static int sensor_read1(HAP_READ, 0);}
|
||||
@ -324,6 +431,7 @@ uint32_t cnt;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
float tsim = 20;
|
||||
|
||||
uint32_t str2c(char **sp, char *vp, uint32_t len) {
|
||||
char *lp = *sp;
|
||||
@ -352,6 +460,8 @@ uint32_t str2c(char **sp, char *vp, uint32_t len) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern char *GetFName();
|
||||
|
||||
/*The main thread for handling the Smart Outlet Accessory */
|
||||
static void smart_outlet_thread_entry(void *p) {
|
||||
/* Initialize the HAP core */
|
||||
@ -360,7 +470,8 @@ static void smart_outlet_thread_entry(void *p) {
|
||||
hap_acc_t *accessory;
|
||||
|
||||
hap_acc_cfg_t cfg = {
|
||||
.name = "Tasmota-Bridge",
|
||||
//.name = "Tasmota-Bridge",
|
||||
.name = GetFName(),
|
||||
.manufacturer = "Tasmota",
|
||||
.model = "Bridge",
|
||||
.serial_num = "001122334455",
|
||||
@ -437,10 +548,10 @@ static void smart_outlet_thread_entry(void *p) {
|
||||
/* Create accessory object */
|
||||
hap_devs[index].accessory = hap_acc_create(&hap_cfg);
|
||||
/* Add a dummy Product Data */
|
||||
uint8_t product_data[] = {'E','S','P','3','2','H','A','P'};
|
||||
hap_acc_add_product_data(hap_devs[index].accessory, product_data, sizeof(product_data));
|
||||
|
||||
int ret = hap_serv_add_char(hap_devs[index].service, hap_char_name_create(hap_devs[index].hap_name));
|
||||
int ret;
|
||||
|
||||
switch (hap_cfg.cid) {
|
||||
case HAP_CID_LIGHTING:
|
||||
{ float fvar = 0;
|
||||
@ -467,18 +578,29 @@ static void smart_outlet_thread_entry(void *p) {
|
||||
case 0: hap_devs[index].service = hap_serv_temperature_sensor_create(fvar); break;
|
||||
case 1: hap_devs[index].service = hap_serv_humidity_sensor_create(fvar); break;
|
||||
case 2: hap_devs[index].service = hap_serv_light_sensor_create(fvar); break;
|
||||
case 3:
|
||||
{ float fvar1 = 0, fvar2 = 0;
|
||||
Ext_UpdVar(hap_devs[index].var2_name, &fvar1, 0);
|
||||
Ext_UpdVar(hap_devs[index].var3_name, &fvar2, 0);
|
||||
hap_devs[index].service = hap_serv_battery_service_create(fvar, fvar1, fvar2);
|
||||
}
|
||||
break;
|
||||
case 4: hap_devs[index].service = hap_serv_wattage_create(fvar); break;
|
||||
case 5: hap_devs[index].service = hap_serv_contact_sensor_create(fvar); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
hap_devs[index].service = hap_serv_outlet_create(true, true);
|
||||
}
|
||||
|
||||
hap_serv_add_char(hap_devs[index].service, hap_char_name_create(hap_devs[index].hap_name));
|
||||
hap_set_read(hap_devs[index].service, index);
|
||||
hap_set_write(hap_devs[index].service, index);
|
||||
|
||||
/* Get pointer to the outlet in use characteristic which we need to monitor for state changes */
|
||||
hap_char_t *outlet_in_use = hap_serv_get_char_by_uuid(hap_devs[index].service, HAP_CHAR_UUID_OUTLET_IN_USE);
|
||||
outlet_in_use = hap_serv_get_char_by_uuid(hap_devs[index].service, HAP_CHAR_UUID_OUTLET_IN_USE);
|
||||
|
||||
/* Add the Outlet Service to the Accessory Object */
|
||||
hap_acc_add_serv(hap_devs[index].accessory, hap_devs[index].service);
|
||||
@ -497,7 +619,7 @@ nextline:
|
||||
lp++;
|
||||
}
|
||||
}
|
||||
|
||||
hk_services = index;
|
||||
|
||||
/* Initialize the appliance specific hardware. This enables out-in-use detection */
|
||||
smart_outlet_hardware_init(OUTLET_IN_USE_GPIO);
|
||||
@ -530,15 +652,10 @@ nextline:
|
||||
/* Enable Hardware MFi authentication (applicable only for MFi variant of SDK) */
|
||||
hap_enable_mfi_auth(HAP_MFI_AUTH_HW);
|
||||
|
||||
/* Initialize Wi-Fi */
|
||||
//app_wifi_init();
|
||||
|
||||
/* After all the initializations are done, start the HAP core */
|
||||
hap_start();
|
||||
/* Start Wi-Fi */
|
||||
//app_wifi_start(portMAX_DELAY);
|
||||
|
||||
uint32_t io_num = OUTLET_IN_USE_GPIO;
|
||||
int32_t io_num = OUTLET_IN_USE_GPIO;
|
||||
if (io_num >= 0) {
|
||||
hap_val_t appliance_value = {
|
||||
.b = true,
|
||||
@ -561,25 +678,35 @@ nextline:
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (1) {
|
||||
}
|
||||
// vTaskDelete(NULL);
|
||||
while (1) {
|
||||
delay(500);
|
||||
// hap_update_from_vars();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define HK_PASSCODE "111-11-111"
|
||||
int hap_loop_stop(void);
|
||||
extern void Ext_toLog(char *str);
|
||||
|
||||
#define HK_MAXSIZE 1024
|
||||
|
||||
void homekit_main(char *desc) {
|
||||
void homekit_main(char *desc, uint32_t flag ) {
|
||||
if (desc) {
|
||||
char *cp = desc;
|
||||
cp += 2;
|
||||
while (*cp == ' ') cp++;
|
||||
// "111-11-111"
|
||||
uint32_t cnt;
|
||||
for (cnt = 0; cnt < 10; cnt++) {
|
||||
hk_code[cnt] = *cp++;
|
||||
|
||||
if (*cp == '*') {
|
||||
strlcpy(hk_code, HK_PASSCODE, 10);
|
||||
cp++;
|
||||
} else {
|
||||
uint32_t cnt;
|
||||
for (cnt = 0; cnt < 10; cnt++) {
|
||||
hk_code[cnt] = *cp++;
|
||||
}
|
||||
hk_code[cnt] = 0;
|
||||
}
|
||||
hk_code[cnt] = 0;
|
||||
if (*cp != '\n') {
|
||||
printf("init error\n");
|
||||
return;
|
||||
@ -587,7 +714,16 @@ void homekit_main(char *desc) {
|
||||
cp++;
|
||||
hk_desc = cp;
|
||||
} else {
|
||||
hap_platfrom_keystore_erase_partition("nvs");
|
||||
if (flag == 99) {
|
||||
hap_loop_stop();
|
||||
hap_reset_to_factory();
|
||||
} else if (flag == 98) {
|
||||
hap_loop_stop();
|
||||
// is just the folder in wrapper
|
||||
hap_platfrom_keystore_erase_partition(hap_platform_keystore_get_nvs_partition_name());
|
||||
} else {
|
||||
hap_loop_stop();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -595,7 +731,8 @@ void homekit_main(char *desc) {
|
||||
|
||||
/* Create the application thread */
|
||||
xTaskCreate(smart_outlet_thread_entry, SMART_OUTLET_TASK_NAME, SMART_OUTLET_TASK_STACKSIZE, NULL, SMART_OUTLET_TASK_PRIORITY, NULL);
|
||||
|
||||
}
|
||||
|
||||
#endif // ESP32
|
||||
#endif // USE_HOMEKIT
|
||||
#endif // USE_HOMEKIT
|
||||
|
@ -366,6 +366,8 @@
|
||||
#define D_CMND_MQTTCLIENT "MqttClient"
|
||||
#define D_CMND_MQTTUSER "MqttUser"
|
||||
#define D_CMND_MQTTPASSWORD "MqttPassword"
|
||||
#define D_CMND_MQTTKEEPALIVE "MqttKeepAlive"
|
||||
#define D_CMND_MQTTTIMEOUT "MqttTimeout"
|
||||
#define D_CMND_TLSKEY "TLSKey"
|
||||
#define D_CMND_FULLTOPIC "FullTopic"
|
||||
#define D_CMND_PREFIX "Prefix"
|
||||
@ -782,6 +784,7 @@ const char JSON_SNS_RANGE[] PROGMEM = ",\"%s\":{\"" D_JSON_RANGE "\":%d}";
|
||||
const char JSON_SNS_GNGPM[] PROGMEM = ",\"%s\":{\"" D_JSON_TOTAL_USAGE "\":%s,\"" D_JSON_FLOWRATE "\":%s}";
|
||||
|
||||
const char S_LOG_I2C_FOUND_AT[] PROGMEM = D_LOG_I2C "%s " D_FOUND_AT " 0x%x";
|
||||
const char S_LOG_I2C_FOUND_AT_PORT[] PROGMEM = D_LOG_I2C "%s " D_FOUND_AT " 0x%x (" D_PORT " %d)";
|
||||
|
||||
const char S_RSLT_POWER[] PROGMEM = D_RSLT_POWER;
|
||||
const char S_RSLT_RESULT[] PROGMEM = D_RSLT_RESULT;
|
||||
|
@ -28,7 +28,7 @@
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
*
|
||||
* Updated until v9.2.0.4
|
||||
* Updated until v9.3.1.1
|
||||
\*********************************************************************/
|
||||
|
||||
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
|
||||
@ -797,7 +797,10 @@
|
||||
#define D_SENSOR_WIEGAND_D1 "Wiegand D1"
|
||||
#define D_SENSOR_NEOPOOL_TX "NeoPool Tx"
|
||||
#define D_SENSOR_NEOPOOL_RX "NeoPool Rx"
|
||||
|
||||
#define D_SENSOR_VL53L0X_XSHUT "VL53L0X XSHUT"
|
||||
#define D_NEW_ADDRESS "Setting address to"
|
||||
#define D_OUT_OF_RANGE "Out of Range"
|
||||
#define D_SENSOR_DETECTED "detected"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
@ -28,7 +28,7 @@
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
*
|
||||
* Updated until v8.2.0.6
|
||||
* Updated until v9.3.1.1
|
||||
\*********************************************************************/
|
||||
|
||||
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
|
||||
@ -796,7 +796,10 @@
|
||||
#define D_SENSOR_WIEGAND_D1 "Wiegand D1"
|
||||
#define D_SENSOR_NEOPOOL_TX "NeoPool Tx"
|
||||
#define D_SENSOR_NEOPOOL_RX "NeoPool Rx"
|
||||
|
||||
#define D_SENSOR_VL53L0X_XSHUT "VL53L0X XSHUT"
|
||||
#define D_NEW_ADDRESS "Setting address to"
|
||||
#define D_OUT_OF_RANGE "Out of Range"
|
||||
#define D_SENSOR_DETECTED "detected"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
@ -28,7 +28,7 @@
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
*
|
||||
* Updated until v6.5.0.9
|
||||
* Updated until v9.3.1.1
|
||||
\*********************************************************************/
|
||||
|
||||
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
|
||||
@ -797,7 +797,10 @@
|
||||
#define D_SENSOR_WIEGAND_D1 "Wiegand D1"
|
||||
#define D_SENSOR_NEOPOOL_TX "NeoPool Tx"
|
||||
#define D_SENSOR_NEOPOOL_RX "NeoPool Rx"
|
||||
|
||||
#define D_SENSOR_VL53L0X_XSHUT "VL53L0X XSHUT"
|
||||
#define D_NEW_ADDRESS "Setting address to"
|
||||
#define D_OUT_OF_RANGE "Out of Range"
|
||||
#define D_SENSOR_DETECTED "detected"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
@ -28,7 +28,7 @@
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
*
|
||||
* Updated until v9.2.0.3
|
||||
* Updated until v9.3.1.1
|
||||
\*********************************************************************/
|
||||
|
||||
//#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
|
||||
@ -797,7 +797,10 @@
|
||||
#define D_SENSOR_WIEGAND_D1 "Wiegand D1"
|
||||
#define D_SENSOR_NEOPOOL_TX "NeoPool Tx"
|
||||
#define D_SENSOR_NEOPOOL_RX "NeoPool Rx"
|
||||
|
||||
#define D_SENSOR_VL53L0X_XSHUT "VL53L0X XSHUT"
|
||||
#define D_NEW_ADDRESS "Setting address to"
|
||||
#define D_OUT_OF_RANGE "Out of Range"
|
||||
#define D_SENSOR_DETECTED "detected"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
@ -28,7 +28,7 @@
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
*
|
||||
* Updated until v6.5.0
|
||||
* Updated until v9.3.1.1
|
||||
\*********************************************************************/
|
||||
|
||||
#define LANGUAGE_MODULE_NAME // Enable to display "Module Generic" (ie Spanish), Disable to display "Generic Module" (ie English)
|
||||
@ -797,7 +797,10 @@
|
||||
#define D_SENSOR_WIEGAND_D1 "Wiegand D1"
|
||||
#define D_SENSOR_NEOPOOL_TX "NeoPool Tx"
|
||||
#define D_SENSOR_NEOPOOL_RX "NeoPool Rx"
|
||||
|
||||
#define D_SENSOR_VL53L0X_XSHUT "VL53L0X XSHUT"
|
||||
#define D_NEW_ADDRESS "Setting address to"
|
||||
#define D_OUT_OF_RANGE "Out of Range"
|
||||
#define D_SENSOR_DETECTED "detected"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user