Sony's LANC camera control protocol project.

Dependencies:   aconno_LANC aconno_bsp aconno_SEGGER_RTT

Revision:
11:e5f11b96088e
Parent:
9:978106d4b181
Child:
12:69dbd9ef58e8
--- a/main.cpp	Wed Jul 11 13:53:47 2018 +0000
+++ b/main.cpp	Thu Jul 12 16:51:44 2018 +0000
@@ -15,10 +15,22 @@
 #include "GapAdvertisingData.h"
 #include "AckService.h"
 
-#define MY_BUF_SIZE     13*8
-#define LANC_H      0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF    /* 13 B */
-#define LANC_H_L    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF    /* 13 B */
-#define LANC_L      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00    /* 13 B */
+#define PRINT_ON_RTT    (1)
+
+#ifdef PRINT_ON_RTT
+    #include "SEGGER_RTT.h"
+    #define printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)
+#else
+    #define printf(...)
+#endif
+
+#define MY_BUF_SIZE     (13*8)
+#define LANC_H          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,\
+                        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF    /* 13 B */
+#define LANC_H_L        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,\
+                        0x00, 0x00, 0x00, 0x00, 0x00, 0xFF    /* 13 B */
+#define LANC_L          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
+                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00    /* 13 B */
 
 /*
  *  Bitovi na I2S bus idu od MSBa do LSBa
@@ -32,7 +44,7 @@
 
 uint8_t MSD[MSD_SIZE] = {0x59, 0x00, 0xDD, 0x4E, 0xCD, 0xC5, 0x5E, 0xA3, 0x43, 0x67, 0x8B, 0x84, 0x94, 0xFF, 0xBA, 0xD9, 0x29, 0xC6};
 uint8_t myMacAddress[6] = {};
-ACKService<1> *ackServicePtr;
+ACKService<2> *ackServicePtr;
 BLE &ble = BLE::Instance();
 
 void sendCommand(uint32_t *commandType, uint32_t *command);
@@ -66,7 +78,7 @@
 }
 
 void onDataWrittenCallback(const GattWriteCallbackParams *params) {
-    //newImage[cnt] = params->data[i];
+    /*
     switch(params->data[0]){
         case 0x00:{
             sendCommand(normalCmdAddr, startStopAddr);        
@@ -87,6 +99,28 @@
         }
         default: break;
     }
+    */
+    uint32_t commandType[MY_BUF_SIZE];
+    uint32_t command[MY_BUF_SIZE];
+    uint8_t counter;
+    
+    printf("Data[0]: %d\n", params->data[0]);
+    printf("Data[1]: %d\n", params->data[1]);
+    
+    for(counter = 0; counter < 8; counter++)
+    {
+        (params->data[0] & (1 << counter)) ? commandType[counter] = LANC_H : 
+                                             commandType[counter] = LANC_L;
+    }
+    
+    for(counter = 0; counter < 8; counter++)
+    {
+        (params->data[0] & (1 << counter)) ? command[counter] = LANC_H : 
+                                             command[counter] = LANC_L;
+    }
+    
+    //sendCommand(commandType, command);
+    
     return;
 }
 
@@ -114,13 +148,13 @@
  */
 void bleInitComplete(BLE::InitializationCompleteCallbackContext *params){
     BLE&        ble   = params->ble;  
-    uint8_t init_values[1];
+    uint8_t init_values[2];
     
    
     /* Get my MAC address */
     BLEProtocol::AddressType_t temp_address_type;
     ble.gap().getAddress(&temp_address_type, myMacAddress);
-    ackServicePtr = new ACKService<1>(ble, init_values);
+    ackServicePtr = new ACKService<2>(ble, init_values);
     
     ble.gap().onDisconnection(disconnectionCallback);
     ble.gap().onConnection(onConnectionCallback);