Skip to content

Commit 9f303ca

Browse files
committed
Add auto notification to USB Serial
1 parent b409371 commit 9f303ca

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

esp3d/src/include/esp3d_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define _VERSION_ESP3D_H
2323

2424
// version and sources location
25-
#define FW_VERSION "3.0.0.a240"
25+
#define FW_VERSION "3.0.0.a241"
2626
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
2727

2828
#endif //_VERSION_ESP3D_H

esp3d/src/modules/usb-serial/usb_serial_service.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "../authentication/authentication_service.h"
2727
#include "usb_serial_service.h"
2828

29+
#if defined(NOTIFICATION_FEATURE)
30+
#include "../notifications/notifications_service.h"
31+
#endif // NOTIFICATION_FEATURE
32+
2933
const uint32_t SupportedUsbSerialBaudList[] = {
3034
9600, 19200, 38400, 57600, 74880, 115200, 230400,
3135
250000, 500000, 921600, 1000000, 1958400, 2000000};
@@ -119,6 +123,9 @@ bool usb_rx_callback(const uint8_t *data, size_t data_len, void *arg) {
119123
void handle_event(const cdc_acm_host_dev_event_data_t *event, void *user_ctx) {
120124
switch (event->type) {
121125
case CDC_ACM_HOST_ERROR:
126+
#if defined(NOTIFICATION_FEATURE)
127+
notificationsservice.sendAutoNotification("USB Error occured");
128+
#endif // NOTIFICATION_FEATURE
122129
esp3d_log_e("CDC-ACM error has occurred, err_no = %d\n",
123130
event->data.error);
124131
break;
@@ -142,13 +149,18 @@ void ESP3DUsbSerialService::setConnected(bool connected) {
142149
_is_connected = connected;
143150
if (_is_connected) {
144151
esp3d_log("USB device connected");
152+
#if defined(NOTIFICATION_FEATURE)
153+
notificationsservice.sendAutoNotification("USB Connected");
154+
#endif // NOTIFICATION_FEATURE
145155
if (xSemaphoreTake(_device_disconnected_mutex, portMAX_DELAY) != pdTRUE) {
146156
esp3d_log_e("Mutex not taken");
147157
_is_connected = false;
148-
149158
}
150159
} else {
151160
esp3d_log("USB device disconnected");
161+
#if defined(NOTIFICATION_FEATURE)
162+
notificationsservice.sendAutoNotification("USB Disconnected");
163+
#endif // NOTIFICATION_FEATURE
152164
xSemaphoreGive(_device_disconnected_mutex);
153165
_vcp_ptr = nullptr;
154166
}
@@ -196,8 +208,9 @@ static void esp3d_usb_serial_connection_task(void *pvParameter) {
196208
}
197209

198210
void ESP3DUsbSerialService::connectDevice() {
199-
if (!_started || _is_connected || _vcp_ptr ) {
200-
//esp3d_log("USB device is connected (%d) or service not started (%d)", _is_connected, _started);
211+
if (!_started || _is_connected || _vcp_ptr) {
212+
// esp3d_log("USB device is connected (%d) or service not started (%d)",
213+
// _is_connected, _started);
201214
return;
202215
}
203216
const cdc_acm_host_device_config_t dev_config = {
@@ -234,10 +247,8 @@ void ESP3DUsbSerialService::connectDevice() {
234247
esp3d_log("USB Connected");
235248
uint16_t vid = esp_usb::getVID();
236249
uint16_t pid = esp_usb::getPID();
237-
esp3d_log("USB device with VID: 0x%04X (%s), PID: 0x%04X (%s) found\n",
238-
vid, esp_usb::getVIDString(), pid, esp_usb::getPIDString());
239-
// TODO:
240-
// Do notification to user ?
250+
esp3d_log("USB device with VID: 0x%04X (%s), PID: 0x%04X (%s) found\n", vid,
251+
esp_usb::getVIDString(), pid, esp_usb::getPIDString());
241252
setConnected(true);
242253
} else {
243254
esp3d_log_e("USB device not identified");
@@ -398,7 +409,7 @@ size_t ESP3DUsbSerialService::writeBytes(const uint8_t *buffer, size_t size) {
398409
return 0;
399410
}
400411
esp3d_log("writeBytes %d : %s", size, (const char *)buffer);
401-
if (_vcp_ptr && _vcp_ptr->tx_blocking((uint8_t *)buffer, size) == ESP_OK) {
412+
if (_vcp_ptr && _vcp_ptr->tx_blocking((uint8_t *)buffer, size) == ESP_OK) {
402413
if (!(_vcp_ptr && _vcp_ptr->set_control_line_state(true, true) == ESP_OK)) {
403414
esp3d_log_e("Failed to set control line state");
404415
return 0;

0 commit comments

Comments
 (0)