mirror of
https://github.com/thelsing/knx.git
synced 2026-02-23 13:50:35 +01:00
move knx-usb to examples
This commit is contained in:
5
examples/knx-usb/.gitignore
vendored
Normal file
5
examples/knx-usb/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
8
examples/knx-usb/custom_hwids.py
Normal file
8
examples/knx-usb/custom_hwids.py
Normal file
@@ -0,0 +1,8 @@
|
||||
Import("env")
|
||||
|
||||
board_config = env.BoardConfig()
|
||||
board_config.update("build.hwids", [
|
||||
# ["0x135e", "0x0024"] # Merten GmbH & Co. KG
|
||||
# ["0x0E77", "0x2001"] # Weinzierl Engineering GmbH
|
||||
["0x7660", "0x0002"] # KNX Assoc.
|
||||
])
|
||||
35
examples/knx-usb/platformio.ini
Normal file
35
examples/knx-usb/platformio.ini
Normal file
@@ -0,0 +1,35 @@
|
||||
;PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:adafruit_feather_m0]
|
||||
platform = atmelsam
|
||||
board = adafruit_feather_m0
|
||||
framework = arduino
|
||||
|
||||
; VID must be changed to some known KNX Manufacturer
|
||||
; so that the KNX USB interface gets recognized by ETS
|
||||
extra_scripts = pre:custom_hwids.py
|
||||
board_build.usb_product="KNX RF - USB Interface"
|
||||
|
||||
lib_deps =
|
||||
Adafruit_TinyUSB_Arduino
|
||||
SPI
|
||||
https://github.com/thelsing/FlashStorage.git
|
||||
knx
|
||||
|
||||
build_flags =
|
||||
-DMEDIUM_TYPE=2
|
||||
-DUSE_CEMI_SERVER
|
||||
-DUSE_TINYUSB
|
||||
-Wno-unknown-pragmas
|
||||
|
||||
debug_tool = jlink
|
||||
#upload_protocol = jlink
|
||||
|
||||
128
examples/knx-usb/src/main.cpp
Normal file
128
examples/knx-usb/src/main.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_TinyUSB.h>
|
||||
#include <knx.h>
|
||||
|
||||
/*
|
||||
* USB stuff
|
||||
*/
|
||||
#define STRINGIFY(s) XSTRINGIFY(s)
|
||||
#define XSTRINGIFY(s) #s
|
||||
|
||||
#pragma message ("USB_VID=" STRINGIFY(USB_VID))
|
||||
#pragma message ("USB_PID=" STRINGIFY(USB_PID))
|
||||
#pragma message ("USB_MANUFACTURER=" STRINGIFY(USB_MANUFACTURER))
|
||||
#pragma message ("USB_PRODUCT=" STRINGIFY(USB_PRODUCT))
|
||||
|
||||
Adafruit_USBD_HID usb_hid;
|
||||
|
||||
// Invoked when received SET_REPORT control request or
|
||||
// received data on interrupt OUT endpoint
|
||||
void setReportCallback(uint8_t report_id, hid_report_type_t report_type, uint8_t const* data, uint16_t bufSize)
|
||||
{
|
||||
// we don't use multiple report and report ID
|
||||
(void) report_id;
|
||||
(void) report_type;
|
||||
|
||||
UsbTunnelInterface::receiveHidReport(data, bufSize);
|
||||
}
|
||||
|
||||
bool sendHidReport(uint8_t* data, uint16_t length)
|
||||
{
|
||||
// We do not use reportId of the TinyUSB sendReport()-API here but instead provide it in the first byte of the buffer
|
||||
return usb_hid.sendReport(0, data, length);
|
||||
}
|
||||
|
||||
bool isSendHidReportPossible()
|
||||
{
|
||||
return usb_hid.ready();
|
||||
}
|
||||
|
||||
/*
|
||||
* KNX stuff
|
||||
*/
|
||||
|
||||
// create macros easy access to group objects
|
||||
#define goTemperature knx.getGroupObject(1)
|
||||
#define goHumidity knx.getGroupObject(2)
|
||||
|
||||
uint32_t cyclSend = 0;
|
||||
uint8_t sendCounter = 0;
|
||||
long lastsend = 0;
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
/*
|
||||
* setup()
|
||||
*/
|
||||
void setup(void)
|
||||
{
|
||||
Serial1.begin(115200);
|
||||
ArduinoPlatform::SerialDebug = &Serial1;
|
||||
Serial1.println("Start.");
|
||||
|
||||
usb_hid.enableOutEndpoint(true);
|
||||
usb_hid.setPollInterval(2);
|
||||
usb_hid.setReportDescriptor(UsbTunnelInterface::getKnxHidReportDescriptor(), UsbTunnelInterface::getHidReportDescriptorLength());
|
||||
usb_hid.setReportCallback(NULL, setReportCallback);
|
||||
|
||||
usb_hid.begin();
|
||||
|
||||
// wait until device mounted
|
||||
while( !USBDevice.mounted() ) delay(1);
|
||||
|
||||
println("KNX USB Interface enabled.");
|
||||
|
||||
// read adress table, association table, groupobject table and parameters from eeprom
|
||||
knx.readMemory();
|
||||
|
||||
if (knx.induvidualAddress() == 0)
|
||||
knx.progMode(true);
|
||||
|
||||
|
||||
if (knx.configured())
|
||||
{
|
||||
cyclSend = knx.paramInt(0);
|
||||
Serial1.print("Zykl. send:");
|
||||
Serial1.println(cyclSend);
|
||||
goTemperature.dataPointType(Dpt(9, 1));
|
||||
goHumidity.dataPointType(Dpt(9, 1));
|
||||
}
|
||||
|
||||
// start the framework.
|
||||
knx.start();
|
||||
}
|
||||
|
||||
/*
|
||||
* loop()
|
||||
*/
|
||||
void loop(void)
|
||||
{
|
||||
// don't delay here to much. Otherwise you might lose packages or mess up the timing with ETS
|
||||
knx.loop();
|
||||
|
||||
// only run the application code if the device was configured with ETS
|
||||
if(!knx.configured())
|
||||
return;
|
||||
|
||||
long now = millis();
|
||||
if ((now - lastsend) < 3000)
|
||||
return;
|
||||
|
||||
lastsend = now;
|
||||
|
||||
float temp = 1.2345;
|
||||
float humi = 60.2;
|
||||
String output = String(millis());
|
||||
output += ", " + String(temp);
|
||||
output += ", " + String(humi);
|
||||
Serial1.println(output);
|
||||
|
||||
if (sendCounter++ == cyclSend)
|
||||
{
|
||||
sendCounter = 0;
|
||||
|
||||
goTemperature.value(temp);
|
||||
goHumidity.value(humi);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user