Hi, Really hoping someone can help me this, just created a simple little widget to show the temperature and an adjusted value, It works fine in the simulator but on the Fenix 5X it doesn't get the value back from the internal sensor, I've no idea why. I created a similar widget that reads the most recent temperature from the history and that works fine, pulling my hair out. Using Eclipse and SDK 3.0.1 - would anyone have any ideas for me please?
The code:
usingToybox.WatchUi;
usingToybox.Sensor;
usingToybox.System;
classTemperatureView extendsWatchUi.View {
varSensorTemp = 999;
functioninitialize() {
View.initialize();
Sensor.setEnabledSensors( [Sensor.SENSOR_TEMPERATURE] );
Sensor.enableSensorEvents( method(:onSnsr) );
}
// Load your resources here
functiononLayout(dc) {
setLayout(Rez.Layouts.MainLayout(dc));
// Call the parent onUpdate function to redraw the layout
view.onUpdate(dc);
}
// Update the view
functiononUpdate(dc) {
varTempFormat = "$1$";
varSensorFormat = "Sensor Reads $1$";
varTempString = "Not Available";
varSensorString = "Not Available";
varTempview = View.findDrawableById("TempLabel");
varSensorview = View.findDrawableById("SensorLabel");
// we got sensor data
if(SensorTemp != 999) {
// we got temperature
varTempInt = SensorTemp;
varSensorInt = SensorTemp;
SensorString = Lang.format(SensorFormat, [SensorInt.format("%.1f")]);
TempInt = TempInt - 10;
TempString = Lang.format(TempFormat, [TempInt.format("%.1f")]);
}
Tempview.setText(TempString);
Sensorview.setText(SensorString);
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
}
functiononSnsr(sensor_info)
{
varTM = sensor_info.temperature;
if( TM != null)
{
SensorTemp = TM;
}
else
{
SensorTemp = 999;
}
WatchUi.requestUpdate();
}
// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
functiononHide() {
}
}
Many Thanks,
Ralph.