Resources - BattClock

Report errors, omissions, etc. regarding the AmigaOS Documentation Wiki here.
Post Reply
dstastny
Posts: 48
Joined: Fri Dec 16, 2016 6:31 am
Location: Atlanta GA

Resources - BattClock

Post by dstastny »

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
User avatar
trixie
Posts: 409
Joined: Thu Jun 30, 2011 2:54 pm
Location: Czech Republic

Re: Resources - BattClock

Post by trixie »

@dstastny

Wiki page updated.
The Rear Window blog

AmigaOne X5000 @ 2GHz / 4GB RAM / Radeon RX 560 / ESI Juli@ / AmigaOS 4.1 Final Edition
SAM440ep-flex @ 667MHz / 1GB RAM / Radeon 9250 / AmigaOS 4.1 Final Edition
Post Reply