Resources - BattClock

Report errors, omissions, etc. regarding the AmigaOS Documentation Wiki here.

Resources - BattClock

Postby dstastny » Tue Dec 05, 2017 4:22 pm

So I'm reading on resources and not sure what else is missing from this page that it marked work in progress other than example. Informational all matches autodocs and headers. So here is updated example

http://wiki.amigaos.net/wiki/BattClock_Resource

Code: Select all

#include <exec/types.h>
#include <dos/dos.h>
#include <utility/date.h>
#include <resources/battclock.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/battclock.h>
#include <proto/utility.h>



int main()
{
    CONST CONST_STRPTR Days[] ={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
    CONST CONST_STRPTR Months[] = {"January","February","March","April","May","June",
                   "July","August","September","October","November","December"};
    STRPTR ampm;
    uint32 AmigaTime;
    struct ClockData MyClock;
   

    struct Library *BattClockBase = IExec->OpenResource(BATTCLOCKNAME);
    struct BattClockIFace *IBattClock = (struct BattClockIFace *)IExec->GetInterface(BattClockBase, "main", 1, NULL);
    if (IBattClock != NULL) {
        /* Get number of seconds till now */
        AmigaTime = IBattClock->ReadBattClock();
        /* Convert to a ClockData structure */
        IUtility->Amiga2Date(AmigaTime,&MyClock);
        IDOS->Printf("\nRobin, tell everyone the BatDate and BatTime");
        /* Print the Date */
        IDOS->Printf("\n\nOkay Batman, the BatDate is ");
        IDOS->Printf("%s, %s %ld, %ld",Days[MyClock.wday],Months[MyClock.month-1], MyClock.mday,MyClock.year);
        /* Convert military time to normal time and set AM/PM */
        if (MyClock.hour < 12) {
            ampm = "AM";        /* hour less than 12, must be morning */
        }
        else {
            ampm = "PM";         /* hour greater than 12,must be night */
            MyClock.hour -= 12;  /* subtract the extra 12 of military */
        };

        if (MyClock.hour == 0) {
                MyClock.hour = 12;   /* don't forget the 12s */
        }
        /* Print the time */
        IDOS->Printf("\n             the BatTime is ");
        IDOS->Printf("%02ld:%02ld:%02ld %s\n\n", MyClock.hour, MyClock.min, MyClock.sec, ampm);
        IExec->DropInterface((struct Interface*)IBattClock);
    }
    else
       IDOS->Printf("Error: Unable to open the %s\n",BATTCLOCKNAME);
    return 0;
}


Doug
dstastny
 
Posts: 32
Joined: Fri Dec 16, 2016 7:31 am
Location: Atlanta GA

Re: Resources - BattClock

Postby trixie » Wed Dec 06, 2017 2:05 pm

@dstastny

Wiki page updated.
Smoke me a kipper, I'll be back for breakfast!
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
User avatar
trixie
 
Posts: 357
Joined: Thu Jun 30, 2011 3:54 pm
Location: Czech Republic


Return to AmigaOS Documentation Wiki

Who is online

Users browsing this forum: No registered users and 1 guest