# Functions API

# Functions API: Generale

# debug_message

Stampa un messaggio nel box dei messaggi di debug all'interno della pagina

# Sintassi

/**
 * @param string $message Messaggio da mostrare
 * 
 * @return void
 */
debug_message($message);

# Esempio

$x = read_val('FOO');
debug_message('FOO is : ' . $x);
// Output
// 12:24:56(0): FOO is 50000

# info_message

Stampa un messaggio nel box di info all'interno del pannello HMI.

# Sintassi

/**
 * @param string $message Messaggio da mostrare
 * 
 * @return void
 */
info_message('Test info Message Here');

# Esempio

$x = read_val('FOO');
info_message('FOO is : ' . $x);

# function_active

Restituisce lo stato di una funzione (attiva o disattiva), passando come parametro l'ID a 3 caratteri della funzione.

# Sintassi

/**
 * @param string $function_id L'ID della funzione
 * 
 * @return bool
 */
function_active('function_id');

# Esempio

$x = function_active('zxy');
debug_message('Is zxy active? ' . $x);

# device_status

Restituisce lo stato del device:

  • 0 se in timeout o quando disattivo
  • 1 se attivo e c'è comunicazione

# Sintassi

/**
 * @param string $device Device scelto da cui leggere lo stato
 * 
 * @return bool
 */
device_status($device);

# Esempio

$x = device_status('DEVICE_ONE');
if ($x == 1) {
  debug_message('DEVICE IS ON');
} else if ($x == 0) {
  debug_message('DEVICE IS OFF');
}
// Output
// 12:24:56(0): DEVICE IS ON

# since_startup

Ritorna il tempo trascorso dall'avvio del sistema.

Il valore di ritorno può essere espresso in:

  • secondi => se il parametro passato alla funzione è 's' o default.
  • minuti => se il parametro passato alla funzione è 'm'.
  • ore => se il parametro passato alla funzione è 'h'.

# Sintassi

/**
 * @param char $unit specifica in che formato ricevere il valore di ritorno della funzione.
 * 
 * @return int
 */
since_startup($unit);

# Esempio

$time = since_startup('s');
debug_message('secondi trascorsi: '.$time);
// Output
// sistema ri-avviato alle 12:24:51
// 12:24:56(0): secondi trascorsi: 5

# Functions API: Variabili

# read_val

Legge un device o una variabile e ne restituisce il valore.

# Sintassi

/**
 * @param string $var_name
 * 
 * @return number
 */
read_val($device);

# Esempio

if (read_val('temperature_sensor_1') > 54) {
  // do something if the condition is true
  debug_message('Temperature Sensor 1 is above 54');
}
// Output
// 12:24:56(0): Temperature Sensor 1 is above 54

# read_future_val

TIP

La variabile in questione deve essere registrata nella Blackbox per poter utilizzare questa funzione.

Legge un device o una variabile X secondi nel futuro e vi ritorna il valore.

# Sintassi

/**
 * @param string $var_name
 * @param number $seconds_future
 * @return value
 */
read_future_val($var_name, $seconds_future);

# Esempio

if (read_future_val('temperature_sensor_1', 10) > 54) {
  debug_message('Temperature Sensor 1 is above 54, in 10 seconds ahead');
}
// Output
// 12:24:56(0): Temperature Sensor 1 is above 54, in 10 seconds ahead

# write_val

Scrivi il valore su un device o su una variabile.

# Sintassi

/**
 * @param string $var_name
 * @param number $value
 * 
 * @return void
 */
write_val($var_name, $value);

# Esempio

write_val('temperature_sensor_1', 20);
$x = read_val('temperature_sensor_1');
debug_message('temperature_sensor_1 is ' . $x);
write_val('temperature_sensor_1', 10);
$x = read_val('temperature_sensor_1');
debug_message('temperature_sensor_1 is ' . $x);
// Output 
// 12:24:40(0): temperature_sensor_1 is 20
// 12:24:56(0): temperature_sensor_1 is 10

# write_val_period

Scrive due valori differenti in due momenti temporali distinti (definiti in millisecondi).

# Sintassi

/**
 * @param string $var_name
 * @param number $value1
 * @param number $value2
 * @param int $ms1
 * @param int $ms2
 */
write_val_period($var_name, $value1, $value2, $ms1, $ms2);

# Esempio

write_val_period('temperature_sensor_1', 50, -50, 5000, 5000);
// Output
// temperature_sensor_1 sarà 50 nei primi 5 secondi.
// temperature_sensor_1 sarà -50 nei successivi 5 secondi.
5AJYhWsAyRAtYhmgByxAtYBmiBSxDtIBliBawDNECliFawDJEC1iGaAGriPwf6DGMr64Q9L4AAAAASUVORK5CYII=
Write val period effect

# reset_val_period

Reset del valore di periodo impostato nella funzione write_val_period()

# Sintassi

/**
 * @param string $var_name
 * 
 * @return void
 */
reset_val_period($var_name);

# Esempio

reset_val_period('temperature_sensor_1');
// Output
// 12:24:40(0): temperature_sensor_1 is 20

# write_val_ramp

Scrive un valore che incrementa linearmente durante un timeframe

# Sintassi

/**
 * @param string $var_name
 * @param number $rampValueStart
 * @param number $rampValueEnd
 * @param number $msRampDuration
 * @return void
 */
write_val_ramp($var_name, $rampValueStart, $rampValueEnd, $msRampDuration)

ATTENZIONE

La rampa così generata deve essere resettata dopo ogni utilizzo.

# Esempio

write_val_ramp('temperature_sensor_1', 1, 100, 1000);
// Output
// Temperature sensor 1 incrementa da 1 a 100 in 1000 secondi
xnUZndwAAAABJRU5ErkJggg==
Write val ramp effect

# reset_val_ramp

Reset della rampa associata alla variabile

# Sintassi

/**
 * @param string $var_name
 * @return void
 */
reset_val_ramp($var_name);

# Esempio

reset_val_ramp('temperature_sensor_1');
// Output
// Temperature sensor smette di incrementare.

# write_val_at_time

Scrivi un valore all'ora impostata, definita nel formato mm:ss

# Sintassi

/** 
 * @param string $var_name
 * @param number $value
 * @param string $time 
 * @return void
 */
write_val_at_time($var_name, $value, $time);

# Esempio

write_val_at_time('temperature_sensor_1', 100, '16:20')
// Output
// Temperature sensor 1 viene aggiornato con il valore 100 alle ore 16:20.

# disable

Disabilita un Device ad essere scritto da HMI Panel / Section / Device List.

# Sintassi

/**
 * @param string $var_name
 * @return void
 */
disable($var_name);

# Esempio

disable('temperature_sensor_1');
// Output
// Temperature sensor 1 non può essere modificato da nessuna parte.

# enable

Abilita il Device ad essere scritto da HMI Panel / Section / Device List

# Sintassi

/**
 * @param string $var_name
 * @return void
 */
enable($var_name);

# Esempio

enable('temperature_sensor_1');
// Output
// Temperature sensor 1 può ora essere modificato.

# get_bounded_value

Ritorna il valore di ingresso entro un range limitato.

# Sintassi

/**
 * @param number   $input_value     Input value
 * @param number   $min_value       Min value
 * @param number   $max_value       Max value
 *
 * @return number
 */
get_bounded_value($input_value, $min_value, $max_value);

# Esempio

get_bounded_value('temperature_sensor_1', 0, 50);
// Output
// Il valore della Temperature sensor 1 è limitato tra 0 e 50 gradi.

# is_value_inside_target_range

Ritorna true se il valore di ingresso è compreso tra [target_value-offset; target_value+offset].

Se non specificato, offset è 5%.

# Sintassi

/**
 * @param number   $input_value     Input value
 * @param number   $target_value    Target value
 * @param number   $offset          Offset to create a range around the target value
 *
 * @return bool
 */
is_value_inside_target_range($input_value, $target_value, $offset = null);

# Esempio

/* temperature_sensor_1 = 21 */
is_value_inside_target_range('temperature_sensor_1', 20, 2);
// Output 
// Il valore del sensore di temperatura 1 è 21, che è inferiore a 22. La funzione restituisce vero.

# is_value_inside_target_range_mod

Restituisce vero se il valore di input è all'interno dell'intervallo creato da [target_value-offset; target_value+offset], tenendo conto del fatto intervallo obiettivo può essere ricalibrato tra $input_min e $input_max.

Se non specificato, l'offset è del 5% del valore_obiettivo.

# Sintassi

/**
 * @param number   $input_value     Input value
 * @param number   $input_min       Minimum input value allowed
 * @param number   $input_max       Maximum input value allowed
 * @param number   $target_value    Target value
 * @param number   $offset          Offset to create a range around the target value
 *
 * @return bool
 */
is_value_inside_target_range_mod($input_value, $input_min, $input_max, $target_value, $offset = null)

# Esempio

is_value_inside_target_range_mod(980, 0, 1000, 20, 50);
is_value_inside_target_range_mod(980, 0, 1000, 20, 30);
// Output
// Il primo esempio restituisce vero perché l'intervallo obiettivo diventerà [970;1000] unione [0;70].
// Il secondo esempio restituisce falso perché l'intervallo obiettivo diventerà [990;1000] unione [0;50].

# scale_value

Ritorna il valore scalato dell'ingresso rispetto ad un range specificato.

# Sintassi

/**
 * @param number   $input_value   Input value
 * @param number   $input_1       Input range start
 * @param number   $input_2       Input range end
 * @param number   $output_1      Output range start
 * @param number   $output_2      Output range end
 * @param bool  $round         Round to nearest integer
 *
 * @return number
 */
scale_value($input_value, $input_1, $input_2, $output_1, $output_2, $round = true)

# Esempio

scale_value(6000, 0, 12000, 0, 3);
// Output
// Poiché 6000 è esattamente la metà di 12000, la funzione restituisce la metà di 3, che è 2 (arrotondato all'intero più vicino, quindi 1.5 diventa 2).

# to_bitmap

Restituisce una bitmap (numero intero) da un array di valori (i valori vengono automaticamente convertiti in bool, se non sono di natura bool).

# Sintassi

/**
 * @param int[]   $values       Input array values to be merged into a number (bitmap)
 * @param bool    $lsb_first    If true, array values are considered ordered from LSB to MSB. Else, viceversa.
 * @param bool    $signed       If true, the MSB will be taken with minus sign. Else, viceversa.
 */
to_bitmap($values, $lsb_first = true, $signed = false)

# Esempio

$bitmap = to_bitmap([1, 0, 1], true);
// La conversione bitmap della sequenza di valori [1, 0, 1] è 5.

# from_bitmap

Restituisce un array di bool da una bitmap (numero intero).

L'array è popolato dal bit meno significativo (LSB) al bit più significativo (MSB): res[0] corrisponde al componente 2^0.

# Sintassi

/**
 * @param int   $bitmap     Input bitmap
 * @param int   $length     Returned array values length
 */
from_bitmap($bitmap, $length = 16)

# Esempio

$array = to_bitmap(5, 3);
// Output
// La conversione dal valore bitmap 5 restituisce il vettore [1, 0, 1].

# increment_cycling_variable

Incrementa una variabile di sistema e la reimposta a zero se il nuovo valore supera $max_value_before_reset.

Il valore aggiornato viene sempre memorizzato all'interno di una variabile della Section: $var_name.

# Sintassi

/**
 * @param string $var_name               Variable to increment
 * @param int    $max_value_before_reset Max value allowed for storing the new variable value. If the new value goes over this parameter, then variable is reset to $var_reset_value.
 * @param int    $var_reset_value        The value assigned to the variable when it goes over the maximum allowed value.
 * 
 * @return int  The updated value
 */
increment_cycling_variable($var_name, $max_value_before_reset, $var_reset_value = 0)

ATTENZIONE

Il parametro $var_name deve essere una variabile dichiarata all'interno delle Section.

# Esempio

/* loop_stage = 2 */
increment_cycling_variable('loop_stage', 5, 0);
/* cycle_stage = 5 */
increment_cycling_variable('cycle_stage', 5, 0);
// Output 
// Il valore di loop_stage viene incrementato di 1 e diventa uguale a 3.
// Il valore di cycle_stage viene incrementato di 1, ma supera il valore massimo raggiungibile, quindi viene reimpostato a 0.

# watchdog_on_bit_inversion

Logica di controllo del watchdog per l'inversione di un bit: verifica l'inversione del bit all'interno di una finestra temporale.

Se il bit si inverte, allora si avvia una nuova finestra a partire dal momento in cui avviene l'inversione e la funzione restituisce vero.

Se non si verifica l'inversione, si avvia una nuova finestra e la funzione restituisce falso.

Lo stato di timeout deve essere sempre memorizzato all'interno di una variabile di sezione: $watchdog_timeout_var.

# Sintassi

/**
 * @param string $watchdog_timer_name     Il timer Plexus che rappresenta la lunghezza della finestra temporale per controllare l'inversione di un bit
 * @param string $watchdog_timeout_var    La variabile Plexus che memorizza lo stato del watchdog
 * @param bool   $watchdog_actual_value   Il valore effettivo del bit nel ciclo corrente
 * 
 * @return bool  Lo stato di timeout, vero quando il watchdog è scaduto
 */
watchdog_on_bit_inversion($watchdog_timer_name, $watchdog_timeout_var, $watchdog_actual_value)

ATTENZIONE

Il parametro $watchdog_timeout_var deve essere una variable dichiarata all'interno delle Section.

# Esempio

watchdog_on_bit_inversion('watchdog_timer', 'watchdog_timeout', 'watchdog_value');
// Output
// Restituisce vero se il valore del watchdog cambia prima che scada il timer del watchdog.
// Restituisce falso in caso contrario.

# emergency_status

Restituisce 1 se il pulsante di emergenza sul pannello HMI è attivo. Zero in caso contrario.

# Sintassi

emergency_status()

ATTENZIONE

Il parametro $watchdog_timeout_var deve essere dichiarato all'interno delle Section.

# Esempio

if(emergency_status())
  debug_message('Emergency is active!');
else 
  debug_message('Emergency is not active');
// Output
// Restituisce 1 se il pulsante di emergenza sul pannello HMI è attivo. Restituisce zero in caso contrario.

# moving_average

Calcola la media mobile di una finestra composta da X elementi (in samples) della variabile specificata.

È possibile invocare più volte la funzione con diversi valori di lunghezza della finestra.

Ogni nuovo valore viene inserito nella finestra e conteggiato nel calcolo della media. Con l'inserimento del nuovo il valore più vecchio viene eliminato.

# Sintassi

moving_average('var_name', $window_in_samples)

# Esempio

// loops  0   1   2   3   4
// input  10  20  30  40  30
$media = moving_average('current_mesurament', 4);
echo $media;
// output 10  15  20  25  30

# reset_moving_average

Resetta lo stato della moving average invocata sullo stesso numero di campioni.

# Sintassi

reset_moving_average('var_name', $window_in_samples)

# Esempio

reset_moving_average('var_name', 4);
// Output
// Will reset a previous call to moving_average('var_name', 4)

# fixed_average

Calcola la media su una finestra fissa di X secondi della variabile specificata.

# Sintassi

fixed_average('var_name', $window_in_seconds)

# Esempio

// sec    0   1   2   3   4   5   6   7   8     9
// input  10  20  30  40  30  15  20  25  30    40
$media = fixed_average('temperature_values', 4);
echo $media;
// Output 
// 0   0   0   0   26  26  26  26  71.25 71.25

# reset_fixed_average

Resetta lo stato della fixed average invocata sullo stesso periodo.

# Sintassi

reset_fixed_average('var_name', $window_in_seconds)

# Esempio

reset_fixed_average('var_name', 4);
// Output
// Will reset a previous call to fixed_average('var_name', 4)

# moving_max

Restituisce il valore massimo di una finestra di X secondi della variabile specificata.

Ogni X secondi il valore più vecchio viene eliminato.

# Sintassi

moving_max('var_name', $window_in_seconds)

# Esempio

// sec    0   1   2   3   4   5   6   7   8   9 
// input  10  20  18  23  17  2   15  7   19  28
$max = moving_max('var_name', 5);
echo $max;
// output 10  20  20  23  23  23  23  17  19  28

# reset_moving_max

Resetta lo stato della moving max invocata sullo stesso periodo

# Sintassi

reset_moving_max('var_name', $window_in_seconds)

# Esempio

reset_moving_max('var_name', 5)
// Output
// Will reset a previous call to moving_max('var_name', 5)

# moving_min

Restituisce il valore minimo di una finestra di X secondi della variabile specificata.

Ogni X secondi il valore più vecchio viene eliminato.

# Sintassi

moving_min('var_name', $window_in_seconds)

# Esempio

// sec    0   1   2   3   4    5   6   7   8   9 
// input  10  20  18  23  17   2   15  7   19  28
$min = moving_min('var_name', 4);
echo $min;
// output 10  10  10  10  17   2   2   2   2   7

# reset_moving_min

Resetta lo stato della moving min invocata sullo stesso periodo.

# Sintassi

reset_moving_min('var_name', $window_in_seconds)

# Esempio

reset_moving_min('var_name', 4)
// Output
// Will reset a previous call to fixed_average('var_name', 4)

# Functions API: Timer

# start_timer

Start Timer

Timer deve essere precedentemente creato dalla pagina Sections.

# Sintassi

/**
 * @param string $timer_name
 * @return void
 */
start_timer($timer_name);

# Esempio

start_timer('my_timer');
// Output
// `my_timer` inizierà a conteggiare il tempo.

# reset_timer

Resetta il timer

# Sintassi

/**
 * @param string $timer_name
 * @return void
 */
reset_timer($timer_name);

# Esempio

reset_timer('my_timer');
// Output
// `my_timer` timer smette di conteggiare il tempo.

# pause_timer

Mette in pausa il Timer

Timer deve essere stato attivato.

# Sintassi

/**
 * @param string $timer_name 
 * @param bool $value (pass 1 to pause it)
 * @return void
 */
pause_timer($timer_name, $value);

# Esempio

pause_timer('my_timer', 1);
// Output
// `my_timer` timer si metterà in pausa.

# timer_running

Controlla se il Timer sta conteggiando il tempo.

# Sintassi

/**
 * @param string $timer_name
 * @return bool
 */
timer_running($timer_name);

# Esempio

if (!timer_running('my_timer')) {
  debug_message('TIMER IS NOT RUNNING');
}
// Output
// `TIMER IS NOT RUNNING`

# read_timer

Legge il valore attuale del Timer

# Sintassi

/**
 * @param string $timer_name
 * @return number
 */
read_timer($timer_name);

# Esempio

$x = read_timer('my_timer');
debug_message('TIMER IS : ' . $x);
// Output
// `TIMER IS 22000`

# set_timer_duration

Imposta la durata del timer

# Sintassi

/**
 * @param string $timer_name 
 * @param number $duration   
 * @return void
 */
set_timer_duration($timer_name, $duration);

# Esempio

set_timer_duration('my_timer', 1000);
// Output
// `my_timer` durata impostata a 1s o 1000 ms

# Functions API: Alerts

# set_alert

Attiva un alert con messaggio.

Se questo allarme è attivo non fa partire gli allarmi subordinati inclusi nell'array opzionale $subordinated_alarms.

# Sintassi

/**
 * @param string $alert_name
 * @param string $message
 * @param Array<string> $subordinated_alarms. Optional, defaults to []
 * @return void
 */
set_alert('alert_name', 'message', $subordinated_alarms)

# Esempio

set_alert('my_alert', 'message', ['subordinated_alarm_name_1', ...])
// Output
// `my_alert` verrà attivato immediatamente.

# set_alert_delay

Attiva un alert con messaggio, ritardato dopo msDelay.

Se questo allarme è attivo non fa partire gli allarmi subordinati inclusi nell'array opzionale $subordinated_alarms.

# Sintassi

/**
 * @param string $alert_name
 * @param string $message
 * @param number $msDelay 
 * @param Array<string> $subordinated_alarms. Optional, defaults to []
 * @return void
 */
set_alert_delay('alert_name', 'message', $ms_delay, $subordinated_alarms)

# Esempio

set_alert_delay('my_alert', 'Something went wrong', $ms_delay, ['subordinated_alarm_name_1', ...])
// Output 
// `my_alert` verrà attivato con un ritardo di 1s.

# reset_alert

Reset di un alert che si è attivato

# Sintassi

/** 
 * @param string $alert_name
 * @return void
 */
reset_alert($alert_name);

# Esempio

reset_alert('my_alert');
// Output
// `my_alert` verrà resettato.

# alert_active

Restituisce lo stato di un alert, attivo/non attivo

# Sintassi

/**
 * @param Alert $alert_name
 * @return bool
 */
alert_active($alert_name);

# Esempio

$x = alert_active('my_alert');
debug_message('my_alert is ' . $x);
// Output
// `my_alert is 1`

# any_alert_active

Restituisce se esiste un alert attivo o meno

# Sintassi

/** 
 * @return bool
 */
any_alert_active();

# Esempio

$x = any_alert_active();
debug_message('Active Alert Currently: ' . $x);
// Output
// `Active Alert Currently: 0`

# Functions API: Stepper API

# start_step

Fa partire lo stepper

# Sintassi

/**
 * @param string $step_name 
 * @return void
 */
start_step($stepper);

# Esempio

start_step('my_stepper');
// Output
// Stepper started

# read_step

Legge lo stepper

# Sintassi

/**
 * @param string $step_name  
 * @return number $value
 */
read_step($step_name);

# Esempio

$x = read_step('my_stepper');
if ($x == 1) {
  debug_message('Step currently at one');
}
// Output
// `1`

# set_step

Imposta lo stepper

# Sintassi

/**
 * @param string $step_name 
 * @param number $value
 * @return void $value
 */
set_step($step_name, $value);

# Esempio

set_step('my_step', 10);
if (read_step('my_step') == 10) {
  debug_message('Step currently at 10');
}
// Output
// my_step step set to 10.
// Step currently at 10

# Functions API: PID control

# PID_controller

Il PID controller cerca di mantenere il processo controllato il più vicino possibile al valore di riferimento desiderato, minimizzando l'errore e fornendo una risposta rapida e stabile. Si veda questo link (opens new window) per maggiori informazioni su un controller PID.

# Sintassi

/**
 * @param string $PID_name 
 * @param Array<string> $PID_params
 *    "Kd"                               => number,       // Coefficiente derivativo
 *    "Kp"                               => number,       // Coefficiente proporzionale (opzionale, default 0)
 *    "Ki"                               => number,       // Coefficiente integrativo (opzionale, default 0)
 *    "Measured_Value"                   => number,       // Valore attuale misurato
 *    "Set_Point"                        => number,       // Valore desiderato da raggiungere
 *    "Set_Point_Max_Error_Tolerance"    => number,       // Errore massimo tollerato entro il quale non viene modificato l'output (opzionale, default = 5% del Set_Point)
 *    "Frequency"                        => int,          // Frequenza di aggiornamento dell'output indicato in numero di loops (100ms) (opzionale, default 1)
 *    "Measured_Value_Average_Frequency" => int,          // Opzionale, se si vuole considerare un valore medio su N campioni di Measured_Value anziché il valore istantaneo (può essere utile in casi dove c'è rumore sulla misurazione) (opzionale, default 1)
 *    "Output_Max"                       => number,       // Valore massimo in uscita
 *    "Output_Min"                       => number,       // Valore minimo in uscita
 *    "Output_Decimals_Digits"           => int,          // Numero di cifre decimali da calcolare nell'output (opzionale, default 0)
 * 
 * @return number PID output
 */
PID_controller($PID_name, $PID_params)

# Esempio

PID_controller('my_PID', array(
  "Kp" => 0.095,
  "Ki" => 0.038,
  "Kd" => 0.002,
  "Measured_Value" => read_val('pressure_in'),
  "Set_Point" => read_val('Pressure_Set_1'),
  "Set_Point_Max_Error_Tolerance" => 6,
  "Output_Max" => 100,
  "Output_Min" => 5,
  "Output_Decimals_Digits" => 1
));

# reset_PID_controller

Resetta il PID_controller specificato

# Sintassi

/**
 * @param string $PID_name
 */
reset_PID_controller($PID_name)

# Esempio

reset_PID_controller('PID_name');
// Output
// 'PID_name' verrà resettato 

# PWM_controller

Crea un segnale digitale con un duty cycle e un periodo specificato. Si veda questo link (opens new window) per maggiori informazioni sul PWM.

# Sintassi

/**
 * @param string $PWM_name
 * @param int $duty Un valore da 0 a 100 che indica la percentuale di tempo sul $msPeriod in cui l'output deve essere 1
 * @param int $msPeriod La durata del PWM in millisecondi
 */
PWM_controller($PWM_name, $duty, $msPeriod)

# Esempio

PWM_controller('PWM_name', 20, 1000 * 10);
// Output
// 'PWM_name' verrà resettato 

# reset_PWM_controller

Resetta il PWM_controller specificato

# Sintassi

/**
 * @param string $PWM_name
 */
reset_PWM_controller($PWM_name)

# Esempio

reset_PWM_controller('PWM_controller');
// Output
// 'PWM_controller' verrà resettato 

# Include function, esempi

# Definizione di costante

È utile definire costanti in modo da richiamarne il valore solo attraverso il nome.

Il valore di riferimento viene cambiato in un unico punto del codice

# Sintassi

const WEIGHT_GOAL = 7000;

# Esempio

const WEIGHT_GOAL = 7000;
if (read_val(weight) == WEIGHT_GOAL) { //weight = 7000 kg
  debug_message('Goal weight is reached');
}
// Output
// 'Goal weight is reached'

# Definizione di costanti di tipo enumerativo

Possono essere richiamati nel codice come: Position::AirFlowing invece di scrivere solo l'integer 1 che perde di significato per chi legge il programma

# Sintassi

abstract class Position
{
    const Unknown = 0;
    const Air = 1;
    const Load = 2;
    const Unload = 3;
}

# Esempio

    if (read_val('Current_position') == Position::Air) {
      //Current_position = 1
      debug_message('Posizione Aria');
    }
// Output
// 'Posizione Aria'

# Definizione di custom API

Definire la custom API nella sezione Include (eseguito solo al primo boot) Imposta le bocchette nello stato desiderato

# Sintassi

/**
  * @param string   $status  ['open', any other to close]
 */
function set_all_sludge_gates($status)
{
    if ($status == 'open') {
        write_val('gate_1', 1);
        write_val('gate_2', 1);
        return;
    }
    write_val('gate_1', 0);
    write_val('gate_2', 0);
}

# Esempio

set_all_sludge_gates('close');
// Output
// gate_1 viene chiuso
// gate_2 viene chiuso
Last Updated: 2/2/2024, 16:28:31