Monday 31 January 2011

Well, it has come to an end...

and I have failed miserably. Unfortunately work and scouting got in the way.

What I did achieve:
- Playing with and getting to know the HP-200LX
- Installing Turbo Pascal on said device
- Creating and running at least a simple program

What I did not achieve:
- Regular blog posts
- being able to save/retrieve data to/from a file, and so keep a history of fuel usage
- using the historic data to create e.g. a bar graph to show comparisons over several data points.


I did enjoy what little time I did get to spend on the project. Thank you urbancamo for hosting!

Now I have 5 months to think of the next project. 'Till July then :)

Saturday 15 January 2011

urbancamo is right....

I have been far too quiet, I'll have to change that.

Thus far, I have done the basics: fuel and distance can be input and fuel usage figures are out (in miles per gallon (UK and US), kilometers per litre and litres per 100 kilometers. And an unusual one: miles per litre - because in the UK fuel is sold by the Litre and vehicles record distance in Miles).

So, some photo's:

The 200LX:

The TP IDE:


editing the program:



Output sample:




Source code is available below for those wanting to play with it.

I wanted to be here a week ago! My next step is to be able to add multiple data points with date info. This will mean creating file I/O to save and recall data. This will enable one to keep historic data of fuel usage - probably usefull to do it even for different vehicles.

Halfway the month already so better get to it...


Source code thus far:

Program FuelCalc;


Uses Crt;


Var
Dt,    {Distance}
Fl,    {Fuel}
MPGUK, {miles per UK gallon}
MPGUS, {miles per US gallon}
KmPL,  {kilometers per litre}
LPHKm, {litres per hundred km}
MPLT:  real;  {miles per litre}
DU,    {Distance Units}
FU: char;  {Fuel Units}
Wt: char;



Procedure GetValues(var Dist, Fuel: real; var DistU, FuelU: char);
  Begin
    While (DistU <> 'K') AND (DistU <> 'k') AND (DistU <> 'M') AND (DistU <> 'm') do
      begin
        WriteLn('Do you wish to enter distance in Kilometers (K) or Miles (M)?');
        Write('Please enter K or M: ');
        ReadLn(DistU);
      end;
    WriteLn;
    While (Dist < 1) OR (Dist > 1E6) do
      begin
        Write('Please enter distance: ');
        ReadLn(Dist);
      end;
    WriteLn;
    While (FuelU <> 'A') AND (FuelU <> 'a') AND (FuelU <> 'B') AND (FuelU <> 'b') AND (FuelU <> 'C') AND (FuelU <> 'c') do
      begin
        WriteLn('Do you wish to enter fuel in (a)Litres, (b)UK Gallons or (c)US Gallons?');
        Write('Please enter a, b or c: ');
        ReadLn(FuelU);
      end;
    WriteLn;
    While (Fuel < 1) OR (Fuel > 1E6) do
      begin
        Write('Please enter fuel used: ');
        Read(Fuel);
      end;
    WriteLn;
  End;



Procedure CalcValues(Dist, Fuel: real; DistU, FuelU: char; var mpgk, mpgs, kpl, lphk, mpl: real);
  Var
    M,    {miles}
    L,    {litres}
    Km,   {kilometers}
    Guk,  {UK gallons}
    Gus: real;  {US gallons}

  Begin
    case DistU of
    'K', 'k':
    Begin
      Km := Dist;
      M := Dist / 1.6093;
    End;
    'M', 'm':
    Begin
      M := Dist;
      Km := Dist * 1.6093;
    End;
    End;

    case FuelU of
      'A', 'a': begin
                  L := Fuel;
                  Guk := Fuel / 4.5461;
                  Gus := Fuel / 3.7854;
                end;
      'B', 'b': begin
                  L := Fuel * 4.5461;
                  Guk := Fuel;
                  Gus := Fuel * 4.5461/3.7854;
                end;
      'C', 'c': begin
                  L := Fuel * 3.7854;
                  Guk := Fuel * 3.7854/4.5461;
                  Gus := Fuel;
                end;
    end;

    mpgk := M / Guk;
    mpgs := M / Gus;
    lphk := L / (Km / 100);
    kpl := Km / L;
    mpl := M / L;

  End;


Procedure Output(mpgk, mpgs, kpl, lphk, mpl: real);
  Begin
    WriteLn('The Fuel Consumption is:');
    WriteLn;
    WriteLn('Miles per Gallon(UK) = ',mpgk:6:2);
    WriteLn('Miles per Gallon(US) = ',mpgs:6:2);
    WriteLn('Km per Litre = ',kpl:6:2);
    WriteLn('Litres per 100 Km = ',lphk:6:2);
    WriteLn('Miles per Litre = ',mpl:6:2);
    WriteLn;
  End;



Begin {main}
  Dt := 0;
  Fl := 0;
  MPGUK := 0;
  MPGUS := 0;
  KmPL := 0;
  LPHKm := 0;
  MPLT := 0;
  DU := ' ';
  FU := ' ';

  ClrScr;
  GetValues(Dt, Fl, DU, FU);
  CalcValues(Dt, Fl, DU, FU, MPGUK, MPGUS, KmPL, LPHKm, MPLT);
  Output(MPGUK, MPGUS, KmPL, LPHKm, MPLT);
  WriteLn('Press ENTER to exit... ');
  ReadLn(Wt);
End.

Friday 7 January 2011

And i'm on...

... and got side-tracked for 2 evenings searching for a misplaced passport (found!). Finally got to do some coding last night. Realised now why I got a serial card and a mouse so soon after acquiring my XT back then, navigating with cursors is a pain! Hope to post more detail this weekend.

Oh, and for those familiar with TP 5.5, I'm only using the 5 part, not the .5 (OOP) part, although oopses will surely abound :).

Monday 3 January 2011

OK, sooo, what is Retro Challenge? See here.

This will be my first attempt at RC, so we'll see what it brings. I intend to write a fuel consumption calculating program on an HP-200LX using Borland Turbo Pascal 5.5 which I purchased as a student around 1990. I found the manuals and disks in a box during a recent move and managed to install it on the 200LX. The 200LX has an Intel 80186 CPU and the operating system is MS-DOS 5.

So, now on to see if they'll accept my entry ....