Not new to programming, but new to Monkey C here, so I thought I'd have a go at making a basic widget.
I'm trying to get the current speed to show, but as far as I can see, computer(info) just isn't being called - I put a println statement to check, but nothing is outputted.
Here is my current code. So far it has a battery indicator for the top left, temperature in the top right, and I'm trying to get speed to display in a circle in the middle.
using Toybox.WatchUi;
using Toybox.Activity;
using Toybox.System;
using Toybox.Graphics;
using Toybox.Sensor;
using Toybox.Application;
class GarminProj1View extends WatchUi.View {
var _temperature;
var _greenBattery;
var _speed;
function initialize() {
View.initialize();
_greenBattery = new Rez.Drawables.greenBattery();
_speed = 0;
_temperature = 0;
}
// Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.MainLayout(dc));
}
// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() {
}
// Update the view
function onUpdate(dc) {
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
Sensor.setEnabledSensors( [Sensor.SENSOR_TEMPERATURE] );
Sensor.enableSensorEvents( method(:onSnsr) );
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_WHITE);
dc.clear();
dc.setColor(Graphics.COLOR_TRANSPARENT, Graphics.COLOR_BLACK);
var stats = System.getSystemStats();
var pwr = stats.battery;
var batStr = Lang.format( "$1$%", [ pwr.format( "%2d" ) ] );
_greenBattery.draw(dc);
dc.drawText(12, 2, Graphics.FONT_TINY, batStr, Graphics.TEXT_JUSTIFY_LEFT);
dc.drawText(197, 2, Graphics.FONT_TINY, _temperature, Graphics.TEXT_JUSTIFY_RIGHT);
dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_BLACK);
dc.drawCircle(100, 60, 50);
dc.setColor(Graphics.COLOR_BLACK,Graphics.COLOR_TRANSPARENT);
dc.drawText(100, 40, Graphics.FONT_NUMBER_HOT, _speed, Graphics.TEXT_JUSTIFY_CENTER);
}
// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
function onHide() {
}
function onSnsr(sensor_info)
{
var temp = sensor_info.temperature;
if( sensor_info.temperature != null )
{
_temperature = temp.toLong() + "C";
}
else
{
_temperature = "";
}
WatchUi.requestUpdate();
}
function compute(info)
{
System.println("Test");
var spd = info.currentSpeed;
//Get speed if valid
if( spd != null )
{
_speed = spd;
}
}
}
Any idea what I'm doing wrong?