LP Long Distance IR Vision Robot

Dependencies:   max77650_charger_sample BufferedSerial SX1276GenericLib Adafruit-MotorShield NEO-6m-GPS MAX17055_EZconfig Adafruit_GFX USBDeviceHT Adafruit-PWM-Servo-Driver

Revision:
23:f74a50977593
Parent:
22:abca9d17d13d
Child:
24:e8d03912f303
--- a/main.cpp	Fri Jul 13 18:22:53 2018 +0000
+++ b/main.cpp	Wed Jul 18 18:52:30 2018 +0000
@@ -10,7 +10,17 @@
  */
  
  #include "main.h"
+ #include "global_buffers.h"
+ #include "GridEye.h"
 
+
+/* If the board that is compiled is the master device (BLE enabled MAX32630FTHR),
+ * then it needs this library and needs to be configed in order for the device to 
+ * work with a 3.3volt output instead of a 1.8 volt output. 
+ * 
+ * This is only needed for the MAX32630FTHR. The MAX325620FTHR is exampt from this 
+ * additional setup in the main program.
+ */ 
  #if defined(TARGET_MAX32630FTHR) // using the RFM95 board
    #include "max32630fthr.h"
     MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
@@ -19,13 +29,23 @@
 DigitalOut myled(LED);
 
 
-int main() {
-#ifdef HELTEC_STM32L4
-    DigitalOut vext(POWER_VEXT);
-    vext = POWER_VEXT_ON;
-#endif    
+#if   defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
+    /* No grid eye object needed. The function the master uses to convert the raw 
+     * data that is sent over from the slave deevice that contains the data from the
+     * actual grid eye sensor is actually a function that is not part of the grid eye
+     * class. this is due to the fact that the grid eye class requires n i2c bus to 
+     * be assigned to a phyiscal sensor. In this case, the library for the Grid Eye 
+     * sensor has a support functin that is used to convert data that is aquired from 
+     * the grid eye sensor. So it is not supposed to be a class specific function.
+    */
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: Robot
+    //Init I2C communications in default I2C bus I2C #1
+    I2C i2cGridEye(P3_4,P3_5);
+    GridEye gridEye(i2cGridEye);
+#endif
 
-
+int main() 
+{
     /*
      * inits the Serial or USBSerial when available (230400 baud).
      * If the serial uart is not is not connected it swiches to USB Serial
@@ -36,10 +56,71 @@
     dprintf("Welcome to the SX1276GenericLib");
   
     dprintf("Starting a simple LoRa PingPong");
+    
+    /* Setup begins here: */
+    
+    /***************************************************************************
+     * Lora Communications
+     **************************************************************************/
     SX1276PingPongSetup();
+    
+    /***************************************************************************
+     * Grid Eye Sensor: Non-Buffer Program Variables
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        int frame_idx = 0;
+    #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
+        // none yet
+    #endif
+    
+    
     while(1) 
-    {
+    {        
+        /***************************************************************************
+         * Grid Eye Sensor 
+         **************************************************************************/
+        #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        
+            // Check to see if the contents of the previous scan are the same. If they are different then continue with converting
+            if( memcmp(prev_raw_frame_data_from_slave, curr_raw_frame_data_from_slave, sizeof(curr_raw_frame_data_from_slave)) != 0 )
+            {
+                // Convert raw data sent from slave to a 16 bit integer array by calling this
+                convRaw8x8Data2Point25degC(curr_raw_frame_data_from_slave, conv_frame_data_from_slave);
+                
+                // Next Print off the Converted data
+                dprintf("\r\nFrame %d data: \r\n", frame_idx);
+                uint8_t idx;
+                float pixel_data;
+                for (int y = 0; y < 8; y++) {
+                    for (int x = 0; x < 8; x++) {
+                        idx = y*8 + x;
+                        pixel_data = conv_frame_data_from_slave[idx]/4.0;
+                        dprintf("%.2f  \t", pixel_data);
+                    }
+                    dprintf("\r\n\r\n");
+                }
+                dprintf("\r\n");
+                
+                // Increment frame counter
+                frame_idx = frame_idx +1;
+            }
+            
+        #elif defined(TARGET_MAX32620FTHR) // Client Device: LoRa Controlled Robot
+            // Aquire raw data about 8x8 frame from the grid eye sensor in this function call 
+            gridEye.getRaw8x8FrameData(curr_raw_frame_data_to_master);
+            
+        #endif
+
+    
+        /***************************************************************************
+        * Lora Communications
+        **************************************************************************/
         SX1276PingPong();
+    
+        
+        
+        
+        
     }
     
 }