Current version

Fork of mbed-os-example-ble-LED by mbed-os-examples

Revision:
21:837783a9ea32
Parent:
20:f9f18052df0c
--- a/source/main.cpp	Wed Mar 08 13:51:28 2017 +0000
+++ b/source/main.cpp	Thu Apr 13 14:45:06 2017 +0000
@@ -26,16 +26,16 @@
 #define FOCUS_FAR           (4)
 #define RECORD              (5)
 
-#define LANC_COMMAND_PIN    (p2)   // Pin connected to Tr to pull lanc bus down/up
-#define LANC_PIN            (p3)   // Lanc bus pin (to scan for START/STOP bits)
+#define LANC_COMMAND_PIN    (p2)   // Pin connected to Tr to pull lanc bus down/up     2
+#define LANC_PIN            (p3)   // Lanc bus pin (to scan for START/STOP bits)        3
 
 
-#define LANC_BIT_DURATION   (92)   // One LANC bit duration in ms
+#define LANC_BIT_DURATION   (105)   // One LANC bit duration in us
 #define LANC_MIN_DELAY      (5)
 #define NUMBER_OF_REPETITIONS (4)
 
-#define REC_CMD_1           (0xAA)
-#define REC_CMD_2           (0xAA)
+#define REC_CMD_1           (0x18)
+#define REC_CMD_2           (0x33)
 #define ZOOM_IN_CMD_4_1     (0x28)
 #define ZOOM_IN_CMD_4_2     (0x08)
 #define ZOOM_OUT_CMD_4_1    (0x28)
@@ -50,9 +50,10 @@
 DigitalOut led_blue(p23, 0);
 DigitalOut led_green(p24, 0);
 
+Serial uart(LANC_COMMAND_PIN, NC, 9600); // tx, rx-> NOT used
+
 void send_command(uint8_t command_1, uint8_t command_2);
 
-DigitalOut command_pin     LANC_COMMAND_PIN;
 DigitalIn  lanc_pin        LANC_PIN;
 
 Timer timer;
@@ -168,17 +169,14 @@
 void init_lanc_bus(){
     // Function initialize lanc bus by pulling it up
     // Bus goes HIGH by setting command pin to LOW
-    command_pin = 0;
     wait_ms(LANC_MIN_DELAY);
 }
 
 void send_command(uint8_t command_1, uint8_t command_2){
     uint8_t command_counter = 0;
-        
     
     while(command_counter < NUMBER_OF_REPETITIONS){
         while(1){
-            //Arduino's PulseIn function (inline implemetation)
             while (lanc_pin == 0);      // Waiting for HIGH
             timer.start();
             while(lanc_pin == 1);        // Waiting for LOW 
@@ -188,29 +186,29 @@
             }
         }
     
-    // Program is out of the while loop -> bus is LOW -> START bit of BYTE_0 is here
+    // Program is out of the while loop -> bus is LOW -> camera generated START BIT
+    // START BIT should last for 104us
+    //wait_us(104);  // -> NEMOJ čekat jer bi to značilo da će start bit trajati dvostruko duže
+    // Now write data on LANC_COMMAND pin
+    uart.putc(command_1 ^ 0xFF);
     
-    // Write Byte 0 to the bus
-    for(int i=0; i<8; i++){
-        command_pin = (command_1 & (1<<i));
-        wait_us(LANC_BIT_DURATION);
-    }
     // Put LANC bus back to HIGH
-    command_pin = 0;
     // Make sure to be in the stop bit before the Byte 1
     wait_us(5); 
     
     // Look while lanc bus is HIGH for STOP bit
     while(lanc_pin == 1);
     
+    uart.putc(command_2 ^ 0xFF);
     //wait_us(LANC_BIT_DURATION);
     //Write Byte 1 to the bus
+    /*
     for(int i=0; i<8; i++){
         command_pin = (command_2 & (1<<i));
         wait_us(LANC_BIT_DURATION);
     }
+    */
     // Put LANC bus back to HIGH
-    command_pin = 0;
     command_counter++;
     
     /*
@@ -228,13 +226,18 @@
     led_green = 1;
     led_blue = 1;
     
-    init_lanc_bus();
+    // init_lanc_bus();
     
     eventQueue.call_every(50, blinkCallback);
     BLE &ble = BLE::Instance();
     ble.onEventsToProcess(scheduleBleEventsProcessing);
     ble.init(bleInitComplete);
 
+    while(1){
+        send_command(REC_CMD_1,REC_CMD_2);
+        wait_ms(1000);
+    }
+    
     eventQueue.dispatch_forever();
 
     return 0;