Flashlight (LED) toggle for D2G via Python! - Droid 2 Global Themes and Apps

Here is a script written in Python that will allow the user to toggle the camera flash led on or off on the Droid 2 Global. I got the idea from a Google search and basically the script writes a "1" to a system file to enable the light or writes "0" to disable it.
import sys
import android
import os
droid = android.Android()
def cls():
os.system(['clear','cls'][os.name == 'nt'])
def turnon():
light = open('/sys/class/leds/torch-flash/flash_light', 'w')
light.write('1')
def turnoff():
light = open('/sys/class/leds/torch-flash/flash_light', 'w')
light.write('0')
#Initial Display Box
title = 'Flashlight Toggle'
message = 'By. Guitarman2010'
droid.dialogCreateAlert(title,message)
droid.dialogSetPositiveButtonText('Ok')
droid.dialogShow()
response = droid.dialogGetResponse().result
yep = response['which'] == 'positive'
#Turns it on
title = 'Flashlight Toggle'
droid.dialogCreateAlert(title)
droid.dialogSetPositiveButtonText('Shine')
droid.dialogShow()
response = droid.dialogGetResponse().result
light = response['which'] == 'positive'
if light:
turnon()
cls()
#Turns if off
title = 'Turn off'
droid.dialogCreateAlert(title)
droid.dialogSetPositiveButtonText('OFF')
droid.dialogShow()
response = droid.dialogGetResponse().result
dark = response['which'] == 'positive'
if dark:
turnoff()
cls()
Sorry for the indentation loss
Edit: I forgot to say I am running cm4d2g
Here is my make-shift video demonstrating this:
http://www.youtube.com/watch?v=Noq5ch8PIig

Related

About dynamic slider

Solved
Hello,
I used a sample code is reading images from R.java file. I want to change it as display from web. But it has an error. Because i sent parameter is drawable but it must be Integer. How do i it?
Current Code
PHP:
image_prev = (ImageView)findViewById(R.id.image_prev);
image_centre = (ImageView)findViewById(R.id.image_centre);
image_next = (ImageView)findViewById(R.id.image_next);
image_res_ids = new ArrayList<Integer>();
image_res_ids.add(R.drawable.zero);
image_res_ids.add(R.drawable.one);
image_res_ids.add(R.drawable.two);
image_res_ids.add(R.drawable.three);
image_res_ids.add(R.drawable.four);
i want to change with
PHP:
image_prev = (ImageView)findViewById(R.id.image_prev);
image_centre = (ImageView)findViewById(R.id.image_centre);
image_next = (ImageView)findViewById(R.id.image_next);
image_res_ids = new ArrayList<Integer>();
Drawable image = loadImageFromURL("http://dedededede.com/image.png"));
image_res_ids.add(image);
example is here
I'm trying this.
image_res_ids.add(System.identityHashCode(image));
but it doesn't work too.

[Q] RemoteViews - OnClickListener & SetTextViewText

I have been working on a Home Screen widget for the past two days. The widget's `onUpdate()` method calls a service which fetches RSS information (title and image link) using `XmlPullParser`. These are working properly by printing the value in `LogCat`.
I want to set the text in the `TextView (tv1)` of AppWidget and image link as image to the `ImageView (imv1)` and a `TextView (go11)` clickable to open the browser and goto the link. I put the following in `OnStart()` just to test the SetText.
Code:
RemoteViews rv = new RemoteViews(this.getApplicationContext().getPackageName(),R.layout.main);
// Set the text
rv.setTextViewText(R.id.tv1,"WORKED");
Its not working. Second, I tried to set the image by:
Code:
InputStream is = (InputStream) new URL(imglnk).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
rv.setImageViewResource(R.id.imv1, 0);
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
rv.setImageViewBitmap(R.id.imv1,bitmap);
Where imglnk is the link to the image. ImageView is not showing the image.
Then I tried to set the OnClick listener to open the browser with google as a test.
Code:
RemoteViews rv1 = new RemoteViews("com.example.axstartup",R.layout.main);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
PendingIntent pi = PendingIntent.getActivity(context, 0, browserIntent,PendingIntent.FLAG_UPDATE_CURRENT);
rv1.setOnClickPendingIntent(R.id.go11, pi);
Even that is not working. Please help me with this.

C++ loop coding help

I have a program that writes out numbers in roman numerals. I need help writing a loop that repeats the program unless I enter -1 it will stop the program from repeating
Code:
#include <iostream>
using namespace std;
int main()
{
double num;
int intnum, m, d, c, l, x, v, i, n;
cout << "Enter a year (1000-3000) enter -1 to exit: ";
cin >> num;
intnum = (int)num;
m = intnum / 1000;
d = ((intnum%1000) / 500);
c = ((intnum%500) / 100);
l = ((intnum%100) / 50);
x = ((intnum%50) / 10);
v = ((intnum%10) / 5);
i = (intnum%5);
n = m + d + c + l + x + v + i;
while (n > 0)
{
cout << "";
{
for (m; m>0; m--)
cout << "M";
}
{
for (d; d>0; d--)
cout << "D";
}
{
for (c; c>0; c--)
cout << "C";
}
{
for (l; l>0; l--)
cout << "L";
}
{
for (x; x>0; x--)
cout << "X";
}
{
for (v; v>0; v--)
cout << "V";
}
{
for (i; i>0; i--)
cout << "I";
}
n--;
}
return 0;
}
I think you want to put your code into another loop, like this:
while (1) {
cin >> num;
if (num == -1) break;
// process num here
}
cycad said:
I think you want to put your code into another loop, like this:
while (1) {
cin >> num;
if (num == -1) break;
// process num here
}
Click to expand...
Click to collapse
It doesn't allow me to quit unless I input -1 which is good BUT it does not repeat the process. After it gives me a roman numeral it just stays there and does nothing until I press -1
I need it to ask me again to enter a year and it will output a roman numeral.
You need to break this down into functions so it's more readable. If something is confusing keep breaking it down.
Try including <string> and then using this prototype:
string ConvertToRomanNumeral(int n);
Also use this prototype:
int GetInput();
Once you create those functions, then you can do something like this in your main function:
while (1) {
num = GetInput();​if (num == -1) break;​string roman_numerals = ConvertToRomanNumeral(num);​cout << roman_numerals << endl;​}
It's a lot easier to read this way.
As a side note, you can input values 1 to 3999 for your algorithm to handle them correctly. Twice as much at no extra cost!
daniel-s said:
As a side note, you can input values up to 3999 for you algorithm to handle them correctly. 33% bonus at no extra cost!
Click to expand...
Click to collapse
Actually this really only works for values up to 3. 4 comes out as IIII which is only right for clocks.
cycad said:
You need to break this down into functions so it's more readable. If something is confusing keep breaking it down.
Try including <string> and then using this prototype:
string ConvertToRomanNumeral(int n);
Also use this prototype:
int GetInput();
Once you create those functions, then you can do something like this in your main function:
while (1) {
num = GetInput();​if (num == -1) break;​string roman_numerals = ConvertToRomanNumeral(num);​cout << roman_numerals << endl;​}
It's a lot easier to read this way.
Click to expand...
Click to collapse
Thanks got it to work.
I have another question about another code. When I run it is suppose to give me the answer to the quadratic equation but it doesn't it gives me "No roots available. How can I fix to make it work properly so when I type in 3 numbers it gives me the answer to the quadratic equation and if there is any roots.
Code:
#include <iostream>
#include <cmath>
using namespace std;
double discriminant(double n1, double n2, double n3);
double pos(double n1, double n2, double n3);
double neg(double n1, double n2, double n3);
int main()
{
double a;
double b;
double c;
double discrimi;
double sqr1;
double sqr2;
cout << "Enter the first number in the quadratic equation: ";
cin >> a;
cout << "Enter the second number in the quadratic equation: ";
cin >> b;
cout << "Enter the third number in the quadratic equation: ";
cin >> c;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
discrimi = discriminant (a,b,c);
if(discrimi > 0 && a != 0) {
sqr1 = pos(a,b,c);
sqr2 = neg(a,b,c);
cout << "In the equation " <<a <<" + "<< b <<" x + "<< c <<" = 0 ";
cout << "Roots of the equation are " << sqr2 <<" & " << sqr2 << endl;
}
else
cout << "No roots availible in the equation. ";
return (0);
}
double discriminant(double a,
double b,
double c){
double discrim;
discrim = pow(b,2) - 4 * a *c;
return(discrim);
}
double pos(double a,
double b,
double c){
double sqr_1;
sqr_1 = (-b + sqrt(pow(b,2) - 4 * a * c)) / (2 * a);
return(sqr_1);
}
double neg(double a,
double b,
double c){
double sqr_2;
sqr_2 = (-b - sqrt(pow(b,2) - 4 * a * c)) / (2 * a);
return(sqr_2);
}
what is this
If these are parts of an exercise or a homework assignment, then the whole point is for you to debug these issues on your own.
You're asking for some very basic debugging. Let me assure you, it's bad practice to run to the forum the first minute your code breaks. Debugging code that you have authored yourself is something that you must master if you want to become any good. And if you're not interested in becoming good, why are you doing this in the first place?

Factory mode

I've seen for other devices a factory mode cable, it's how I rooted kindle fire. http://forum.xda-developers.com/showthread.php?t=1392693
I was looking at LG's kernel source and seen this
/g3-kernel/arch/arm/mach-msm/lge/devices_lge.c
Code:
static enum lge_boot_mode_type lge_boot_mode = LGE_BOOT_MODE_NORMAL;
int __init lge_boot_mode_init(char *s)
{
if (!strcmp(s, "charger"))
lge_boot_mode = LGE_BOOT_MODE_CHARGER;
else if (!strcmp(s, "chargerlogo"))
lge_boot_mode = LGE_BOOT_MODE_CHARGERLOGO;
else if (!strcmp(s, "qem_130k") || !strcmp(s, "factory"))
lge_boot_mode = LGE_BOOT_MODE_FACTORY;
else if (!strcmp(s, "qem_56k") || !strcmp(s, "factory2"))
lge_boot_mode = LGE_BOOT_MODE_FACTORY2;
else if (!strcmp(s, "qem_910k"))
lge_boot_mode = LGE_BOOT_MODE_FACTORY3;
else if (!strcmp(s, "pif_130k") || !strcmp(s, "pifboot"))
lge_boot_mode = LGE_BOOT_MODE_PIFBOOT;
else if (!strcmp(s, "pif_56k") || !strcmp(s, "pifboot2"))
lge_boot_mode = LGE_BOOT_MODE_PIFBOOT2;
else if (!strcmp(s, "pif_910k"))
lge_boot_mode = LGE_BOOT_MODE_PIFBOOT3;
printk("ANDROID BOOT MODE : %d %s\n", lge_boot_mode, s);
/* */
This is about ID pin in the usb connector. The 56k, 130k, 910k, I believe are resistance value. No idea what qem or pif are.
Anyone want to give it a shot and build some cables?
The original Fires were a ***** to root without the cables...I did a bunch of them, but had to use the "short circuit the board" method, with a piece of wire each time to get into fastboot mode, then followed with a Linux script. A dedicated cable would make it much simpler.

Amlogic .dts editing for LED light

I've got an s905x Amlogic box running SlimBox but the LED light is always on and it's very distracting.
I've extracted the .dts from the original Android 6 .dtb and want to edit SlimBox Android 9 .dts to add proper LED support.
Original Android 6 .dts:
Code:
ledlight {
compatible = "amlogic, ledlight";
dev_name = "ledlight";
status = "okay";
power_gpio_0 = <0x70>;
power_gpio_1 = <0x71>;
power_gpio_g {
led_name = "power_led";
led_gpio = <0x20 0x49 0x0>;
led_active = <0x1>;
led_type = [47 00];
linux,phandle = <0x70>;
phandle = <0x70>;
};
power_gpio_r {
led_name = "power_led";
led_gpio = <0x69 0x6 0x0>;
led_active = <0x1>;
led_type = [52 00];
linux,phandle = <0x71>;
phandle = <0x71>;
};
};
SlimBox Android 9 .dts:
Code:
sysled {
compatible = "amlogic, sysled";
dev_name = "sysled";
status = "okay";
led_gpio = <0x11 0x49 0x0>;
led_active_low = <0x1>;
};
Any ideas?
Hello.
I am also interested in learning how to control the led.
Greetings.
Hello.
I have tried the Khadas Rom from Supurceleron SC_VIM2_USER_NORMAL-v2.0-20210315.img and the definition for the led is the same as in Slimbox android 9. But from the khadas settings you can control the behavior of the LED, always on, always off and flash mode.
So even though the definition in the android 9 .dts is like this, you can somehow control the behavior of the LED, but it's beyond my knowledge.
Greetings.

Categories

Resources