mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-15 04:56:15 +08:00
Add auto notification to USB Serial
This commit is contained in:
parent
b40937122a
commit
9f303ca3ee
@ -22,7 +22,7 @@
|
|||||||
#define _VERSION_ESP3D_H
|
#define _VERSION_ESP3D_H
|
||||||
|
|
||||||
// version and sources location
|
// version and sources location
|
||||||
#define FW_VERSION "3.0.0.a240"
|
#define FW_VERSION "3.0.0.a241"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||||
|
|
||||||
#endif //_VERSION_ESP3D_H
|
#endif //_VERSION_ESP3D_H
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
#include "../authentication/authentication_service.h"
|
#include "../authentication/authentication_service.h"
|
||||||
#include "usb_serial_service.h"
|
#include "usb_serial_service.h"
|
||||||
|
|
||||||
|
#if defined(NOTIFICATION_FEATURE)
|
||||||
|
#include "../notifications/notifications_service.h"
|
||||||
|
#endif // NOTIFICATION_FEATURE
|
||||||
|
|
||||||
const uint32_t SupportedUsbSerialBaudList[] = {
|
const uint32_t SupportedUsbSerialBaudList[] = {
|
||||||
9600, 19200, 38400, 57600, 74880, 115200, 230400,
|
9600, 19200, 38400, 57600, 74880, 115200, 230400,
|
||||||
250000, 500000, 921600, 1000000, 1958400, 2000000};
|
250000, 500000, 921600, 1000000, 1958400, 2000000};
|
||||||
@ -119,6 +123,9 @@ bool usb_rx_callback(const uint8_t *data, size_t data_len, void *arg) {
|
|||||||
void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) {
|
void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) {
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case CDC_ACM_HOST_ERROR:
|
case CDC_ACM_HOST_ERROR:
|
||||||
|
#if defined(NOTIFICATION_FEATURE)
|
||||||
|
notificationsservice.sendAutoNotification("USB Error occured");
|
||||||
|
#endif // NOTIFICATION_FEATURE
|
||||||
esp3d_log_e("CDC-ACM error has occurred, err_no = %d\n",
|
esp3d_log_e("CDC-ACM error has occurred, err_no = %d\n",
|
||||||
event->data.error);
|
event->data.error);
|
||||||
break;
|
break;
|
||||||
@ -142,13 +149,18 @@ void ESP3DUsbSerialService::setConnected(bool connected) {
|
|||||||
_is_connected = connected;
|
_is_connected = connected;
|
||||||
if (_is_connected) {
|
if (_is_connected) {
|
||||||
esp3d_log("USB device connected");
|
esp3d_log("USB device connected");
|
||||||
|
#if defined(NOTIFICATION_FEATURE)
|
||||||
|
notificationsservice.sendAutoNotification("USB Connected");
|
||||||
|
#endif // NOTIFICATION_FEATURE
|
||||||
if (xSemaphoreTake(_device_disconnected_mutex, portMAX_DELAY) != pdTRUE) {
|
if (xSemaphoreTake(_device_disconnected_mutex, portMAX_DELAY) != pdTRUE) {
|
||||||
esp3d_log_e("Mutex not taken");
|
esp3d_log_e("Mutex not taken");
|
||||||
_is_connected = false;
|
_is_connected = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
esp3d_log("USB device disconnected");
|
esp3d_log("USB device disconnected");
|
||||||
|
#if defined(NOTIFICATION_FEATURE)
|
||||||
|
notificationsservice.sendAutoNotification("USB Disconnected");
|
||||||
|
#endif // NOTIFICATION_FEATURE
|
||||||
xSemaphoreGive(_device_disconnected_mutex);
|
xSemaphoreGive(_device_disconnected_mutex);
|
||||||
_vcp_ptr = nullptr;
|
_vcp_ptr = nullptr;
|
||||||
}
|
}
|
||||||
@ -197,7 +209,8 @@ static void esp3d_usb_serial_connection_task(void *pvParameter) {
|
|||||||
|
|
||||||
void ESP3DUsbSerialService::connectDevice() {
|
void ESP3DUsbSerialService::connectDevice() {
|
||||||
if (!_started || _is_connected || _vcp_ptr) {
|
if (!_started || _is_connected || _vcp_ptr) {
|
||||||
//esp3d_log("USB device is connected (%d) or service not started (%d)", _is_connected, _started);
|
// esp3d_log("USB device is connected (%d) or service not started (%d)",
|
||||||
|
// _is_connected, _started);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const cdc_acm_host_device_config_t dev_config = {
|
const cdc_acm_host_device_config_t dev_config = {
|
||||||
@ -234,10 +247,8 @@ void ESP3DUsbSerialService::connectDevice() {
|
|||||||
esp3d_log("USB Connected");
|
esp3d_log("USB Connected");
|
||||||
uint16_t vid = esp_usb::getVID();
|
uint16_t vid = esp_usb::getVID();
|
||||||
uint16_t pid = esp_usb::getPID();
|
uint16_t pid = esp_usb::getPID();
|
||||||
esp3d_log("USB device with VID: 0x%04X (%s), PID: 0x%04X (%s) found\n",
|
esp3d_log("USB device with VID: 0x%04X (%s), PID: 0x%04X (%s) found\n", vid,
|
||||||
vid, esp_usb::getVIDString(), pid, esp_usb::getPIDString());
|
esp_usb::getVIDString(), pid, esp_usb::getPIDString());
|
||||||
// TODO:
|
|
||||||
// Do notification to user ?
|
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
} else {
|
} else {
|
||||||
esp3d_log_e("USB device not identified");
|
esp3d_log_e("USB device not identified");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user