Browse Source

mostly done

master
Robin Thoni 9 years ago
parent
commit
debf1a65d8
3 changed files with 32 additions and 23 deletions
  1. 9
    8
      UsbRaw.cpp
  2. 3
    5
      UsbRaw.h
  3. 20
    10
      examples/UsbRawDemo1/main.ino

+ 9
- 8
UsbRaw.cpp View File

9
 UsbRawDevice::UsbRawDevice()
9
 UsbRawDevice::UsbRawDevice()
10
     : _dataSend(0),
10
     : _dataSend(0),
11
       _dataSendLen(0),
11
       _dataSendLen(0),
12
-      _callback(0),
13
-      _dataReceived(0),
14
-      _dataReceivedLen(0)
12
+      _callback(0)
15
 {
13
 {
16
 }
14
 }
17
 
15
 
40
 
38
 
41
 void UsbRawDevice::setDataString(const char* data)
39
 void UsbRawDevice::setDataString(const char* data)
42
 {
40
 {
43
-    setData((const uchar*)data, strlen(data));
41
+    setData((const uchar*)data, strlen(data) + 1);
42
+}
43
+
44
+void UsbRawDevice::setDataUsbNoMsg()
45
+{
46
+    setData(0, USB_NO_MSG);
44
 }
47
 }
45
 
48
 
46
 usbMsgLen_t UsbRawDevice::_usbFunctionSetup(usbRequest_t* rq)
49
 usbMsgLen_t UsbRawDevice::_usbFunctionSetup(usbRequest_t* rq)
47
 {
50
 {
48
-    _rq = rq;
51
+    _rq = *rq;
49
     if (_callback)
52
     if (_callback)
50
     {
53
     {
51
         _callback(rq, this, 0, 0);
54
         _callback(rq, this, 0, 0);
58
 
61
 
59
 uchar UsbRawDevice::_usbFunctionWrite(uchar *data, uchar len)
62
 uchar UsbRawDevice::_usbFunctionWrite(uchar *data, uchar len)
60
 {
63
 {
61
-    free(_dataReceived);
62
-    _dataReceived = (uchar*)memcpy(malloc(len), data, _dataReceivedLen = len);
63
     if (_callback)
64
     if (_callback)
64
     {
65
     {
65
-        _callback(_rq, this, _dataReceived, len);
66
+        _callback(&_rq, this, data, len);
66
     }
67
     }
67
     return 1;
68
     return 1;
68
 }
69
 }

+ 3
- 5
UsbRaw.h View File

25
 
25
 
26
     void setDataString(const char* data);
26
     void setDataString(const char* data);
27
 
27
 
28
+    void setDataUsbNoMsg();
29
+
28
     usbMsgLen_t _usbFunctionSetup(usbRequest_t* rq);
30
     usbMsgLen_t _usbFunctionSetup(usbRequest_t* rq);
29
 
31
 
30
     uchar _usbFunctionWrite(uchar *data, uchar len);
32
     uchar _usbFunctionWrite(uchar *data, uchar len);
39
 
41
 
40
     void (*_callback)(CALLBACK_ARGS);
42
     void (*_callback)(CALLBACK_ARGS);
41
 
43
 
42
-    uchar* _dataReceived;
43
-
44
-    uchar _dataReceivedLen;
45
-
46
-    usbRequest_t* _rq;
44
+    usbRequest_t _rq;
47
 };
45
 };
48
 
46
 
49
 extern UsbRawDevice UsbRaw;
47
 extern UsbRawDevice UsbRaw;

+ 20
- 10
examples/UsbRawDemo1/main.ino View File

9
 
9
 
10
 void callback(CALLBACK_ARGS)
10
 void callback(CALLBACK_ARGS)
11
 {
11
 {
12
-    if (rq->bRequest == 0)
12
+    /*digitalWrite(ledPin, !digitalRead(ledPin));
13
+    delay(100);*/
14
+
15
+    /*if (data)
13
     {
16
     {
17
+        strcpy((char *) buffer, (const char *) data);
18
+
14
         digitalWrite(ledPin, !digitalRead(ledPin));
19
         digitalWrite(ledPin, !digitalRead(ledPin));
20
+        delay(200);
21
+        digitalWrite(ledPin, !digitalRead(ledPin));
22
+    }*/
23
+
24
+    if (rq->bRequest == 0)
25
+    {
26
+        digitalWrite(ledPin, 0);
15
     }
27
     }
16
     else if (rq->bRequest == 1)
28
     else if (rq->bRequest == 1)
17
     {
29
     {
19
     }
31
     }
20
     else if (rq->bRequest == 4)
32
     else if (rq->bRequest == 4)
21
     {
33
     {
22
-        digitalWrite(ledPin, !digitalRead(ledPin));
23
-        /*if (!data)
34
+        if (data)
24
         {
35
         {
25
-            dev->setData(0, USB_NO_MSG);
36
+            digitalWrite(ledPin, !digitalRead(ledPin));
37
+            delay(200);
38
+            digitalWrite(ledPin, !digitalRead(ledPin));
39
+            strcpy((char *) buffer, (const char *) data);
26
         }
40
         }
27
         else
41
         else
28
         {
42
         {
29
-            dev->setData(data, sizeof(data));
30
-        }*/
31
-        if (data)
32
-        {
33
-            dev->setDataString("response");
43
+            dev->setDataUsbNoMsg();
34
         }
44
         }
35
     }
45
     }
36
     else
46
     else
37
     {
47
     {
38
-        dev->setData(data, strlen((const char*)data) + 1);
48
+        dev->setData(buffer, strlen((const char*)buffer) + 1);
39
     }
49
     }
40
 }
50
 }
41
 
51
 

Loading…
Cancel
Save