/**
 * Selects the specified analog input, automatically handling any multiplexing and timing needs.
 *
 * @param input Analog_Input_t* The analog input to select.
 * @retval none
 */
void SelectAnalogInput(Analog_Input_t* input) {
	if (input != NULL ) {
		if (isExternalInput(input->physicalInput)) {
			SelectExternalInput(input->externalInput);
			CurrentInput = input;
		} else if (isInternalInput(input->physicalInput)) {
			SelectInternalInput(input->internalInput);
			CurrentInput = input;
		} else if (input->physicalInput == EXTERNAL_OFFSET_CAL) {
			SelectCalibrationInput();
			CurrentInput = input;
		} else {
			/* ERROR */
			snprintf(TOSTRING_BUFFER, sizeof(TOSTRING_BUFFER),
					"[Analog Input Multiplexer] Attempted to select an input which does not exist.");
			TelnetWriteErrorMessage(TOSTRING_BUFFER);
#ifdef INPUT_MULTIPLEXER_DEBUG
			printf("[Analog Input Multiplexer] Attempted to select an input which does not exist.\n\r");
#endif
		}
	} else {
#ifdef INPUT_MULTIPLEXER_DEBUG
		printf("[Analog Input Multiplexer] Attempted to select a NULL input.\n\r");
#endif
	}
}
Exemplo n.º 2
0
/**
 * Removes a digital input structure from the board's list by specifying its physical input channel.
 *
 * @param id uint8_t The physical channel to remove, if present.
 * @retval none
 */
static void RemoveDigitalInputByID(uint8_t id) {
	if (isExternalInput(id)) {
		InitializeInput(&Ext_DInputs[id]);
	} else {
		/* This is out of range */
#ifdef DIGITALINPUT_DEBUG
		printf("[Digital Input] Cannot find the requested digital input. Input does not exist on the board.\n\r");
#endif
	}
}
Exemplo n.º 3
0
/**
 * Retrieve a digital input structure by specifying the physical input channel.
 *
 * @param number uint8_t The physical input channel to retrieve.
 * @retval Digital_Input_t* Pointer to the digital input structure.
 */
Digital_Input_t* GetDigitalInputByNumber(uint8_t number) {
	if (isExternalInput(number)) {
		return &Ext_DInputs[number];
	} else {
		/* This is out of range */
#ifdef DIGITALINPUT_DEBUG
		printf("[Digital Input] Cannot find the requested digital input. Input does not exist on the board.\n\r");
#endif
		return NULL ;
	}
}
Exemplo n.º 4
0
/**
 * Removes a digital input from the board's list based on the supplied parameters.
 *
 * @param keys char** Array of strings containing the command line keys. Indexed with values.
 * @param values char** Array of strings containing the command line values. Indexed with keys.
 * @param count uint8_t The number of parameters passed on the command line.
 * @retval Tekdaqc_Function_Error_t The error status code.
 */
Tekdaqc_Function_Error_t RemoveDigitalInput(char keys[][MAX_COMMANDPART_LENGTH], char values[][MAX_COMMANDPART_LENGTH], int count) {
	Tekdaqc_Function_Error_t retval = ERR_FUNCTION_OK;
	char* param;
	int8_t index = -1;
	for (uint_fast8_t i = 0U; i < NUM_REMOVE_DIGITAL_INPUT_PARAMS; ++i) {
		index = GetIndexOfArgument(keys, REMOVE_DIGITAL_INPUT_PARAMS[i], count);
		if (index >= 0) { /* We found the key in the list */
			param = values[index]; /* We use the discovered index for this key */
			switch (i) { /* Switch on the key not position in arguments list */
			case 0U: { /* INPUT key */
				char* testPtr = NULL;
				uint8_t in = (uint8_t) strtol(param, &testPtr, 10);
				if (testPtr == param) {
					retval = ERR_DIN_PARSE_ERROR;
				} else {
					if (isExternalInput(in)) {
						/* A valid input number */
						RemoveDigitalInputByID(in);
					} else {
						/* Input number out of range */
#ifdef DIGITALINPUT_DEBUG
						printf("[Digital Input] The requested input number is invalid.\n\r");
#endif
						retval = ERR_DIN_INPUT_OUTOFRANGE;
					}
				}
				break;
			}
			default:
				retval = ERR_DIN_PARSE_ERROR;
			}
		} else {
			/* Somehow an error happened */
#ifdef DIGITALINPUT_DEBUG
			printf("[Digital Input] Unable to locate required key: %s\n\r", REMOVE_DIGITAL_INPUT_PARAMS[i]);
#endif
			retval = ERR_DIN_PARSE_MISSING_KEY; /* Failed to locate a key */
		}
	}
	return retval;
}
/**
 * Looks up the corresponding ExternalMuxedInput_t for the specified input number.
 *
 * @param input uint8_t The input number to lookup.
 * @retval ExternalMuxInput_t The lookup value.
 */
ExternalMuxedInput_t GetExternalMuxedInputByNumber(uint8_t input) {
	ExternalMuxedInput_t in = NULL_CHANNEL;
	if (isExternalInput(input)) {
		switch (input) {
		case 0:
			in = EXTERN_0;
			break;
		case 1:
			in = EXTERN_1;
			break;
		case 2:
			in = EXTERN_2;
			break;
		case 3:
			in = EXTERN_3;
			break;
		case 4:
			in = EXTERN_4;
			break;
		case 5:
			in = EXTERN_5;
			break;
		case 6:
			in = EXTERN_6;
			break;
		case 7:
			in = EXTERN_7;
			break;
		case 8:
			in = EXTERN_8;
			break;
		case 9:
			in = EXTERN_9;
			break;
		case 10:
			in = EXTERN_10;
			break;
		case 11:
			in = EXTERN_11;
			break;
		case 12:
			in = EXTERN_12;
			break;
		case 13:
			in = EXTERN_13;
			break;
		case 14:
			in = EXTERN_14;
			break;
		case 15:
			in = EXTERN_15;
			break;
		case 16:
			in = EXTERN_16;
			break;
		case 17:
			in = EXTERN_17;
			break;
		case 18:
			in = EXTERN_18;
			break;
		case 19:
			in = EXTERN_19;
			break;
		case 20:
			in = EXTERN_20;
			break;
		case 21:
			in = EXTERN_21;
			break;
		case 22:
			in = EXTERN_22;
			break;
		case 23:
			in = EXTERN_23;
			break;
		case 24:
			in = EXTERN_24;
			break;
		case 25:
			in = EXTERN_25;
			break;
		case 26:
			in = EXTERN_26;
			break;
		case 27:
			in = EXTERN_27;
			break;
		case 28:
			in = EXTERN_28;
			break;
		case 29:
			in = EXTERN_29;
			break;
		case 30:
			in = EXTERN_30;
			break;
		case 31:
			in = EXTERN_31;
			break;
		default:
			/* Do nothing */
			break;
		}
	}
	return in;
}