Пример #1
0
uint8_t setActuatorSettingsParamByIndex(uint16_t index, const mavlink_param_union_t* param)
{
	ActuatorSettingsData settings;
	ActuatorSettingsGet(&settings);
	switch (index)
	{
		case 0:
		{
			if (param->type == MAVLINK_TYPE_UINT32_T)
			{
				settings.FixedWingRoll1 = param->param_uint32;
			}
			else
			{
				return MAVLINK_RET_VAL_PARAM_TYPE_MISMATCH;
			}
		}
			break;
		case 1:
		{
			if (param->type == MAVLINK_TYPE_UINT32_T)
			{
				settings.FixedWingRoll2 = param->param_uint32;
			}
			else
			{
				return MAVLINK_RET_VAL_PARAM_TYPE_MISMATCH;
			}
		}
			break;
		default:
		{
			return MAVLINK_RET_VAL_PARAM_NAME_DOES_NOT_EXIST;
		}
			break;
	}
	
	// Not returned in default case, try to write (ok == 0) and return result of
	// write operation
	if (ActuatorSettingsSet(&settings) == 0)
	{
		return MAVLINK_RET_VAL_PARAM_SUCCESS;
	}
	else
	{
		return MAVLINK_RET_VAL_PARAM_WRITE_ERROR;
	}
}
Пример #2
0
/* PWMOutSet(int,int): set output pulse width of an unused output channel */
void SystemPWMOutSet(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
{
	int16_t channel = Param[0]->Val->Integer;
	int16_t value = Param[1]->Val->Integer;

	// check channel range
	if ((channel < 0) || (channel >= ACTUATORSETTINGS_CHANNELNEUTRAL_NUMELEM))
		return;

	// check mixer settings
	MixerSettingsData mixerSettings;
	MixerSettingsGet(&mixerSettings);

	// this structure is equivalent to the UAVObjects for one mixer.
	typedef struct {
		uint8_t type;
		int8_t matrix[5];
	} __attribute__((packed)) Mixer_t;

	// base pointer to mixer vectors and types
	Mixer_t * mixers = (Mixer_t *)&mixerSettings.Mixer1Type;

	// the mixer has to be disabled for this channel.
	if (mixers[channel].type != MIXERSETTINGS_MIXER1TYPE_DISABLED)
		return;

	// check actuator settings
	ActuatorSettingsData actuatorSettings;
	ActuatorSettingsGet(&actuatorSettings);

	// the channel type has to be a PWM output.
	if (actuatorSettings.ChannelType[channel] != ACTUATORSETTINGS_CHANNELTYPE_PWM)
		return;

	actuatorSettings.ChannelMin[channel] = value;
	actuatorSettings.ChannelMax[channel] = value;
	actuatorSettings.ChannelNeutral[channel] = value;

	ActuatorSettingsSet(&actuatorSettings);
}