Thursday, 28 October 2010

MapMyFitness JSON API Example




function loadMaps() {
var type = 2; //bike ride
var radius = 10;
$.ajax({
type: 'GET',
url: "http://api.mapmyfitness.com/3/routes/search_routes?&o=json&user_id=&user_key=&keyword=&min_latitude=51.08786&max_latitude=51.38786&min_longitude=-0.3013&max_longitude=-0.3013&center_longitude=51.38786&center_latitude=-0.3013&center_geocode=&radius=" + radius + "&route_type_id=" + type + "&city=&state=&country_code=&zip=&start_record=0&limit=25&sort_by=featured_flag%20desc,%20average_rating%20desc,%20route_name",
data: "id=" + "&lang=en-us&format=json&jsoncallback=?",
success: function(feed) {
// Create an empty array to store images
var thumbs = [];

// Loop through the items
for (var i = 0, l = feed.result.output.routes.length; i < l && i < 16; ++i) {
var routename = feed.result.output.routes[i].route_name;
// Add the new element to the array
thumbs.push(routename);
}

// Display the routes on the page
$('#feed').html(thumbs.join(''));

var show_user = tmpl("item_tmpl"), html = "";

for (var ii = 0; ii < feed.result.output.routes.length; ii++) {
html += show_user(feed.result.output.routes[ii]);
}
//var results = document.getElementById("results");
$('#vcalendar').html(html);
},
dataType: 'jsonp'
});
}

Flickr API - JQuery Javascript Example


function loadFlickr(flickrid) {
// Display a loading icon in our display element
$('#feed').html('');

// Request the JSON and process it
$.ajax({
type: 'GET',
url: "http://api.flickr.com/services/feeds/photos_public.gne",
data: "id=" + flickrid + "&lang=en-us&format=json&jsoncallback=?",
success: function(feed) {
// Create an empty array to store images
var thumbs = [];

// Loop through the items
for (var i = 0, l = feed.items.length; i < l && i < 16; ++i) {
// Manipulate the image to get thumb and medium sizes
var img = feed.items[i].media.m.replace(
/^(.*?)_m\.jpg$/,
''
);

// Add the new element to the array
thumbs.push(img);
}

// Display the thumbnails on the page
$('#feed').html(thumbs.join(''));

// A function to add a lightbox effect
addLB();
},
dataType: 'jsonp'
});
}

Wednesday, 13 October 2010

Basic Netduino HL1606 driver port.


Straight port of Arduino library to interface with RGB LED strips built with the HL1606 driver chip.

This hasnt even been tested yet, I just converted the code without even analysing it.

[EDIT] OK I've had a chance to look at the code and what its suppose to do. The HL1606 is basically 2* shift register and 2* LED driver. The code below is Bit Bashing it's way through, which is a pretty basic way of controlling, especially since there should be some hardware support which can do the job for us (e.g. SPI).

I'm going to have a go a writing a driver which is a bit more efficient than the below code. I'll keep you posted!



http://code.google.com/p/ledstrip/



using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

using System.IO;
using System.Text;

namespace NetduinoLEDSriptDriver
{
class HL1606Driver
{
enum BitOrder
{
LSBFirst,
MSBFirst
}

enum LEDState
{
OFF, // 0b00
ON, // 0b01
UP, // 0b10
DOWN, // 0b11

};

//#define _BV(bit) (1 << (bit)) //#include
//Converts a bit number into a byte value.
private const uint NONCMD = 0xFF;
private const uint LATCH = 0x07;
private const uint SPEED2X = 0x06;
private const bool LOW = false;
private const bool HIGH = true;

static OutputPort _dPin;
private OutputPort _sPin;
private OutputPort _latchPin;
private OutputPort _clkPin;

private bool _faderEnabled;
private uint _faderPulseNextEdge;

//System Function
protected void digitalWrite(OutputPort port, bool state)
{
port.Write(state);
}

protected bool digitalRead(OutputPort port)
{
return port.Read();
}

//public void pinMode(uint port, uint state)
//{

//}

public HL1606Driver(Cpu.Pin dPin, Cpu.Pin sPin, Cpu.Pin latchPin, Cpu.Pin clkPin)
{

//Setup Ports
try
{
_dPin = new OutputPort(dPin, false);
_sPin = new OutputPort(sPin, false); ;
_latchPin = new OutputPort(latchPin, false);
_clkPin = new OutputPort(clkPin, false);

}
catch (Exception)
{

throw;
}

_faderEnabled = false;

//Setup Port Inital States
wakeup();

}

void wakeup()
{
digitalWrite(_dPin, LOW);
digitalWrite(_sPin, LOW);
digitalWrite(_latchPin, LOW);
digitalWrite(_clkPin, LOW);
}


void faderCrank()
{
short mymillis;

if (!_faderEnabled) return;
SystemTime t = new SystemTime();

mymillis = t.Milliseconds;

// Give us 250ms slop in case we don't exactly catch our edge.
if (mymillis >= _faderPulseNextEdge && mymillis < _faderpulsehalfwidth =" _faderPulseNewHalfWidth;" _faderpulsenextedge =" (uint)mymillis" myvar =" value;" myvar ="=" _faderenabled =" false;" _faderpulsehalfwidth =" 0;" _faderpulsenewhalfwidth =" 0;" _faderpulsenewhalfwidth =" myVar;" _faderenabled =" true;" _faderpulsehalfwidth =" myVar;" t =" new" _faderpulsenextedge =" (uint)t.Milliseconds" value ="=" _faderenabled =" false;" _faderpulsehalfwidth =" 0;" _faderpulsenewhalfwidth =" 0;" _faderpulsenewhalfwidth =" value;" _faderenabled =" true;" _faderpulsehalfwidth =" value;" t =" new" _faderpulsenextedge =" (uint)t.Milliseconds" cmd =" 0;" flags =" LATCH;">= NONCMD || bluecmd >= NONCMD || greencmd >= NONCMD) return;

cmd |= (greencmd << cmd =" 0;" flags =" LATCH">= NONCMD || bluecmd >= NONCMD || greencmd >= NONCMD) return;

cmd |= (greencmd << i =" 0;" _bitorder ="=" mask =" (byte)(1" mask =" (byte)(1" ms =" (int)delay">

Monday, 11 October 2010

Training Peaks Webservice

<script language='javascript'>
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script>



Dim sUserName As String = "username"
Dim sPassword As String = "password"
Dim nUserId As Integer = 115133
Dim bData() As Byte

Dim ws As trainingpeaksWS.Service = New trainingpeaksWS.Service()
Dim p() As trainingpeaksWS.PersonBase = ws.GetAccessibleAthletes("username", "password", trainingpeaksWS.AthleteAccountTypes.SharedSelfCoachedPremium)


Dim v As String = ws.Version()

Dim dt As DateTime = DateTime.Now()
dt = dt.AddDays(-30)

Dim v3 As Object = ws.GetWorkoutsForAthlete("username", "password", dt, DateTime.Now)
Dim v2 As Object = ws.GetWorkoutsForAccessibleAthlete("username", "password", nUserId, dt, DateTime.Now)
Dim v4 As Object = ws.GetExtendedWorkoutDataForAccessibleAthlete("username", "password", nUserId, 40760637)

Dim workout As trainingpeaksWS.Workout = New trainingpeaksWS.Workout()


ws.ImportFileForUser(sUserName, sPassword, bData)