Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 Limited Edition and Dev Alpha C
My Carrier: Movistar-Venezuela

flashlight error in my app... [qml + c++ only]

hello brothers want help with something, create an application and has the option of flashlight.

use this example:

 

http://blackberry.github.com/Cascades-Samples/sensordemo.html

 

The flashlight does not work very well, but sometimes turns to select some of these in specific:

 

    Label {
        text: {
            if (light.val == AmbientLightReading.Dark) 
            {
                return qsTr("Light: Dark");
            } 
            else if (light.val == AmbientLightReading.Twilight) 
            {
                return qsTr("Light: Twilight");
            } 
            else if (light.val == AmbientLightReading.Light) 
            {
                return qsTr("Light: Light");
            } 
            else if (light.val == AmbientLightReading.Bright) 
           {
                return qsTr("Light: Bright");
            } 
            else if (light.val == AmbientLightReading.Sunny) 
            {
                return qsTr("Light: Sunny");
            } 
            else {
                return qsTr("Light: Undefined");
            }
        }
    }

    DropDown {
        id: lightDropDown
        title: qsTr("LUZ")

       Option {
            text: qsTr("Undefined")
       }
        Option {
            text: qsTr("Dark")
        }
        Option {
            text: qsTr("Twilight")
            selected: true
        }
        Option {
            text: qsTr("Light")
        }
        Option {
            text: qsTr("Bright")
        }
        Option {
            text: qsTr("Sunny")
        }
    }

 and also a gyroscope:

 

    Slider {
        id: gyroSlider
        value: 10
        fromValue: 0
        toValue: 50
    }

 

I want only one button On / Off button to turn on or off the flashlight and could adapt this example for it?

 

IMG_00000229.png

 

So looks today.


Follow me in Twitter:

@Marcossit

BBM Channel:

MarcossitDev: C0002C366  

DeviceSuite For BlackBerry 10:

Link to Download DeviceSuite:

Support was successful? Accept as Solution and click on:


Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: flashlight error in my app... [qml + c++ only]

[ Edited ]

This will turn it on, once it's on have a property set to change it back to 0 (off) when clicked again

 

Camera {
    id: myCamera
    attachedObjects: [
	CameraSettings {
	id: settings
	}
]
}

Button {
    text: "On"
onClicked { settings.cameraMode = 1 //sets camera mode to video settings.flashMode = 3; //sets flash mode to light myCamera.applySettings(settings);
} }

 

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 Limited Edition and Dev Alpha C
My Carrier: Movistar-Venezuela

Re: flashlight error in my app... [qml + c++ only]

[ Edited ]

Friend I get the following error with your code ..

 

sdsd.png

 

 

 

 

sadasdasd.png

 

 

 


Follow me in Twitter:

@Marcossit

BBM Channel:

MarcossitDev: C0002C366  

DeviceSuite For BlackBerry 10:

Link to Download DeviceSuite:

Support was successful? Accept as Solution and click on:


Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 Limited Edition and Dev Alpha C
My Carrier: Movistar-Venezuela

Re: flashlight error in my app... [qml + c++ only]

solvent and the mistake was that I miss onClicked:<--this {}

 

but will not start the Flash as ... This is my full code.

 

 

/* Copyright (c) 2012 Research In Motion Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import bb.cascades 1.0
import QtMobility.sensors 1.2
import Flashlight 1.0
import bb.system 1.0
import bb.cascades.multimedia 1.0
Page{
           
Container {
    
    //! [0]
    attachedObjects: [
        Flashlight {
            id: flashlight
        },

        Gyroscope {
            id: accel

            // Create a variable to count the number of sensor readings
            property int count: 0

            // Turn on the sensor
            active: true

            // Don't change sensor axis on screen rotation
            axesOrientationMode: Gyroscope.FixedOrientation

            // Keep the sensor active when the app isn't visible or the screen is off (requires app permission in bar-descriptor)
            alwaysOn: true

            // If the device isn't moving (x&y&z==0), don't send updates, saves power
            skipDuplicates: true

            onReadingChanged: { // Called when a gyroscope reading is available
                // Check whether rotation on Z axis is above the configured threshold
                if (reading.z > gyroSlider.value.toFixed() * 360 / (2 * 3.14)) {
                    if (count > 5 && ambLight.val < lightDropDown.selectedIndex) {
                        // If after 5 readings the ambient light is darker than the configured threshold, toggle the flash light
                        count = 0
                        flashlight.enabled = ! flashlight.enabled;
                    }
                }
                count ++;
            }
        },

        AmbientLightSensor {
            id: ambLight

            // Create a variable to hold the ambient light value
            property variant val: AmbientLightSensor.Undefined

            // Turn on the sensor
            active: true

            // Keep the sensor active when the app isn't visible or the screen is off (requires app permission in bar-descriptor)
            alwaysOn: true

            // If the device isn't moving (x&y&z==0), don't send updates, saves power
            skipDuplicates: true

            onReadingChanged: { // Called when an ambient light reading is available
                val = reading.lightLevel;
                if (ambLight.val >= lightDropDown.selectedIndex && flashlight.enabled) {
                    // Switch off the flash light if current ambient light is brigther than configured threshold
                    flashlight.enabled = false;
                }
            }
        },

        LightSensor {
            id: light

            // Create a variable to hold the ambient light value
            property real val: 0

            // Turn on the sensor
            active: true

            // Keep the sensor active when the app isn't visible or the screen is off (requires app permission in bar-descriptor)
            alwaysOn: true

            // If the device isn't moving (x&y&z==0), don't send updates, saves power
            skipDuplicates: true

            onReadingChanged: { // Called when an light reading is available
                val = reading.lux;
            }
        }
    ]
    //! [0]

  //  TextArea {
  //      text: qsTr("To enable the flash light give the device a clockwise flick with an angular velocity greater then 'Gyro Threshold'. The flashlight is only enabled in environments darker then 'Light Threshold'. The flashlight will automatically turn off in enviroments brighter then 'Light Threshold'.")
  //  }

    Label {
        text: {
            if (light.val == AmbientLightReading.Dark) 
            {
                return qsTr("Light: Dark");
            } 
            else if (light.val == AmbientLightReading.Twilight) 
            {
                return qsTr("Light: Twilight");
            } 
            else if (light.val == AmbientLightReading.Light) 
            {
                return qsTr("Light: Light");
            } 
            else if (light.val == AmbientLightReading.Bright) 
           {
                return qsTr("Light: Bright");
            } 
            else if (light.val == AmbientLightReading.Sunny) 
            {
                return qsTr("Light: Sunny");
            } 
            else {
                return qsTr("Light: Undefined");
            }
        }
    }

    DropDown {
        id: lightDropDown
        title: qsTr("LUZ")

       Option {
            text: qsTr("Undefined")
       }
        Option {
            text: qsTr("Dark")
        }
        Option {
            text: qsTr("Twilight")
            selected: true
        }
        Option {
            text: qsTr("Light")
        }
        Option {
            text: qsTr("Bright")
        }
        Option {
            text: qsTr("Sunny")
        }
    }

    Divider {}


       // text: qsTr("Oscuridad: 50%").arg(gyroSlider.value.toFixed())
   

    Label {
        text: qsTr("Oscuridad: %1").arg(gyroSlider.value.toFixed())
    }

    Slider {
        id: gyroSlider
        value: 10
        fromValue: 0
        toValue: 50
    }

    //! [1]
    Label {
        horizontalAlignment: HorizontalAlignment.Center

        text: qsTr("Luminosidad Exterior: %1 lux").arg(Math.round(light.val))
        textStyle {
            base: SystemDefaults.TextStyles.BodyText
            color: Color.Yellow
            fontWeight: FontWeight.Bold
            lineHeight: 2
        }
    }
    //! [1]
Camera {
    id: myCamera
    attachedObjects: [
	CameraSettings {
	id: settings
	}
]
}
    
       Button {
            objectName: "applySettings"
            text: "On"
          onClicked: {
        settings.cameraMode = 1 //sets camera mode to video
        settings.flashMode = 3; //sets flash mode to light
         myCamera.applySettings(settings);

            }
        }
        
        /*
        onClicked {
                settings.cameraMode = 1 //sets camera mode to video
                settings.flashMode = 3; //sets flash mode to light
                myCamera.applySettings(settings);
              } //other Code...
        */
 // button
}
}

 


Follow me in Twitter:

@Marcossit

BBM Channel:

MarcossitDev: C0002C366  

DeviceSuite For BlackBerry 10:

Link to Download DeviceSuite:

Support was successful? Accept as Solution and click on:


Developer
Posts: 828
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Rogers

Re: flashlight error in my app... [qml + c++ only]

[ Edited ]

if you haven't previously opened the camera then 

        onClicked {
                myCamera.open();
                settings.cameraMode = 1 //sets camera mode to video
                settings.flashMode = 3; //sets flash mode to light
                myCamera.applySettings(settings);
              } //other Code...

 make sure you close the camera if the application exits fullscreen or the device goes to sleep

 

onAsleep(myCamera.close()) or onThumbnailed(myCamera.close())