Device Functions

Here we will cover a few functions available within your code, these functions

Function

Description

Zen

Plus

Returns the elapsed time between main iterations in milliseconds

✔️

✔️

Returns the active slot number

✔️

✔️

Loads a specified slot

✔️

✔️

Returns the identifier of the controller button

✔️

✔️

Sets the vm timeout for the next iteration

✔️

✔️

Sets the stick output at a given angle and radius with a high resolution value

✔️

Sets the LED on the ZEN to the supplied RGB color

✔️

Sets the LED on the ZEN to the supplied HSB color

✔️

The clamp() function clamps a value between an upper and lower bound. clamp() enables selecting a middle value within a range of values between a defined minimum and maximum. It takes three parameters: a minimum value, a preferred value, and a maximum allowed value.

✔️

get_rtime

get_rtimereturns the elapsed time between the current and previous iteration of the main function. The value returned is in milliseconds.

You can see this function in action by using this counter script:

int days;
int hours;
int minutes;
int seconds;
int milliseconds;
main {
    milliseconds = milliseconds + get_rtime();
    if(milliseconds >= 1000) {
        milliseconds = milliseconds - 1000
        seconds = seconds + 1;
        if(seconds == 60) {
            seconds = 0;
            minutes = minutes + 1;
            if(minutes == 60) {
                minutes = 0;
                hours = hours + 1;
                if(hours == 24) {
                    hours = 0;
                    days = days + 1;
                }
            }
        }
    }
    set_val(TRACE_1, days);
    set_val(TRACE_2, hours);
    set_val(TRACE_3, minutes);
    set_val(TRACE_4, seconds);
    set_val(TRACE_5, milliseconds / 10);
}

🔴 Syntax

get_rtime ( );

Parameters

None

🔵 Returns

The elapsed time, in milliseconds, between the main iteration

Main Section

get_slot

get_slot returns an int value representing the current active slot of the Cronus Device.

int _currentSlot;
 
init {
     _currentSlot = get_slot();
 }
 
main {
 
}

🔴 Syntax

getslot();

Parameters

None

🔵 Returns

An int value representing the current active slot of the Cronus Device.

load_slot

load_slot will attempt to load the slot number specified within its parameter. If there is no script current stored in the specified slot, then it will unload the current slot and load slot 0 of the device.

main {
 
    if(event_press(XB1_RB))     // if RB / R2 is pressed...
        load_slot(5);           // Load slot 5
   
    if(event_press(XB1_LB))     // if LB / L2 is pressed...
        load_slot(0);           // Unload current slot and load slot 0
 
}

🔴 Syntax

load_slot ( <slot_number> );

Parameters

<slot_number> : A value which represents a slot number to load with a range of 0 - 9 on Cronus MAX Plus or 0 - 8 on Cronus ZEN.

🔵 Returns

Nothing

get_ctrlbutton

get_ctrlbutton returns the current control button. The control button is set in the Device tab within Cronus PRO's Options window or the Device Tab of the Cronus Zen. The enable remote control switch on device dictates which button it is set to

{{IMAGE PLACEHOLDER}}

get_ctrlbutton();

🔴 Syntax

get_ctrlbutton( );

Parameters

Nothing

🔵 Returns

Depending on the remote slot settings the value can be 0, 1 or 8.

vm_tctrl

Sets the virtual machine timeout for the next iteration. By default, the virtual machine runs the main loop every 10 milliseconds as it aids stability. You can however adjust how often each main iteration is run. Just be aware than changing this setting may cause instability within your script.

main {
 
    vm_tctrl(-5); // Run the VM every 5ms
 
}

🔴 Syntax

vm_tctrl( <variable> );

Parameters

<variable> : Numeric value to add to the Virtual Machine base time. Range -9 ~ 10

🔵 Returns

Nothing

set_polar

Sets the stick output at a given angle and radius with a high resolution value

set_polar(POLAR_LS,250, 32000);

🔴 Syntax¹ ² ³

set_polar(stick,angle,radius);

Parameters

stick: defined stick (POLAR_LS or POLAR_RS).

angle: index point of the bit to be set with a range of 0 to 359.

radius: index point of the bit to be set with a range of -32768 to 32767.

🔵 Returns

Nothing

set_rgb

Sets the LED on the ZEN to the supplied RGB color (Red,Green,Blue).

set_rgb(255,0,0) // red
set_rgb(0,255,0)// green
set_rgb(0,0,255) // blue

🔴 Syntax¹ ² ³

set_rgb(red,green,blue);

Parameters

  1. red: index point of the bit to be set with a range of 0 - 255

  2. green: index point of the bit to be set with a range of 0 - 255

  3. blue: index point of the bit to be set with a range of 0 - 255

🔵 Returns

Nothing

set_hsb

set_hsb sets the LED colors on the Zen eyes or a Playstation controller based on the Hue, Saturation, and Brightness.

set_hsb(300, 55, 70);

🔴 Syntax¹ ² ³

set_hsb( Hue, Saturation, Brightness);

Parameters

  1. hue: index point of the bit to be set with a range of 0 - 359

  2. saturation: index point of the bit to be set with a range of 0 - 100

  3. brightness: index point of the bit to be set with a range of 0 - 100

🔵 Returns

Nothing

clamp function

The clamp function clamps x to the range [min, max].


	clamp(-11, -10, 10)
	// result = -10;

🔴 Syntax¹ ² ³

  • clamp (x, min, max)

Parameters

  1. x The number to clamp.

  2. min Lower bound of range to which x is clamped. Minimum value returned.

  3. max Upper bound of range to which x is clamped. Maximum value returned.

🔵 Returns

Returns min if x is less than min, max if x is greater than max, and x otherwise.

Last updated