简体   繁体   English

通过gluon CharmDown服务从指南针和加速度计传感器获取值

[英]Get values from compass and accelerometer sensors, with gluon CharmDown services

I have a phone ARCHOS DIAMOND S with Android 5.1 Lollipop, that includes accelerometer and compass sensors. 我有一部配备Android 5.1 Lollipop的ARCHOS DIAMOND S手机,其中包括加速度计和指南针传感器。 I have checked them with some freeware. 我已经用一些免费软件检查了它们。

Moreover, DisplayService, OrientationService work fine. 而且,DisplayService,OrientationService可以正常工作。 But not the compass and accelerometer services. 但不是指南针和加速度计服务。

Have I forgotten something in the Java code? 我忘记了Java代码中的某些内容吗?

Thanks for your help 谢谢你的帮助

Accelerometer: "acceleration.getX()" does not work. 加速度计:“ acceleration.getX()”不起作用。 In the console, ""Test accelero 2a"" is written and, then, a shutdown message appears 在控制台中,写入““ Test accelero 2a””,然后显示关闭消息

Label labelVarAafficherAccelX = new Label();
Label labelVarAafficherAccelY = new Label();
System.out.println("Test accelero 1");
Services.get(AccelerometerService.class).ifPresent(service -> {
    Acceleration acceleration = service.getCurrentAcceleration();  
    System.out.println("Test accelero 2a");
    double getX = acceleration.getX();  // that does not work
    System.out.println("**Test accelero 2b**");
    String varAafficherAccelX = Double.toString(acceleration.getX());
    String varAafficherAccelY = Double.toString(acceleration.getY());
    labelVarAafficherAccelX.setText(varAafficherAccelX);
    labelVarAafficherAccelY.setText(varAafficherAccelY);
    System.out.printf("Acceleration field: %.2f, %.2f, %.2f ", acceleration.getX(), acceleration.getY(), acceleration.getZ());
});

Compass: The return value from the heading service is always 0.0 (whereas I had successfully tested this phone sensor with a freeware). 指南针:标题服务的返回值始终为0.0(而我已经使用免费软件成功测试了此手机传感器)。

Label labelGluonHeading = new Label();
Services.get(CompassService.class).ifPresent(service -> {
    double heading = service.getHeading(); // heading (cap): from 0 to 359.99
    System.out.println("**Heading:** " +heading);
    labelGluonHeading.setText("GLUON_Cap: " + Double.toString(heading));
});

In the build.gradle, the downconfig works fine because, when I add a service, it is loaded once before building the application 在build.gradle中,downconfig可以正常工作,因为当我添加服务时,在构建应用程序之前将其加载一次

The build.gradle: build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.2'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.gluonapplication.GluonApplication'

dependencies {
    compile 'com.gluonhq:charm:4.3.0'
}

jfxmobile {
     downConfig {
        version '3.2.0'
        plugins 'accelerometer', 'compass', 'device', 'orientation', 'storage', 'vibration', 'display', 'magnetometer', 'lifecycle', 'statusbar', 'position'
    }

    android {
        applicationPackage = 'com.gluonapplication'
        manifest = 'src/android/AndroidManifest.xml'
        androidSdk = 'C:/Users/pascal/AppData/Local/Android/sdk'
        resDirectory = 'src/android/res'
        compileSdkVersion = '23'
        buildToolsVersion = '25.0.1'
    }
    ios {
         infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

ABOUT THE ACCELEROMETER , the trace is: 关于加速计 ,跟踪为:

02-01 19:59:39.349 17994 18039 I System.out: Test accelero 2b

02-01 19:59:39.350 17994 18039 W System.err: Exception in Application start method

02-01 19:59:39.352   317 18045 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872736, size: 46080, flags: 0x00000000, timestamp: 1920000 us (1.92 secs))

02-01 19:59:39.352   317 18045 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072870816)

02-01 19:59:39.353   317 18045 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c313a0 (length 9600), timestamp 6720000 us (6.72 secs)

02-01 19:59:39.355 17994 18039 I System.out: QuantumRenderer: shutdown

02-01 19:59:39.356 17994 18034 W System.err: java.lang.reflect.InvocationTargetException

02-01 19:59:39.356 17994 18034 W System.err:    at java.lang.reflect.Method.invoke(Native Method)

02-01 19:59:39.356 17994 18034 W System.err:    at java.lang.reflect.Method.invoke(Method.java:372)

02-01 19:59:39.356 17994 18034 W System.err:    at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)

02-01 19:59:39.356 17994 18034 W System.err:    at java.lang.Thread.run(Thread.java:818)

02-01 19:59:39.356 17994 18034 W System.err: Caused by: java.lang.RuntimeException: Exception in Application start method

02-01 19:59:39.356 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)

02-01 19:59:39.356 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$138(LauncherImpl.java:182)

02-01 19:59:39.356 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$1(LauncherImpl.java)

02-01 19:59:39.356 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)

02-01 19:59:39.356 17994 18034 W System.err:    ... 1 more

02-01 19:59:39.356 17994 18034 W System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double com.gluonhq.charm.down.plugins.Acceleration.getX()' on a null object reference

02-01 19:59:39.356 17994 18037 D Surface : Surface::setBuffersDimensions(this=0xf49e5500,w=720,h=1152)

02-01 19:59:39.356   288   960 I BufferQueueProducer: [SurfaceView](this:0x7f72779000,id:231,api:1,p:17994,c:288) new GraphicBuffer needed

02-01 19:59:39.356   288   960 I [MALI][Gralloc]: Usage: 0xb00, format: 0x1 stride: 720 vertical_stride: 1152 size: 3317760

02-01 19:59:39.357   317 18045 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872832, size: 46080, flags: 0x00000000, timestamp: 2160000 us (2.16 secs))

02-01 19:59:39.357   288   960 D GraphicBuffer: alloc, handle(0x7f7277d7a0) (w:720 h:1152 s:720 f:0x1 u:0x000b00) err(0)

02-01 19:59:39.357   317 18045 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072870912)

02-01 19:59:39.357   317 18045 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c31400 (length 9600), timestamp 6960000 us (6.96 secs)

02-01 19:59:39.358 17994 18034 W System.err:    at com.gluonapplication.GluonApplication.lambda$start$0(GluonApplication.java:287)

02-01 19:59:39.358 17994 18034 W System.err:    at com.gluonapplication.GluonApplication$$Lambda$1.accept(Unknown Source)

02-01 19:59:39.358 17994 18034 W System.err:    at java.util.Optional.ifPresent(Optional.java:154)

02-01 19:59:39.358 17994 18034 W System.err:    at com.gluonapplication.GluonApplication.start(GluonApplication.java:282)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$145(LauncherImpl.java:863)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$8(LauncherImpl.java)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$158(PlatformImpl.java:326)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$6(PlatformImpl.java)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)

02-01 19:59:39.358 17994 18034 W System.err:    at java.security.AccessController.doPrivileged(AccessController.java:52)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$5(PlatformImpl.java)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$6.run(Unknown Source)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)

02-01 19:59:39.358 17994 18034 W System.err:    at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)

02-01 19:59:39.358 17994 18034 W System.err:    ... 1 more

02-01 19:59:39.358 17994 18037 D GraphicBuffer: register, handle(0xf00b17a0) (w:720 h:1152 s:720 f:0x1 u:0x000b00)

02-01 19:59:39.360   371   371 D QMCX983D: waitting for enable m or o sensor

02-01 19:59:39.360   371   371 D QMCX983D: QMC_IOCTL_GET_OPEN_STATUS failed

02-01 19:59:39.360   371   371 D QMCX983D: QMC_IOCTL_GET_DELAY failed

02-01 19:59:39.360   371   371 D QMCX983D: QMC_IOCTL_SET_YPR failed!

02-01 19:59:39.361   317 18045 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872928, size: 46080, flags: 0x00000000, timestamp: 2400000 us (2.40 secs))

02-01 19:59:39.361   317 18045 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072871008)

02-01 19:59:39.361   317 18045 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c31460 (length 9600), timestamp 7200000 us (7.20 secs)

02-01 19:59:39.365 17994 18037 D Surface : Surface::setBuffersDimensions(this=0xf49e5500,w=720,h=1152)

02-01 19:59:39.366   317 18045 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072873024, size: 46080, flags: 0x00000000, timestamp: 2640000 us (2.64 secs))

02-01 19:59:39.366   288   474 I BufferQueueProducer: [SurfaceView](this:0x7f72779000,id:231,api:1,p:17994,c:288) new GraphicBuffer needed

Note: the trace is the same with or with the "New Acceleration" Acceleration acceleration = new Acceleration(0, 0, 0, LocalDateTime.now()); 注意:跟踪与“ New Acceleration”相同或与之相同。Acceleration加速度= new Acceleration(0,0,0,LocalDateTime.now()); acceleration = service.getCurrentAcceleration(); 加速度= service.getCurrentAcceleration();


ABOUT THE HEADING SENSOR , the trace is: 关于航向传感器 ,跟踪为:

02-01 20:20:24.870 19093 19137 I System.out: **Deb test compass**

02-01 20:20:24.870   371   371 D QMCX983D: QMC_IOCTL_SET_YPR failed!

02-01 20:20:24.871   317   897 E AudioALSAPlaybackHandlerBase: openPcmDriver(), pcm_start(0xf2c7c7c0) fail due to cannot start channel: Broken pipe

02-01 20:20:24.871   317   897 D AudioALSAPlaybackHandlerBase: -openPcmDriver(), mPcm = 0xf2c7c7c0

02-01 20:20:24.871   317   897 D AudioALSAHardwareResourceManager: +startOutputDevice(), new_devices = 0x2, mStartOutputDevicesCount = 0 SampleRate = 44100

02-01 20:20:24.871   317   897 D AudioALSADriverUtility: GetPropertyValue key = af.resouce.extdac_support value = 0

02-01 20:20:24.871   317   897 D AudioALSADeviceConfigManager: GetDeviceDescriptorbyname

02-01 20:20:24.871   317   897 D AudioALSADeviceConfigManager: CheckDeviceExist exist devicename = headphone_output

02-01 20:20:24.871   317   897 D AudioALSADeviceConfigManager: ApplyDeviceTurnonSequenceByName() DeviceName = headphone_output descriptor->DeviceStatusCounte = 0

02-01 20:20:24.871   317   897 D AudioALSADeviceConfigManager: cltname = Audio_Amp_R_Switch cltvalue = On

02-01 20:20:24.872   317 19143 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872640, size: 46080, flags: 0x00000000, timestamp: 1680000 us (1.68 secs))

02-01 20:20:24.872   317 19143 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072870720)

02-01 20:20:24.873   317 19143 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c31340 (length 9600), timestamp 6480000 us (6.48 secs)

02-01 20:20:24.873   317   897 D AudioALSADeviceConfigManager: cltname = Audio_Amp_L_Switch cltvalue = On

02-01 20:20:24.873   317   897 D AudioALSADeviceConfigManager: GetDeviceDescriptorbyname

02-01 20:20:24.873   317   897 D AudioALSADeviceConfigManager: CheckDeviceExist exist devicename = ext_speaker_output

02-01 20:20:24.873   317   897 D AudioALSADeviceConfigManager: ApplyDeviceTurnonSequenceByName() DeviceName = ext_speaker_output descriptor->DeviceStatusCounte = 0

02-01 20:20:24.873   317   897 D AudioALSADeviceConfigManager: cltname = Ext_Speaker_Amp_Switch cltvalue = On

02-01 20:20:24.875   849  3163 D SensorService: Calling batch handle==1 flags=0rate=10000000 timeout== 0

02-01 20:20:24.875   849  3163 D SensorService: SensorDevice::batch: ident=0x7f61119cc0, handle=0x00000001, flags=0, period_ns=10000000 timeout=0

02-01 20:20:24.875   849  3163 D SensorService:     >>> curr_period=66667000 min_period=10000000 curr_timeout=0 min_timeout=0

02-01 20:20:24.875   849  3163 D SensorService: Calling activate on 1

02-01 20:20:24.875   849  3163 D SensorService: SensorDevice::activate: ident=0x7f61119cc0, handle=0x00000001, enabled=1, count=2

02-01 20:20:24.875   849  3163 D SensorService: enable index=0

02-01 20:20:24.875   849  3163 D SensorService:     >>> actuating h/w setDelay 1 10000000

02-01 20:20:24.875   849  3163 E Sensors : handleToDriver handle(0)

02-01 20:20:24.875   849  3163 D Accel   : setDelay: (handle=0, ns=10000000)

02-01 20:20:24.875   849  3163 D Accel   : no ACC setDelay control attr 


02-01 20:20:24.875   849  3163 E Sensors : new setDelay handle(0),ns(10000000)m, error(-1), index(2)

02-01 20:20:24.875   849  3163 E Sensors : new setDelay handle(0),ns(10000000) err! go to hwmsen

02-01 20:20:24.875   849  3163 D Hwmsen_sensors: setDelay: (handle=0, ns=10000000)

02-01 20:20:24.875   849  3163 D Hwmsen_sensors: setDelay: (what=0, ms=10)

02-01 20:20:24.875   849  3163 D Hwmsen_sensors: really setDelay: (what=0, ms=10)

02-01 20:20:24.875   849  1694 D SensorService: Calling batch handle==2 flags=0rate=100000000 timeout== 0

02-01 20:20:24.875   849  1694 D SensorService: SensorDevice::batch: ident=0x7f61119cc0, handle=0x00000002, flags=0, period_ns=100000000 timeout=0

02-01 20:20:24.875   849  1694 D SensorService:     >>> curr_period=-1 min_period=100000000 curr_timeout=-1 min_timeout=0

02-01 20:20:24.875   849  1694 D SensorService: Calling activate on 2

02-01 20:20:24.875   849  1694 D SensorService: SensorDevice::activate: ident=0x7f61119cc0, handle=0x00000002, enabled=1, count=1

02-01 20:20:24.875   849  1694 D SensorService: enable index=0

02-01 20:20:24.875   849  1694 D SensorService:     >>> actuating h/w activate handle=2 enabled=1

02-01 20:20:24.875   849  1694 D Sensors : activate handle =1, enable = 1

02-01 20:20:24.875   849  1694 E Sensors : handleToDriver handle(1)

02-01 20:20:24.875   849  1694 D Sensors : use new sensor index=3, mSensors[index](7089b000)

02-01 20:20:24.875   849  1694 D Magnetic: fwq enable: handle:1, en:1 


02-01 20:20:24.875   849  1694 D Magnetic: handle(1),path:magactive 


02-01 20:20:24.875   849  1694 D Magnetic: no magntic enable attr 


02-01 20:20:24.875   849  1694 D Sensors : use old sensor err(-1),index(3) go to old hwmsen

02-01 20:20:24.875   849  1694 D Hwmsen_sensors: Hwmsen_Enable: handle:1, en:1 


02-01 20:20:24.876   849  1694 D Hwmsen_sensors: virtual int Hwmsen::enable(int32_t, int): handle 1, enable or disable 1!

02-01 20:20:24.877   317 19143 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872736, size: 46080, flags: 0x00000000, timestamp: 1920000 us (1.92 secs))

02-01 20:20:24.877   317 19143 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072870816)

02-01 20:20:24.877   317 19143 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c313a0 (length 9600), timestamp 6720000 us (6.72 secs)

02-01 20:20:24.881   317 19143 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872832, size: 46080, flags: 0x00000000, timestamp: 2160000 us (2.16 secs))

02-01 20:20:24.881   317 19143 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072870912)

02-01 20:20:24.881   317 19143 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c31400 (length 9600), timestamp 6960000 us (6.96 secs)

02-01 20:20:24.882   849  1694 D Hwmsen_sensors: active_sensors =13


02-01 20:20:24.882   849  1694 D SensorService:     >>> actuating h/w setDelay 2 100000000

02-01 20:20:24.882   849  1694 E Sensors : handleToDriver handle(1)

02-01 20:20:24.882   849  1694 D Magnetic: no MAG setDelay control attr


02-01 20:20:24.882   849  1694 E Sensors : new setDelay handle(1),ns(100000000)m, error(-1), index(3)

02-01 20:20:24.882   849  1694 E Sensors : new setDelay handle(1),ns(100000000) err! go to hwmsen

02-01 20:20:24.882   849  1694 D Hwmsen_sensors: setDelay: (handle=1, ns=100000000)

02-01 20:20:24.882   849  1694 D Hwmsen_sensors: setDelay: (what=1, ms=100)

02-01 20:20:24.882   849  1694 D Hwmsen_sensors: really setDelay: (what=1, ms=100)

02-01 20:20:24.883 19093 19137 I System.out: **Heading: 0.0**

02-01 20:20:24.884 19093 19137 I System.out: Fin test compass

02-01 20:20:24.884 19093 19137 I System.out: Deb test orientation

02-01 20:20:24.885   317 19143 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072872928, size: 46080, flags: 0x00000000, timestamp: 2400000 us (2.40 secs))

02-01 20:20:24.885   317 19143 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072871008)

02-01 20:20:24.885   317 19143 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c31460 (length 9600), timestamp 7200000 us (7.20 secs)

02-01 20:20:24.889 19093 19137 I System.out: Fin test orientation

02-01 20:20:24.889 19093 19137 I System.out: Hello World! Debug avec adb - fin d'initialisation

02-01 20:20:24.889   317 19143 W OMXCodec: FILL_BUFFER_DONE(buffer: 4072873024, size: 46080, flags: 0x00000000, timestamp: 2640000 us (2.64 secs))

02-01 20:20:24.889   317 19143 W OMXCodec: EMPTY_BUFFER_DONE(buffer: 4072871104)

02-01 20:20:24.889   317 19143 D OMXCodec: [OMX.MTK.AUDIO.DECODER.MP3] Calling emptyBuffer on buffer 0xf2c314c0 (length 9600), timestamp 7440000 us (7.44 secs)

Given that both acceleration and heading change quickly over time, you should listen to changes in the properties AccelerometerService::accelerationProperty and CompassService::headingProperty , instead of getting a single value in a given instant (as it will be probably 0 or null) since the sensors might not be ready yet. 鉴于加速度和航向都随时间快速变化,因此您应该侦听AccelerometerService::accelerationPropertyCompassService::headingProperty属性的变化,而不是在给定的瞬间获得单个值(因为它可能为0或null),因为传感器可能尚未准备好。

This is how you can listen to heading variations: 这是您可以听取标题变化的方法:

Services.get(CompassService.class)
    .ifPresent(s -> s.headingProperty()
          .addListener((obs, ov, nv) -> 
               labelGluonHeading.setText(String.format("Heading: %.2f\u00b0", 
                     nv.doubleValue())))); 

And to the accelerometer sensor: 对于加速度传感器:

Services.get(AccelerometerService.class)
    .ifPresent(s -> s.accelerationProperty()
        .addListener((obs, ov, nv) -> 
            labelGluonAcceleration.setText(String.format("%.1f %.1f %.1f", 
                    nv.getX(), nv.getY(), nv.getZ())))); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM