blob: cdf5fbb1ea4808fb591ef3d96f88386a04164078 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#include "EnumCameraParameter.h"
8#include <stdio.h>
9#include <string.h>
10
11/**
12 * Constructor for an enumeration camera parameter.
13 * Enumeration camera parameters have lists of value choices and strings that go
14 * with them. There are also C++ enumerations to go along with them.
15 * @param setString The string for an HTTP request to set the value.
16 * @param getString The string for an HTTP request to get the value.
17 * @param choices An array of strings of the parameter choices set in the http strings.
18 * @param numChoices The number of choices in the enumeration set.
19 */
20EnumCameraParameter::EnumCameraParameter(const char *setString, const char *getString, bool requiresRestart,
21 const char *const*choices, int numChoices)
22 : IntCameraParameter(setString, getString, requiresRestart)
23{
24 m_enumValues = choices;
25 m_numChoices = numChoices;
26}
27
28/*
29 * Check if an enumeration camera parameter has changed.
30 * Check if the parameter has changed and update the camera if it has. This is called
31 * from a loop in the parameter checker task.
32 * @returns true if the camera needs to restart
33 */
34bool EnumCameraParameter::CheckChanged(bool &changed, char *param)
35{
36 changed = m_changed;
37 if (m_changed)
38 {
39 m_changed = false;
40 sprintf(param, m_setString, m_enumValues[m_value]);
41 return m_requiresRestart;
42 }
43 return false;
44}
45
46/**
47 * Extract the parameter value from a string.
48 * Extract the parameter value from the camera status message.
49 * @param string The string returned from the camera.
50 * @param length The length of the string from the camera.
51 */
52void EnumCameraParameter::GetParamFromString(const char *string, int stringLength)
53{
54 char resultString[50];
55 if (SearchForParam(m_getString, string, stringLength, resultString) < 0) return;
56 for (int i = 0; i < m_numChoices; i++)
57 {
58 if (strcmp(resultString, m_enumValues[i]) == 0)
59 {
60 if (!m_changed) // don't change parameter that's been set in code
61 {
62 m_value = i;
63 }
64 }
65 }
66}
67