At 09:48 AM 3/31/99 -0600, you wrote:
>Does anybody have any source code they can share to display the battery
>level graphically? Like in the "App" menu header area?
>
>TIA,
>Denny
>
>**********
>Denny W. Jones
>Lighthouse Technologies
>http://www.lhtech-inc.com
>**********
>

Denny,

Here is the code I use to display the battery level on my Symbol SPT-1500
(Palm III) Don't forget to define a gadget on your form...

-jeff






/***********************************************************************
 *
 * FUNCTION:            displayBatteryLevel
 *
 * DESCRIPTION:         Draws the Battery object, depending on the percentage
 *
 * PARAMETERS:          FormPtr.
 *
 * RETURNED:            Nothing.
 *
 ***********************************************************************/
static void displayBatteryLevel( void )
{
        RectangleType   r;
        RectangleType   gaugeMainR;
        RectangleType   gaugeEndR;
        Word            frameEndWidth;
        Word            frameEndHeight;
        Word            batteryGaugeWidth;
        Word            batteryPowerWidth;
        Word            batteryGaugeMainWidth;
        Word            batteryGaugeEndWidth;   
        Short           x1, x2, y1, y2;
        Byte            batteryPercent;
        Word                    currForm;

        gFrm = FrmGetActiveForm();
        currForm = FrmGetActiveFormID();

   // Now fill in how much of the battery is left
   SysBatteryInfo(false, 0, 0, 0, 0, 0, &batteryPercent);

   // Save new battery percent
        gLastKnownBatteryPercent = batteryPercent;

        switch( currForm ) {
        case MainMenuForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm,
MainMenuBatteryGadget), &r);
                break;
        case TransactionForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm,
TransactionBatteryGadget), &r);
                break;
        case LoginForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm, 
LoginBatteryGadget), &r);
                break;
        case ManualEntryForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm,
ManualEntryBatteryGadget), &r);
                break;
        case NotesForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm, 
NotesBatteryGadget), &r);
                break;
        case EditNoteForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm,
EditNoteBatteryGadget), &r);
                break;
        case BatteryForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm, 
BatteryBatteryGadget),
&r);
                break;
        case SystemForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm, 
SystemBatteryGadget),
&r);
                break;
        case SymbologyForm:
                FrmGetObjectBounds (gFrm, FrmGetObjectIndex (gFrm,
SymbologyBatteryGadget), &r);
                break;
        default:
                return;
        }

   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