Help module to simulate Gyroscope with Accelerometer and Compass - Xposed General
Hello!
I test a fake gyro on Unity 5, with C# and works on my Moto G XT1032
I wanna make a virtual gyroscope with the accelerometer values and the compass value
I've downloaded a gyroscope noise filter (XposedJitteryGyroFix) to replace the gyroscope values with fake gyro values, but this don't make a gyroscope on my phone, don't works, don't found a gyroscope on apps
Can Xposed make a fake gyroscope on android's system?
what did you download? I'm also interested
compass + accelerometer should make a so so gyro
cougarten said:
what did you download? I'm also interested
compass + accelerometer should make a so so gyro
Click to expand...
Click to collapse
I've download a XposedJitteryGyroFix, that filter the noise from Gyroscope and replace the real Gyroscope Values, but don't make a fake gyroscope on system, because that don't work on my phone
Fake Gyro Script
This code makes a fake gyro values, with (x,y,z)'s acceleration and compass input:
Code:
public float[] fakeGyro(float x, float y, float z, float compass)
{
float[] gyro = new float[3];
double xrot = Math.atan2(z, y);
double yzmag = Math.sqrt(Math.pow(y, 2) + Math.pow(z, 2));
double zrot = Math.atan2(x, yzmag);
double xangle = xrot * (180 / Math.PI) + 180;
double zangle = -zrot * (180 / Math.PI);
gyro[0] = (float)xangle;
gyro[1] = (float)zangle;
gyro[2] = compass;
return gyro;
}
This code convert the degree values to radians, because the gyroscope have values on radians:
Code:
public float degreeToRad(float degree)
{
return degree * 0.0174533f;
}
I've replace this from the filter gyro's project:
Code:
protected void beforeHookedMethod(MethodHookParam param) throws
Throwable {
Field field = param.thisObject.getClass().getEnclosingClass().getDeclaredField("sHandleToSensor");
field.setAccessible(true);
int handle = (Integer) param.args[0];
Sensor ss = ((SparseArray<Sensor>) field.get(0)).get(handle);
if (ss.getType() == Sensor.TYPE_GYROSCOPE || ss.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
changeSensorEvent((float[]) param.args[1]);
}
}
To this:
Code:
protected void beforeHookedMethod(MethodHookParam param) throws
Throwable {
Field field = param.thisObject.getClass().getEnclosingClass().getDeclaredField("sHandleToSensor");
field.setAccessible(true);
int handle = (Integer) param.args[0];
Sensor ss = ((SparseArray<Sensor>) field.get(0)).get(handle);
// PUT VALUES HERE
float x = 0;
float y = 0;
float z = 0;
float compass = 0;
float[] val;
if(ss.getType() == Sensor.TYPE_ACCELEROMETER)
{
val = (float[])param.args[1];
x = degreeToRad(val[0])/9.81f;
y = degreeToRad(val[1])/9.81f;
z = degreeToRad(val[2])/9.81f;
/*x = val[0];
y = val[1];
z = val[2];*/
}
if(ss.getType() == Sensor.TYPE_ORIENTATION)
{
val = (float[])param.args[1];
compass = degreeToRad(val[0]);
}
float[] Gyro;
Gyro = fakeGyro(x,y,z,compass);
if (ss.getType() == Sensor.TYPE_GYROSCOPE || ss.getType() == Sensor.TYPE_GYROSCOPE_UNCALIBRATED) {
//changeSensorEvent((float[]) param.args[1]);
changeSensorEvent(Gyro);
}
}
how to use the Code?
Hey,
I have the same Problem..
I also need a fake gyroscope sensor on my Sony m5, lollipop 5.1
Could you please tell me how to use the Code above?
Thanks in Advance
Luis
GaussGEIST said:
Hey,
I have the same Problem..
I also need a fake gyroscope sensor on my Sony m5, lollipop 5.1
Could you please tell me how to use the Code above?
Thanks in Advance
Luis
Click to expand...
Click to collapse
The calculation of FakeGyro is using accelerometer X Y and Z, but these variables is between -1 and 1, but I don't know how is on Android Studio, I've made it for Unity 5 and works on game, not made a virtual gyro
That don't works because I don't know why, the apps don't recognize the fake gyro, and I don't know how make it works, I mind the filter only replace values of gyro, but don't make a virtual gyro with the values that try to replace
I don't know how can make a virtual gyroscope's sensor
I've download the source of XposedJitteryGyroFix and edit with:
Add the first and second code one line before of:
Code:
private static List<Object> antiJitterValues(boolean absolute_mode, float[] values, float[][] medianValues, float[] prevValues) {
The first code is for calculate fake gyro with Acceleration(X Y Z) and Compass
The second code is for convert degrees to rads
The third code it's for find to replace with the fourth code
any news?
kos25k said:
any news?
Click to expand...
Click to collapse
No, I don't know how to do that works, and I haven't got help of someone
nicolobos77 said:
No, I don't know how to do that works, and I haven't got help of someone
Click to expand...
Click to collapse
hello, i share your thread here : [XPOSED] VirtualSensor - Emulate a gyroscope from the accelerometer and compass
nicolobos77 said:
Hello!
I test a fake gyro on Unity 5, with C# and works on my Moto G XT1032
I wanna make a virtual gyroscope with the accelerometer values and the compass value
I've downloaded a gyroscope noise filter (XposedJitteryGyroFix) to replace the gyroscope values with fake gyro values, but this don't make a gyroscope on my phone, don't works, don't found a gyroscope on apps
Can Xposed make a fake gyroscope on android's system?
Click to expand...
Click to collapse
That's awesome dude, hope someone could help you soon!
Groso, espero que alguien te pueda ayudar!
josegon30 said:
That's awesome dude, hope someone could help you soon!
Groso, espero que alguien te pueda ayudar!
Click to expand...
Click to collapse
Someone have created a module and works on my Moto G
Alguien creo un modulo que funciona en mi Moto G
http://forum.xda-developers.com/xposed/modules/xposed-virtualsensor-emulate-gyroscope-t3424555
Related
fix multitouch?? or not??
MotionEvent http://android-developers.blogspot.com/?hl=en The Android framework’s primary point of access for touch data is the android.view.MotionEvent class. Passed to your views through the onTouchEvent and onInterceptTouchEvent methods, MotionEvent contains data about “pointers,” or active touch points on the device’s screen. Through a MotionEvent you can obtain X/Y coordinates as well as size and pressure for each pointer. MotionEvent.getAction() returns a value describing what kind of motion event occurred. One of the more common uses of touch input is letting the user drag an object around the screen. We can accomplish this in our View class from above by implementing onTouchEvent as follows: @Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); // Remember where we started mLastTouchX = x; mLastTouchY = y; break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); // Calculate the distance moved final float dx = x - mLastTouchX; final float dy = y - mLastTouchY; // Move the object mPosX += dx; mPosY += dy; // Remember this touch position for the next move event mLastTouchX = x; mLastTouchY = y; // Invalidate to request a redraw invalidate(); break; } } return true; } The code above has a bug on devices that support multiple pointers. While dragging the image around the screen, place a second finger on the touchscreen then lift the first finger. The image jumps! What’s happening? We’re calculating the distance to move the object based on the last known position of the default pointer. When the first finger is lifted, the second finger becomes the default pointer and we have a large delta between pointer positions which our code dutifully applies to the object’s location. If all you want is info about a single pointer’s location, the methods MotionEvent.getX() and MotionEvent.getY() are all you need. MotionEvent was extended in Android 2.0 (Eclair) to report data about multiple pointers and new actions were added to describe multitouch events. MotionEvent.getPointerCount() returns the number of active pointers. getX and getY now accept an index to specify which pointer’s data to retrieve.
anyone know?
You don't have much code up there but... "mLastTouchX = x; mLastTouchY = y;" I assume those are globals... and the fact is that both action down and action move use those at the same time if you use two fingers... EX: -finger down create mlasttouchx&y at lets says 0,0 and you move to 1,1 enabling action move to correct it... -keep finger still and add second finger... -second finger changes the SAME variables of the previous item -lift first finger so on action up theres no update (since you have no action up) I'm not sure HOW to fix this issue (I've never tried multitouch) but your code doesn't support it. How about adding some toggle variables and add an action up so on release it updates the points OR try using pointers (up to 3 as far as i can see probably for multitouch) http://developer.android.com/reference/android/view/MotionEvent.html
Disable magnetic screen on/off sensor
Hi, I believe the title says it all. I tried to find the solution here but without success. While Im satisfied with my Nexus 7 case, I found out that sometimes if I just close it and put the tablet into bag it fails to turn the screen off. So, Id prefer to do that manually. Is there a software way to disable the magnetic sensor? I dont want to play tailor with my case ...
Just manually turn it off. Closing the case won't turn your screen back on... If the problem is that as the tab shuffles around in your bag and the case cover opens just enough to turn it back on, that's a different issue. Then you'll need some type of band or something to put around it. Sent from my Nexus 7 using Tapatalk 2
Thanks, that will do. :good: But is there really NO sw way to disable it? I dont like automatic functions just lying around ...
michalurban said: Thanks, that will do. :good: But is there really NO sw way to disable it? I dont like automatic functions just lying around ... Click to expand... Click to collapse Unless you find a way in the code to disable it or figure out how to physically remove it. or... just get a case with out a magnet in it.
knitler said: Unless you find a way in the code to disable it or figure out how to physically remove it. or... just get a case with out a magnet in it. Click to expand... Click to collapse Ive been hoping in someone else finding the way to disable it in the code. Anyway, I guess Ill get another case and see ... THX! :good:
michalurban said: Ive been hoping in someone else finding the way to disable it in the code. Anyway, I guess Ill get another case and see ... THX! :good: Click to expand... Click to collapse Until seeing it on youtube, I wasn't even aware of this feature. The amazing thing to me is the fact that the actual case sold for the N7 at the google store does not have this feature (ie. no magnet)......
Im afraid I took the matters into my own hands and solved my magnetic problem once and for all ... :laugh:
michalurban said: Im afraid I took the matters into my own hands and solved my magnetic problem once and for all ... :laugh: Click to expand... Click to collapse Your case isn't nearly as attractive now. Seriously, I can't see how this was a real issue unless your case was designed badly. Example; some flip-around cases if not shielded will turn the N7 off when flipped around.
khaytsus said: Your case isn't nearly as attractive now. Seriously, I can't see how this was a real issue unless your case was designed badly. Example; some flip-around cases if not shielded will turn the N7 off when flipped around. Click to expand... Click to collapse Well, small hole inside the case isnt a big deal for me. Anyway, the problem was that the case managed to turn the tablet off only when closed really good. And if closed, only a few milimeters (say 2) of movement of the front cover to the left made the case wake my N7. I couldnt really be sure what would the Thing do in my bag - but the case itself is good, co I kept it this way.
This can be done strictly via software. Here is a modified version of the kernel driver from drivers/input/lid.c that allows you to enable/disable this feature. By default, it acts normally. To disable the magnetic switch, do "echo 0 > /sys/module/lid/parameters/lid_enabled", or use any other app you want to write to that file. To enable it again, just write a non-zero value to the parameter. Ive only tested it on my nexus7, but it seems to work perfectly. Code: /* * ASUS Lid driver. */ #include <linux/module.h> #include <linux/err.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/input.h> #include <linux/platform_device.h> #include <linux/workqueue.h> #include <linux/gpio_event.h> #include <asm/gpio.h> #include <../gpio-names.h> #include "lid.h" MODULE_DESCRIPTION(DRIVER_LID); MODULE_LICENSE("GPL"); /* * functions declaration */ static void lid_report_function(struct work_struct *dat); static int lid_input_device_create(void); static ssize_t show_lid_status(struct device *class, struct device_attribute *attr,char *buf); /* * global variable */ static unsigned int hall_sensor_gpio = TEGRA_GPIO_PS6; static struct workqueue_struct *lid_wq; static struct input_dev *lid_indev; static struct platform_device *lid_dev; /* Device structure */ // to allow enabling/disabling the lid switch static int lid_enabled = 1; module_param( lid_enabled, int, 0644 ); static DEVICE_ATTR(lid_status, S_IWUSR | S_IRUGO, show_lid_status,NULL); /* Attribute Descriptor */ static struct attribute *lid_attrs[] = { &dev_attr_lid_status.attr, NULL }; /* Attribute group */ static struct attribute_group lid_attr_group = { .attrs = lid_attrs, }; static ssize_t show_lid_status(struct device *class,struct device_attribute *attr,char *buf) { return sprintf(buf, "%d\n", gpio_get_value(hall_sensor_gpio)); } static irqreturn_t lid_interrupt_handler(int irq, void *dev_id){ if( lid_enabled ) { int gpio = irq_to_gpio(irq); if (gpio == hall_sensor_gpio){ LID_NOTICE("LID interrupt handler...gpio: %d..\n", gpio_get_value(hall_sensor_gpio)); queue_delayed_work(lid_wq, &lid_hall_sensor_work, 0); } } else { printk( "lid: ignoring irq\n" ); } return IRQ_HANDLED; } static int lid_irq_hall_sensor(void) { int rc = 0 ; unsigned gpio = hall_sensor_gpio; unsigned irq = gpio_to_irq(hall_sensor_gpio); const char* label = "hall_sensor" ; LID_INFO("gpio = %d, irq = %d\n", gpio, irq); LID_INFO("GPIO = %d , state = %d\n", gpio, gpio_get_value(gpio)); tegra_gpio_enable(gpio); rc = gpio_request(gpio, label); if (rc) { LID_ERR("gpio_request failed for input %d\n", gpio); } rc = gpio_direction_input(gpio) ; if (rc) { LID_ERR("gpio_direction_input failed for input %d\n", gpio); goto err_gpio_direction_input_failed; } LID_INFO("GPIO = %d , state = %d\n", gpio, gpio_get_value(gpio)); rc = request_irq(irq, lid_interrupt_handler,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, label, lid_indev); if (rc < 0) { LID_ERR("Could not register for %s interrupt, irq = %d, rc = %d\n", label, irq, rc); rc = -EIO; goto err_gpio_request_irq_fail ; } enable_irq_wake(irq); LID_INFO("LID irq = %d, rc = %d\n", irq, rc); return 0 ; err_gpio_request_irq_fail : gpio_free(gpio); err_gpio_direction_input_failed: return rc; } static void lid_report_function(struct work_struct *dat) { int value = 0; if (lid_indev == NULL){ LID_ERR("LID input device doesn't exist\n"); return; } msleep(CONVERSION_TIME_MS); value = gpio_get_value(hall_sensor_gpio); if(value) input_report_switch(lid_indev, SW_LID, 0); else input_report_switch(lid_indev, SW_LID, 1); input_sync(lid_indev); LID_NOTICE("SW_LID report value = %d\n", value); } static int lid_input_device_create(void){ int err = 0; lid_indev = input_allocate_device(); if (!lid_indev) { LID_ERR("lid_indev allocation fails\n"); err = -ENOMEM; goto exit; } lid_indev->name = "lid_input"; lid_indev->phys = "/dev/input/lid_indev"; set_bit(EV_SW, lid_indev->evbit); set_bit(SW_LID, lid_indev->swbit); err = input_register_device(lid_indev); if (err) { LID_ERR("lid_indev registration fails\n"); goto exit_input_free; } return 0; exit_input_free: input_free_device(lid_indev); lid_indev = NULL; exit: return err; } static int __init lid_init(void) { int err_code = 0; printk(KERN_INFO "%s+ #####\n", __func__); LID_NOTICE("start LID init.....\n"); lid_dev = platform_device_register_simple("LID", -1, NULL, 0); if (!lid_dev){ printk ("LID_init: error\n"); return -ENOMEM; } sysfs_create_group((struct kobject*)&lid_dev->dev.kobj, &lid_attr_group); err_code = lid_input_device_create(); if(err_code != 0) return err_code; lid_wq = create_singlethread_workqueue("lid_wq"); INIT_DELAYED_WORK_DEFERRABLE(&lid_hall_sensor_work, lid_report_function); lid_irq_hall_sensor(); return 0; } static void __exit lid_exit(void) { input_unregister_device(lid_indev); sysfs_remove_group(&lid_dev->dev.kobj, &lid_attr_group); platform_device_unregister(lid_dev); } module_init(lid_init); module_exit(lid_exit);
So how would one go about implementing this modified code? Personally, I can't believe that there is not a standard setting to enable/disable this feature, but it ROM developers and/or users can implement this modified code easily, that would be a big help! Thanks. Sent from my ASUS Transformer Pad TF700T using Tapatalk 2
jtrosky said: So how would one go about implementing this modified code? Personally, I can't believe that there is not a standard setting to enable/disable this feature, but it ROM developers and/or users can implement this modified code easily, that would be a big help! Thanks. Click to expand... Click to collapse To disable the magnetic switch, do "echo 0 > /sys/module/lid/parameters/lid_enabled" Click to expand... Click to collapse The code was for reference. EDIT: No it's not, I'm an idiot.
Not the way I read it. The modified code has to be built into a kernel to access the option file. Sent from my Nexus 7 using xda app-developers app
Yes, this is one of the files that make up the kernel, with about 10 lines added to it. You would have to replace the file in the kernel source code, build the kernel, insert that kernel into a boot.img, and flash it to your tablet. If you can't manage all that, then you could pester the person who does make the kernel you're using to add it.
rmm200 said: Not the way I read it. The modified code has to be built into a kernel to access the option file. Click to expand... Click to collapse This is what I get for reading things too fast.. Ah well.
gianptune said: This can be done strictly via software. Here is a modified version of the kernel driver from drivers/input/lid.c that allows you to enable/disable this feature. By default, it acts normally. To disable the magnetic switch, do "echo 0 > /sys/module/lid/parameters/lid_enabled", or use any other app you want to write to that file. To enable it again, just write a non-zero value to the parameter. Ive only tested it on my nexus7, but it seems to work perfectly. Code: /* * ASUS Lid driver. */ #include <linux/module.h> #include <linux/err.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/input.h> #include <linux/platform_device.h> #include <linux/workqueue.h> #include <linux/gpio_event.h> #include <asm/gpio.h> #include <../gpio-names.h> #include "lid.h" MODULE_DESCRIPTION(DRIVER_LID); MODULE_LICENSE("GPL"); /* * functions declaration */ static void lid_report_function(struct work_struct *dat); static int lid_input_device_create(void); static ssize_t show_lid_status(struct device *class, struct device_attribute *attr,char *buf); /* * global variable */ static unsigned int hall_sensor_gpio = TEGRA_GPIO_PS6; static struct workqueue_struct *lid_wq; static struct input_dev *lid_indev; static struct platform_device *lid_dev; /* Device structure */ // to allow enabling/disabling the lid switch static int lid_enabled = 1; module_param( lid_enabled, int, 0644 ); static DEVICE_ATTR(lid_status, S_IWUSR | S_IRUGO, show_lid_status,NULL); /* Attribute Descriptor */ static struct attribute *lid_attrs[] = { &dev_attr_lid_status.attr, NULL }; /* Attribute group */ static struct attribute_group lid_attr_group = { .attrs = lid_attrs, }; static ssize_t show_lid_status(struct device *class,struct device_attribute *attr,char *buf) { return sprintf(buf, "%d\n", gpio_get_value(hall_sensor_gpio)); } static irqreturn_t lid_interrupt_handler(int irq, void *dev_id){ if( lid_enabled ) { int gpio = irq_to_gpio(irq); if (gpio == hall_sensor_gpio){ LID_NOTICE("LID interrupt handler...gpio: %d..\n", gpio_get_value(hall_sensor_gpio)); queue_delayed_work(lid_wq, &lid_hall_sensor_work, 0); } } else { printk( "lid: ignoring irq\n" ); } return IRQ_HANDLED; } static int lid_irq_hall_sensor(void) { int rc = 0 ; unsigned gpio = hall_sensor_gpio; unsigned irq = gpio_to_irq(hall_sensor_gpio); const char* label = "hall_sensor" ; LID_INFO("gpio = %d, irq = %d\n", gpio, irq); LID_INFO("GPIO = %d , state = %d\n", gpio, gpio_get_value(gpio)); tegra_gpio_enable(gpio); rc = gpio_request(gpio, label); if (rc) { LID_ERR("gpio_request failed for input %d\n", gpio); } rc = gpio_direction_input(gpio) ; if (rc) { LID_ERR("gpio_direction_input failed for input %d\n", gpio); goto err_gpio_direction_input_failed; } LID_INFO("GPIO = %d , state = %d\n", gpio, gpio_get_value(gpio)); rc = request_irq(irq, lid_interrupt_handler,IRQF_TRIGGER_RISING|IRQF_TRIGGER_FALLING, label, lid_indev); if (rc < 0) { LID_ERR("Could not register for %s interrupt, irq = %d, rc = %d\n", label, irq, rc); rc = -EIO; goto err_gpio_request_irq_fail ; } enable_irq_wake(irq); LID_INFO("LID irq = %d, rc = %d\n", irq, rc); return 0 ; err_gpio_request_irq_fail : gpio_free(gpio); err_gpio_direction_input_failed: return rc; } static void lid_report_function(struct work_struct *dat) { int value = 0; if (lid_indev == NULL){ LID_ERR("LID input device doesn't exist\n"); return; } msleep(CONVERSION_TIME_MS); value = gpio_get_value(hall_sensor_gpio); if(value) input_report_switch(lid_indev, SW_LID, 0); else input_report_switch(lid_indev, SW_LID, 1); input_sync(lid_indev); LID_NOTICE("SW_LID report value = %d\n", value); } static int lid_input_device_create(void){ int err = 0; lid_indev = input_allocate_device(); if (!lid_indev) { LID_ERR("lid_indev allocation fails\n"); err = -ENOMEM; goto exit; } lid_indev->name = "lid_input"; lid_indev->phys = "/dev/input/lid_indev"; set_bit(EV_SW, lid_indev->evbit); set_bit(SW_LID, lid_indev->swbit); err = input_register_device(lid_indev); if (err) { LID_ERR("lid_indev registration fails\n"); goto exit_input_free; } return 0; exit_input_free: input_free_device(lid_indev); lid_indev = NULL; exit: return err; } static int __init lid_init(void) { int err_code = 0; printk(KERN_INFO "%s+ #####\n", __func__); LID_NOTICE("start LID init.....\n"); lid_dev = platform_device_register_simple("LID", -1, NULL, 0); if (!lid_dev){ printk ("LID_init: error\n"); return -ENOMEM; } sysfs_create_group((struct kobject*)&lid_dev->dev.kobj, &lid_attr_group); err_code = lid_input_device_create(); if(err_code != 0) return err_code; lid_wq = create_singlethread_workqueue("lid_wq"); INIT_DELAYED_WORK_DEFERRABLE(&lid_hall_sensor_work, lid_report_function); lid_irq_hall_sensor(); return 0; } static void __exit lid_exit(void) { input_unregister_device(lid_indev); sysfs_remove_group(&lid_dev->dev.kobj, &lid_attr_group); platform_device_unregister(lid_dev); } module_init(lid_init); module_exit(lid_exit); Click to expand... Click to collapse im interested in trying this on the sprint GS4. can you possibly be a little more detailed on what i need to do? thank you very much.
In my opinion the best solution to this problem is two steps: 1) Remove any magnet in the case cover. Disables smart cover feature physically rather than software. 2) Use NFC tags with programs configured to control exactly the items needed, e.g. sleep mode, settings, wi-fi, etc. This may require two to four NFC tags, one for each major scenario. These might be "deep sleep, battery save", "sleep with fast restore", "wake no communicate", "wake and communication", etc. You could put the tags on a strip of material along with color codes. Touch the tag to the NFC sensor and no messing around. As others may notice, I attended the XDA dev conference. LOL
As I know all magnetic cases or stuffs are harmful for mobile phones or tablets... By the way do you guys think that, can this little magnet in the case ، hurm n7 in the long term ?
Xposed Module Somebody made a Xposed module for the Moto G that disables the magnetic lock. It could work on the N7, but i dont have a smart cover to try. http://forum.xda-developers.com/showthread.php?t=2621807
sasa31 said: As I know all magnetic cases or stuffs are harmful for mobile phones or tablets... By the way do you guys think that, can this little magnet in the case ، hurm n7 in the long term ? Click to expand... Click to collapse I ordered my N7 during the IO in which it was announced. Been in a magnetic case since then, so about a year and a half. What do you "know" is harmful? A static magnetic field is unlikely to harm solid state electronics or affect their operation. Sent from my SCH-I545 using Tapatalk
implement gyro in Game
Hi, I am a beginner in the world of Android Studio and I have to develop a Game for a school project. Now I want implement the X value of the accelerometer (player has to go to right or left). I have made a class called "Gyroscope" which extends my Game panel class. I am not sure what to do now, could someone please help me? Gyroscope.class: Code: public class Gyroscope extends Activity implements SensorEventListener { private Sensor Gyro; private SensorManager SenMan; public static float xValue; @Override protected void onCreate (Bundle savedInstanceState){ super.onCreate(savedInstanceState); SenMan = (SensorManager)getSystemService(SENSOR_SERVICE); Gyro = SenMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); SenMan.registerListener(this, Gyro, SensorManager.SENSOR_DELAY_NORMAL); } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) {} @Override public void onSensorChanged(SensorEvent event) { xValue = event.values[0]; } } Code in Game Panel: Code: public boolean Gyroscope(){ if(Gyroscope.xValue < 0 ){ player.setUp(false); } return true;} As a test, I had set Player.setUp(false);. This is only because i have not set the movement to left and right at this moment.
adding xml with java code
im not sure how to do this. but im doing a simple crazy 8 countdown score tracker. So far i got main activity with 4 buttons 1, 2, 3, 4 for players. when you click on them what i want to do is popul,ate input text fields based on how manyt players are joining the game. so for example if i select 3 i want the next activity to display 3 text fields so i can put their names in. Im pretty new here so im not sure how to achieve this. God i wish this was more like php. i would do it with a breeze. eg php code. while($players){ echo "<input type=text name=plyr".$players."name>Enter ".$players." player name</input>"; }
Search Google for add views programmatically. Trimis de pe al meu Sony Z2 D6503
Try this code: Code: TextView textView = new TextView(context); textView.setText("your text"); textView.setId(TextView.generateViewId()); //generate id for this View if you want to access it in future idList.add(textView.getId()); //idList is a ArrayList contains all TextView id which are created dynamically parentView.addView(textView);
In Android, you can pass parameters/data between activities by using Intent. Let's say selectOne is your button's onclick function Code: // MainActivity public final static String EXTRA_NUMBER_PLAYER = "com.example.myfirstapp.NUMBER_PLAYER"; public void selectOne(View view) { Intent intent = new Intent(this, NextActivity.class); intent.putExtra(EXTRA_NUMBER_PLAYER, 1); startActivity(intent); } In your NextActivity, you can retrieve the number Code: // NextActivity @Override protected void onCreate(Bundle savedInstanceState) { // Other codes Intent intent = getIntent(); int numberPlayer = intent.getIntExtra(MainActivity.EXTRA_NUMBER_PLAYER); } For more detail, you can refer to https://developer.android.com/training/basics/firstapp/starting-activity.html. I'm a PHP developer also. Feel free to drop me any question.
Optical Dust Sensor GP2Y1010AU0F
Hi there, i am looking for some help to configure the optical dust sensor in C++ language. What i need it to do is to be able to detect any dust particles and im able to retrieve the reading and display it on an 20x4 character LCD Display connected to a PIC18F4550 Microcontroller. But the problem is this Optical Dust sensor is really confusing and i have troubles configuring it. The Optical Dust sensor is just another part of my project and this is the code for the Dust sensor, would love to receive some help or correction on the codes thanks! : void ADC_dust() { int length; float volt_reading; char result; char error[] = "ERROR! "; ADCON0= 0X0D; //convert channel 3. PORTAbits.RA4 = 0; //turn on LED Delay10KTCYx(4); //wait for reading to become stable ADCON0bits.GO = 1; // This is bit0 of ADCON0, START CONVERSION NOW while(ADCON0bits.GO == 1); // Waiting for DONE PORTAbits.RA4 = 1; //volt_reading = ((ADRES-50+0.1-0.1)/614)*0.52; //*check if vdd change overtime volt_reading = (ADRES*5.0)/1024; //*check if vdd change overtime volt_reading = (volt_reading*(5/29))-(3/29); // Update LCD dust values displaydec(volt_reading, 3, 0xD9); // Display dust value lcd_write_data('m'); lcd_write_data('g'); lcd_write_data(0x2F); // To write '/' 0010x1111 lcd_write_data('m'); // write '3' lcd_write_data(0x33); lcd_write_data(' '); lcd_write_data(' '); // Update Thingspeak dust Values length = dec2buf(volt_reading, 3); // Convert dust value into string ESP8266_SendData(length, '4'); // Update Thingspeak Pressure value (Field 4) }