26
26
#include " ../authentication/authentication_service.h"
27
27
#include " usb_serial_service.h"
28
28
29
+ #if defined(NOTIFICATION_FEATURE)
30
+ #include " ../notifications/notifications_service.h"
31
+ #endif // NOTIFICATION_FEATURE
32
+
29
33
const uint32_t SupportedUsbSerialBaudList[] = {
30
34
9600 , 19200 , 38400 , 57600 , 74880 , 115200 , 230400 ,
31
35
250000 , 500000 , 921600 , 1000000 , 1958400 , 2000000 };
@@ -119,6 +123,9 @@ bool usb_rx_callback(const uint8_t *data, size_t data_len, void *arg) {
119
123
void handle_event (const cdc_acm_host_dev_event_data_t *event, void *user_ctx) {
120
124
switch (event->type ) {
121
125
case CDC_ACM_HOST_ERROR:
126
+ #if defined(NOTIFICATION_FEATURE)
127
+ notificationsservice.sendAutoNotification (" USB Error occured" );
128
+ #endif // NOTIFICATION_FEATURE
122
129
esp3d_log_e (" CDC-ACM error has occurred, err_no = %d\n " ,
123
130
event->data .error );
124
131
break ;
@@ -142,13 +149,18 @@ void ESP3DUsbSerialService::setConnected(bool connected) {
142
149
_is_connected = connected;
143
150
if (_is_connected) {
144
151
esp3d_log (" USB device connected" );
152
+ #if defined(NOTIFICATION_FEATURE)
153
+ notificationsservice.sendAutoNotification (" USB Connected" );
154
+ #endif // NOTIFICATION_FEATURE
145
155
if (xSemaphoreTake (_device_disconnected_mutex, portMAX_DELAY) != pdTRUE) {
146
156
esp3d_log_e (" Mutex not taken" );
147
157
_is_connected = false ;
148
-
149
158
}
150
159
} else {
151
160
esp3d_log (" USB device disconnected" );
161
+ #if defined(NOTIFICATION_FEATURE)
162
+ notificationsservice.sendAutoNotification (" USB Disconnected" );
163
+ #endif // NOTIFICATION_FEATURE
152
164
xSemaphoreGive (_device_disconnected_mutex);
153
165
_vcp_ptr = nullptr ;
154
166
}
@@ -196,8 +208,9 @@ static void esp3d_usb_serial_connection_task(void *pvParameter) {
196
208
}
197
209
198
210
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);
201
214
return ;
202
215
}
203
216
const cdc_acm_host_device_config_t dev_config = {
@@ -234,10 +247,8 @@ void ESP3DUsbSerialService::connectDevice() {
234
247
esp3d_log (" USB Connected" );
235
248
uint16_t vid = esp_usb::getVID ();
236
249
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 ());
241
252
setConnected (true );
242
253
} else {
243
254
esp3d_log_e (" USB device not identified" );
@@ -398,7 +409,7 @@ size_t ESP3DUsbSerialService::writeBytes(const uint8_t *buffer, size_t size) {
398
409
return 0 ;
399
410
}
400
411
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) {
402
413
if (!(_vcp_ptr && _vcp_ptr->set_control_line_state (true , true ) == ESP_OK)) {
403
414
esp3d_log_e (" Failed to set control line state" );
404
415
return 0 ;
0 commit comments