Pilot#

Functions

struct pilot *pilot_create(const struct pilot_params *params, struct adc122s051 *adc, struct lm_pwm_channel *pwm, uint16_t *buf)#

Creates a pilot instance with the specified parameters.

This function initializes and allocates memory for a pilot structure with the specified parameters, ADC and PWM channel handles, and buffer for ADC samples.

Parameters:
  • params[in] Pointer to the pilot_params structure containing the configuration parameters for the pilot instance.

  • adc[in] Pointer to the adc122s051 structure.

  • pwm[in] Pointer to the PWM channel structure.

  • buf[in] Pointer to the buffer to be used for ADC samples.

Returns:

struct pilot* Pointer to the created pilot structure.

void pilot_delete(struct pilot *pilot)#

Deletes a pilot instance.

This function deallocates the memory and cleans up resources associated with the specified pilot structure.

Parameters:

pilot[in] Pointer to the pilot structure to be deleted.

void pilot_set_status_cb(struct pilot *pilot, pilot_status_cb_t cb, void *cb_ctx)#

Set the callback for pilot status changes.

This function sets a callback function that will be called whenever the status of the pilot changes. The callback function will be provided with the current status and the user-defined context.

Parameters:
  • pilot[in] Pointer to the pilot structure.

  • cb[in] The callback function to be called on status changes.

  • cb_ctx[in] User-defined context to be passed to the callback function.

int pilot_enable(struct pilot *pilot)#

Enables the pilot instance.

This function enables the pilot instance, allowing it to start its operations. It typically involves starting the PWM signal and any necessary ADC measurements.

Parameters:

pilot[inout] Pointer to the pilot structure.

Returns:

int Status code (0 for success, non-zero for error).

int pilot_disable(struct pilot *pilot)#

Disables the pilot instance.

This function disables the pilot instance, stopping its operations. It typically involves stopping the PWM signal and any ongoing ADC measurements.

Parameters:

pilot[inout] Pointer to the pilot structure.

Returns:

int Status code (0 for success, non-zero for error).

int pilot_set_duty(struct pilot *pilot, const uint8_t pct)#

Sets the duty cycle for the pilot PWM signal.

This function sets the PWM duty cycle for the pilot signal to the specified percentage.

Parameters:
  • pilot[inout] Pointer to the pilot structure.

  • pct[in] Percentage of the PWM duty cycle to be set.

Returns:

int Status code (0 for success, non-zero for error).

uint8_t pilot_get_duty_set(const struct pilot *pilot)#

Get the duty cycle set by the user.

This function retrieves the duty cycle percentage that has been set by the user, not the value read from the PWM signal.

Parameters:

pilot[in] Pointer to the pilot structure.

Returns:

The duty cycle percentage set by the user.

uint8_t pilot_duty(const struct pilot *pilot)#

Retrieves the current duty cycle of the pilot PWM signal.

This function retrieves the current duty cycle percentage of the pilot PWM signal. The duty cycle represents the proportion of time the signal is active within a given period.

Parameters:

pilot[in] Pointer to the pilot structure.

Returns:

uint8_t The current duty cycle percentage of the pilot PWM signal.

pilot_status_t pilot_status(const struct pilot *pilot)#

Retrieves the current status of the pilot instance.

This function retrieves the current status of the pilot instance and returns it as a pilot_status_t structure. The status includes various operational parameters and states of the pilot.

Parameters:

pilot[in] Pointer to the pilot structure.

Returns:

pilot_status_t The current status of the pilot instance.

uint16_t pilot_millivolt(const struct pilot *pilot, const bool low_voltage)#

Retrieves the current millivolt value from the pilot instance.

This function retrieves the current millivolt value measured by the pilot instance. It typically involves reading the latest ADC measurement and converting it to millivolts. The low_voltage parameter indicates whether to retrieve the low voltage measurement.

Parameters:
  • pilot[in] Pointer to the pilot structure.

  • low_voltage[in] Boolean indicating whether to retrieve the low voltage measurement.

Returns:

uint16_t The current millivolt value measured by the pilot.

bool pilot_ok(const struct pilot *pilot)#

Checks if the pilot instance is operating correctly.

This function checks the status of the pilot instance and returns true if it is operating correctly, otherwise returns false.

Parameters:

pilot[inout] Pointer to the pilot structure.

Returns:

bool True if the pilot is operating correctly, false otherwise.

pilot_error_t pilot_error(const struct pilot *pilot)#

Retrieves the current error status of the pilot instance.

This function retrieves the current error status of the pilot instance and returns it as a pilot_error_t enumeration value. The error status indicates any issues or faults detected in the pilot instance.

Parameters:

pilot[in] Pointer to the pilot structure.

Returns:

pilot_error_t The current error status of the pilot instance.

const char *pilot_stringify_status(const pilot_status_t status)#

Converts a pilot status to its string representation.

This function converts the specified pilot status to its corresponding string representation. This can be useful for logging or displaying pilot status in a human-readable format.

Parameters:

status[in] The pilot status to be converted to a string.

Returns:

const char* The string representation of the specified pilot status.

void pilot_default_params(struct pilot_params *params)#

Retrieves the default parameters for the pilot instance.

This function initializes the provided pilot_params structure with the default parameters for the pilot instance. These default parameters can be used to configure the pilot instance with standard settings.

Parameters:

params[out] Pointer to the pilot_params structure to be initialized with default values.

Typedefs

typedef void (*pilot_status_cb_t)(void *ctx, pilot_status_t status)#
struct pilot_boundary#
#include <pilot.h>

Public Members

uint16_t a#
uint16_t b#
uint16_t c#
uint16_t d#
uint16_t e#
struct pilot_boundaries#
#include <pilot.h>

Public Members

struct pilot_boundary upward#
struct pilot_boundary downward#
struct pilot_params#
#include <pilot.h>

Public Members

uint16_t scan_interval_ms#
uint16_t cutoff_voltage_mv#
uint16_t noise_tolerance_mv#
uint16_t max_transition_clocks#
struct pilot_boundaries boundary#
uint16_t sample_count#

Enums

enum pilot_status_t#

Values:

enumerator PILOT_STATUS_A = 12#
enumerator PILOT_STATUS_B = 9#
enumerator PILOT_STATUS_C = 6#
enumerator PILOT_STATUS_D = 3#
enumerator PILOT_STATUS_E = 0#
enumerator PILOT_STATUS_F = -12#
enumerator PILOT_STATUS_UNKNOWN = 0xff#
enum pilot_error_t#

Values:

enumerator PILOT_ERROR_NONE#
enumerator PILOT_ERROR_DUTY_MISMATCH#
enumerator PILOT_ERROR_FLUCTUATING#
enumerator PILOT_ERROR_TOO_LONG_INTERVAL#
enumerator PILOT_ERROR_INVALID_PARAMS#
enumerator PILOT_ERROR_NOT_INITIALIZED#
enumerator PILOT_ERROR_UNKNOWN#

Defines

PILOT_NUMBER_OF_SAMPLES 500#