I recieved some code a while back on how to do this but after modifying it to
run on the palm pro (the sysBatteryInfo call is different) I get the
percentage but the guage is no longer correct. I am assuming that the new call
for Palm 3 must return something other that battery volts (mine is based a a 3
volt battery which I also need a better way of doing this too). Can somebody
help?
Thanks,
Daniel
See code below...

static void DisplayBatteryLevel (FormPtr formP)
{
   RectangleType  r;
   RectangleType  gaugeMainR;
   RectangleType  gaugeEndR;
   Word           frameEndWidth;
   Word           frameEndHeight;
   Word           batteryGaugeWidth;
   Word           batteryPowerWidth;
   Word           batteryGaugeMainWidth;
   Word           batteryGaugeEndWidth;   
   Short          x1, x2, y1, y2;
   
   // Now fill in how much of the battery is left
        batteryPercent = (100 * SysBatteryInfo(false, 0, 0, 0, 0, 0)) / 300;

   // Get the bounds of the battery gadget.
   formP = FrmGetActiveForm();
   FrmGetObjectBounds (formP, FrmGetObjectIndex (formP,
PatientInformationBatteryTestGadget), &r);

   frameEndHeight = r.extent.y / 4;
   frameEndWidth = frameEndHeight;
   batteryGaugeWidth = r.extent.x - frameEndWidth - 3;

   // Draw the frame of the battery gadget.
   x1 = r.topLeft.x;
   y1 = r.topLeft.y;
   x2 = x1 + r.extent.x - frameEndWidth - 2;
   y2 = y1 + r.extent.y - 1;
   WinDrawLine (x1, y1, x1, y2);                   // left side
   WinDrawLine (x1, y1, x2, y1);                   // top side
   WinDrawLine (x1, y2, x2, y2);                   // bottom side
   WinDrawLine (x2, y1, x2, y1 + frameEndHeight);
   WinDrawLine (x2, y2, x2, y2 - frameEndHeight);
   WinDrawLine (x2, y1 + frameEndHeight, x2 + frameEndWidth, y1 +
frameEndHeight); 
   WinDrawLine (x2, y2 - frameEndHeight, x2 + frameEndWidth, y2 -
frameEndHeight);
   WinDrawLine (x2 + frameEndWidth, y1 + frameEndHeight, x2 + frameEndWidth,
y2 - frameEndHeight);

   batteryGaugeWidth = r.extent.x - 2;
   batteryPowerWidth = (batteryPercent * batteryGaugeWidth + 50) / 100;

   batteryGaugeMainWidth = r.extent.x - frameEndWidth - 3;
   batteryGaugeEndWidth = batteryGaugeWidth - batteryGaugeMainWidth;
   
   // Draw the power indicator.
   gaugeMainR.topLeft.x = r.topLeft.x + 1;
   gaugeMainR.topLeft.y = r.topLeft.y + 1;
   gaugeMainR.extent.x = batteryGaugeMainWidth;
   gaugeMainR.extent.y = r.extent.y - 2;
   
   gaugeEndR.topLeft.x = r.topLeft.x + batteryGaugeMainWidth + 1;
   gaugeEndR.topLeft.y = r.topLeft.y + frameEndHeight + 1;
   gaugeEndR.extent.x = batteryGaugeEndWidth - 1;
   gaugeEndR.extent.y = r.extent.y - (frameEndHeight * 2) - 2;

   if (batteryPowerWidth < batteryGaugeMainWidth)
      gaugeMainR.extent.x = batteryPowerWidth;
   WinDrawRectangle (&gaugeMainR, 0);

   if (batteryPowerWidth < batteryGaugeMainWidth)
      {
      // And clear the battery which is used up
      gaugeMainR.topLeft.x += gaugeMainR.extent.x;
      gaugeMainR.extent.x = batteryGaugeMainWidth - gaugeMainR.extent.x;
      WinEraseRectangle (&gaugeMainR, 0);
      }

   if (batteryPowerWidth > batteryGaugeMainWidth)
      {
      gaugeEndR.extent.x = batteryPowerWidth - batteryGaugeMainWidth;
      WinDrawRectangle (&gaugeEndR, 0);

      gaugeEndR.topLeft.x += gaugeEndR.extent.x;
      gaugeEndR.extent.x = batteryGaugeEndWidth - gaugeEndR.extent.x;
      }

   WinEraseRectangle (&gaugeEndR, 0);
}

Reply via email to