Smartwatch, Compass value does not change

Hello,
I’ve written a little smartwatch watchface (with the Ketai Libary), and the compass value isn’t changing. I tried it with getting the Sensor manually, but then it said me, The field Sensor.TYPE_ORIENTATION is deprecated..
So i searched and found this (Android Developers) .
There stands the new thing for accessing the orientation is this (SensorManager.getOrientation())
But it expects parameters, from where should I get them?

OS: Windows 10
Mobile: Galaxy S7 edge Android 9
Watch: Fossil Sport

Code (Ketai Libary)
void setup() {
  fullScreen();
  //size(390, 390);
  frameRate(60);
  smooth(2);
  
  sensor = new KetaiSensor(this);
}

void draw() {
  background(0);
  displayCompass();
}

void displayCompass() {
  stroke(204, 0, 0);
  noFill();
  strokeWeight(width*0.08);
  strokeCap(SQUARE);
  ellipseMode(CENTER);
  
  println(compass);
  arc(0, 0, (width-width*0.56), (width-width*0.56), radians(-5 + compass), radians(5 + compass), OPEN);
}

void onOrientationEvent(float x, float y, float z, long time, int accuracy) {
  compass = x;
}

Thanks.

@Lightosk ===

  • I am supposing that you get only the warning “deprecated” and that your code compile without any error.
  • “Deprecated” does not mean that a field will not work, only that there is a better one now.
  • Sensor.Type_ORIENTATION works with Android MM and Nougat (tested) and you can forget the warning (“deprecated”)
  • Yet if you want to use getOrientation() you have to create two sensors, accelerometer && magneticField (the same way that for the “deprecated” one!) wich will return 3 values (X,Y,Z) that you store in arrays; then you have to call getRotationMatrix()with parameters (arrayR=float[9], null, yourArray1, values, your array2 values; finally create another array arrayOr=float[3] and call getOrientation(arrayR, arrayOr): it will return the values you are looking for but in radians.
  • Now if you want to use this way i am quite sure that you have to leave Ketai for android direct coding…
1 Like

Well, I’ve done the coding with acceleration and magnet field with no result. Whyever it didn’t work either on the mobile as on the watch, but with the deprecated orientation it worked on mobile, but not on the watch. It works on mobile with a wallpaper, too, so it can’t depend on the difference with getActivity() and getContext(). But I know the watch has got a compass, because another app from the Play Store works (here).

I found another thing. When I install the sketch on the watch as an app and not as a watchface, it works! It seems like you can’t access all sensors as a watchface, whyever.