commit e1371225149e0f1ebb4b96e1826f6352aec2ec82
Author: Gokul S <g-s@ti.com>
Date:   Thu Jan 23 13:12:32 2025 +0530

    final commit

diff --git a/apps/basic_demos/app_multi_cam/main.c b/apps/basic_demos/app_multi_cam/main.c
index c4118f9..7b36ef5 100755
--- a/apps/basic_demos/app_multi_cam/main.c
+++ b/apps/basic_demos/app_multi_cam/main.c
@@ -152,6 +152,8 @@ typedef struct {
     vx_uint32 bypass_split_graph;
 
     vx_image gDisplayInImage;
+    uint32_t aewb_starting_channel;
+    uint32_t aewb1_starting_channel;
 
 } AppObj;
 
@@ -1060,7 +1062,7 @@ static vx_status app_init(AppObj *obj)
 
     if((1 == obj->enable_aewb) && (status == VX_SUCCESS))
     {
-        status = app_init_aewb(obj->context, &obj->aewbObj, &obj->sensorObj, "aewb_obj", 0, obj->objArrSplitObj.output0_num_elements);
+        status = app_init_aewb(obj->context, &obj->aewbObj, &obj->sensorObj, "aewb_obj", obj->aewb_starting_channel, obj->objArrSplitObj.output0_num_elements);
         APP_PRINTF("AEWB init done!\n");
     }
 
@@ -1076,7 +1078,7 @@ static vx_status app_init(AppObj *obj)
         APP_PRINTF("VISS init done!\n");
         if((1 == obj->enable_aewb) && (status == VX_SUCCESS))
         {
-            status = app_init_aewb(obj->context, &obj->aewbObj1, &obj->sensorObj, "aewb_obj", obj->objArrSplitObj.output0_num_elements, obj->objArrSplitObj.output1_num_elements);
+            status = app_init_aewb(obj->context, &obj->aewbObj1, &obj->sensorObj, "aewb_obj", obj->aewb1_starting_channel, obj->objArrSplitObj.output1_num_elements);
             APP_PRINTF("AEWB init done!\n");
         }
         if((obj->sensorObj.enable_ldc == 1) && (status == VX_SUCCESS))
@@ -1919,6 +1921,36 @@ static void set_img_mosaic_params(ImgMosaicObj *imgMosaicObj, vx_uint32 in_width
     imgMosaicObj->params.clear_count  = CAPTURE_BUFFER_Q_DEPTH;
 }
 
+static void app_update_aewb_stating_channel(AppObj *obj){
+    obj->aewb_starting_channel = 0;
+    vx_uint8 ch = obj->sensorObj.ch_mask;
+    if(obj->enable_split_graph == 0){
+        while( !(ch & 0x01) ){
+            obj->aewb_starting_channel++;
+            ch = ch >> 1;
+        }
+        printf("starting_channel %d\n",obj->aewb_starting_channel);
+    }
+    else{
+        
+        while( !(ch & 0x01) ){
+            obj->aewb_starting_channel++;
+            ch = ch >> 1;
+        }
+        obj->aewb1_starting_channel = obj->aewb_starting_channel;
+        vx_uint8 i=0;
+        while( i < obj->objArrSplitObj.output0_num_elements ){
+            
+            if( ch & 0x01 ) {
+                i++;
+            }
+            obj->aewb1_starting_channel++; 
+            ch = ch >> 1;
+        }
+        printf("starting_channel %d starting_channel_1 %d\n",obj->aewb_starting_channel, obj->aewb1_starting_channel);
+    }
+}
+
 static void app_update_param_set(AppObj *obj)
 {
     vx_uint16 resized_width, resized_height;
@@ -1941,6 +1973,7 @@ static void app_update_param_set(AppObj *obj)
         obj->objArrSplitObj.output0_num_elements = (obj->sensorObj.num_cameras_enabled + 1) / 2;
         obj->objArrSplitObj.output1_num_elements = obj->sensorObj.num_cameras_enabled - obj->objArrSplitObj.output0_num_elements;
     }
+    app_update_aewb_stating_channel(obj);
     set_img_mosaic_params(&obj->imgMosaicObj, resized_width, resized_height, obj->sensorObj.num_cameras_enabled, &obj->objArrSplitObj, obj->enable_split_graph);
 }
 
diff --git a/modules/src/app_aewb_module.c b/modules/src/app_aewb_module.c
index c9747d0..f6a64a5 100755
--- a/modules/src/app_aewb_module.c
+++ b/modules/src/app_aewb_module.c
@@ -160,6 +160,7 @@ static vx_status configure_aewb(vx_context context, AEWBObj *aewbObj, SensorObj
 
             ch = 0;
             ch_mask = sensorObj->ch_mask >> starting_channel;
+            vx_uint32 num_cameras_enabled_ = num_cameras_enabled;
             while(ch_mask > 0)
             {
                 if(ch_mask & 0x1)
@@ -169,10 +170,11 @@ static vx_status configure_aewb(vx_context context, AEWBObj *aewbObj, SensorObj
                     aewbObj->params.channel_id = ch + starting_channel;
                     vxCopyUserDataObject(config, 0, sizeof(tivx_aewb_config_t), &aewbObj->params, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST);
                     vxReleaseUserDataObject(&config);
+                    num_cameras_enabled_--;
                 }
-                ch++;
+                ch++; 
                 ch_mask = ch_mask >> 1;
-                if (ch >= num_cameras_enabled)
+                if ( num_cameras_enabled_ == 0)
                 {
                     break;
                 }
diff --git a/modules/src/app_sensor_module.c b/modules/src/app_sensor_module.c
index 73f02b2..c057f48 100755
--- a/modules/src/app_sensor_module.c
+++ b/modules/src/app_sensor_module.c
@@ -70,6 +70,7 @@ vx_status app_querry_sensor(SensorObj *sensorObj)
     char* sensor_list[ISS_SENSORS_MAX_SUPPORTED_SENSOR];
     vx_uint16 selectedSensor = 0xFFF;
     vx_uint8 sensors_detected[ISS_SENSORS_MAX_SUPPORTED_SENSOR];
+    uint8_t num_sensors_found= 0;
     vx_bool sensorSelected = vx_false_e;
 #if !(defined(SOC_AM62A) && defined(QNX))
     vx_bool ldcSelected = vx_false_e;
@@ -108,11 +109,16 @@ vx_status app_querry_sensor(SensorObj *sensorObj)
             ch = getchar();
             if(ch == '0')
             {
-                uint8_t num_sensors_found= 0;
                 uint16_t channel_mask = 0xFFF;
                 /*AutoDetect*/
                 memset(sensors_detected, 0xFFF, ISS_SENSORS_MAX_SUPPORTED_SENSOR);
                 status = appDetectImageSensor(sensors_detected, &num_sensors_found, channel_mask);
+                sensorSelected = sensorObj->num_sensors_found;
+                if(num_sensors_found < 1){
+                    status = -1;
+                    printf("No sensors found exiting \n");
+                    return status; 
+                }
                 if(0 == status)
                 {
                     int detected_sensor_index;
@@ -122,6 +128,7 @@ vx_status app_querry_sensor(SensorObj *sensorObj)
                         detected_sensor_index = sensors_detected[ch_id];
                         if(detected_sensor_index < ISS_SENSORS_MAX_SUPPORTED_SENSOR)
                         {
+                            selectedSensor = sensors_detected[ch_id]; // assuming all sensors are same
                             detected_sensor_name = sensor_list[detected_sensor_index];
                             printf("sensor detected at channel %d = %s \n", ch_id, detected_sensor_name);
                         }
@@ -140,15 +147,19 @@ vx_status app_querry_sensor(SensorObj *sensorObj)
             {
                 selectedSensor = ch - 'a';
                 /*Assume all cameras are identical*/
-                for(ch_id=0;ch_id<ISS_SENSORS_MAX_SUPPORTED_SENSOR;ch_id++)
-                {
-                    sensors_detected[ch_id] = selectedSensor;
-                }
+                // for(ch_id=0;ch_id<ISS_SENSORS_MAX_SUPPORTED_SENSOR;ch_id++)
+                // {
+                //     sensors_detected[ch_id] = selectedSensor;
+                // }
+                uint16_t channel_mask = 0xFFF;
+                /*AutoDetect*/
+                memset(sensors_detected, 0xFFF, ISS_SENSORS_MAX_SUPPORTED_SENSOR);
+                status = appDetectImageSensor(sensors_detected, &num_sensors_found, channel_mask);
             }
 
             //TODO : sensor properties need to be queried. 
             //Currently this is supported for cam0 only
-            selectedSensor = sensors_detected[0];
+            // selectedSensor = sensors_detected[0];
             if(selectedSensor > (sensorObj->num_sensors_found-1))
             {
                 printf("Invalid selection %d. Try again \n", selectedSensor);
@@ -217,7 +228,66 @@ vx_status app_querry_sensor(SensorObj *sensorObj)
                 printf("Invalid selection %d. Try again \n", num_cameras);
             }
         }
-        sensorObj->ch_mask = (1<<sensorObj->num_cameras_enabled) - 1;
+        // sensorObj->ch_mask = (1<<sensorObj->num_cameras_enabled) - 1;
+        sensorObj->ch_mask = 0;
+        if(num_sensors_found < sensorObj->num_cameras_enabled){
+            printf("Number of camera found is less than entered num_of_cameras\n");
+        }
+        
+        while(sensorObj->ch_mask == 0)
+        {
+            char c;
+            int ret;
+            int ch_mask;
+            fflush(stdin);
+            printf("Enter Channel mask in decimal. Indicates number and positions of cameras selected\n");
+            printf("For e.g. channel_mask = 15 (0x0F) indicates that first 4 cameras are enabled\n");
+            printf("Press 0 to autodetect channel mask \n");
+            ret = scanf("%d", &ch_mask);
+            while ((c = getchar()) != '\n' && c != EOF);
+            sensorObj->ch_mask = ch_mask;
+            if( (1==ret) && ((sensorObj->ch_mask > 0xfff) || (sensorObj->ch_mask < 0)) )
+            {
+                sensorObj->ch_mask = 0;
+                printf("Invalid selection %d. Try again \n", sensorObj->ch_mask);
+            }
+            else
+            {
+                if(sensorObj->ch_mask == 0){
+                    break;
+                }
+            }
+        }
+        if(sensorObj->ch_mask == 0){
+            num_sensors_found = num_sensors_found - sensorObj->num_cameras_enabled; // // num_sensors to skip
+            for(ch_id=ISS_SENSORS_MAX_SUPPORTED_SENSOR-1;ch_id >= 0;ch_id--)
+            {
+                sensorObj->ch_mask = (sensorObj->ch_mask << 1);
+                if(sensors_detected[ch_id] < ISS_SENSORS_MAX_SUPPORTED_SENSOR )
+                {
+                    if(num_sensors_found){
+                        num_sensors_found--;
+                    }
+                    else{
+                        sensorObj->ch_mask = sensorObj->ch_mask | 0x01; 
+                    }
+                }
+            }
+            printf("Detected channel mask = %x\n", sensorObj->ch_mask);
+        }
+        else{
+            vx_uint32 mask = sensorObj->ch_mask;
+            sensorObj->num_cameras_enabled = 0;
+            while(mask > 0)
+            {
+                if(mask & 0x1)
+                {
+                    sensorObj->num_cameras_enabled++;
+                }            
+                mask = mask >> 1;
+            }
+            printf("Channel mask = %x Number of camera selected = %d\n", sensorObj->ch_mask, sensorObj->num_cameras_enabled);
+        }
     }
     else
     {
