Example Program

Here is a code example we created to test the JwiK™ runtime:

class RFM50Test
{
    public final static int ON       = 0;
    public final static int OFF      = 1;
    
    public LedManager ledManager = new LedManager();
    public byte[] arrayOfByte;

    public void main(String[] args) 
    {
        //int pn = RFM50.GetPartNumber();
        arrayOfByte = new byte[256];
        for(int i=0;i<256;i++)
            arrayOfByte[i] = (byte)i;
        RFM50.ProcessBytes(arrayOfByte);
        while(true)
        {
            ledManager.LedOn(RFM50.LED1);
            RFM50.Led(RFM50.LED2,OFF);
            RFM50.Wait(1000);
            RFM50.Led(RFM50.LED1,OFF);
            RFM50.Led(RFM50.LED2,OFF);
            RFM50.Wait(1000);
            
            // put the processor to sleep
            RFM50.SetPowerMode(RFM50.SLEEP);
            
            // when we get here, the processor has woken up because of an even
            //int result = RFM50.GetWakeUpReason();
            
            //switch(result)
            //{
                //case RFM50.WAKEONWATCHDOG:
                //RFM50.Led(RFM50.LED2,OFF);
                //break;
            //}
        }
    }
}
public class RFM50
{
    public final static int LED1 = 0;
    public final static int LED2 = 1;
      
    public final static int SI1000 = 0xD1;
    public final static int SI1001 = 0xD2;
    
    public final static int NORMAL = 0;
    public final static int IDLE = 1;
    public final static int STOP = 2;
    public final static int SUSPEND = 3;
    public final static int SLEEP = 4;
    
    public final static int PRECINT = 0;
    public final static int LPINT = 1;
    public final static int EXT = 2;
    public final static int RTC = 3;
    
    public final static int CMOS = 0;
    public final static int CMOSDIV2 = 1;
    public final static int RC = 2;
    public final static int CAPOSC = 3;
    public final static int XTOSC = 4;
    public final static int XTOSCDIV2 = 5;
    
    public final static int WAKEONINTERRUPT = 0;
    public final static int WAKEONWATCHDOG = 1;
    
    public static native void Led(int ledNo, int state);
    public static native void Wait(int mSec);
    public static native void ProcessBytes(byte[] bytesToProcess);
    
    public static native int GetPartNumber();
    
    public static native void SetPowerMode(int mode);
    public static native int GetWakeUpReason();
    public static native void DisableOscBias();
    public static native void EnableOscBias();
    public static native void SetClockDivisor(int div);
    public static native void EnableClockSS();
    public static native void SetExtOscMode(int mode);
    public static native void SetExtOscBias(int bias);
    
}
class LedManager
{
    public void LedOn(int ledNo)
    {
        RFM50.Led(ledNo,0);
    }
}


In this example, RFM50Test is the main class because it defines a Main() method. It encapsulates two additional classes: RFM50 and LedManager.

RFM50 is an example of a native class to access hardware or software drivers written in C. It defines a series of hardware specific constants which become members of the class as well as a number of static native method definitions that reference the C functions in the driver.

LedManager is an example of a driver implemented as an actual Java class.

NOTE: This example flashes a couple of LEDs in the most innefficient way possible. It is not intended to be a true example of how to write JwiK™ applications as much as it is an example of what JwiK™ can do.

Last edited Jul 20, 2012 at 4:34 AM by stevetherfguy, version 3

Comments

No comments yet.