mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-02 10:24:11 +01:00
Make the initial values for enums be the string. Make setValue accept
numerical or string constants for enums. Only returns a string though.
This commit is contained in:
parent
72de0c622a
commit
6758d5c598
@ -343,8 +343,14 @@ public class UAVObjectField {
|
||||
break;
|
||||
}
|
||||
case ENUM:
|
||||
{
|
||||
byte val = (byte) options.indexOf((String) data);
|
||||
{
|
||||
byte val;
|
||||
try {
|
||||
// Test if numeric constant passed in
|
||||
val = ((Number) data).byteValue();
|
||||
} catch (Exception e) {
|
||||
val = (byte) options.indexOf((String) data);
|
||||
}
|
||||
//if(val < 0) throw new Exception("Enumerated value not found");
|
||||
List<Byte> l = (List<Byte>) this.data;
|
||||
l.set(index, val);
|
||||
|
@ -210,9 +210,9 @@ bool UAVObjectGeneratorJava::process_object(ObjectInfo* info)
|
||||
{
|
||||
if ( info->fields[n]->type == FIELDTYPE_ENUM )
|
||||
{
|
||||
initfields.append( QString("\t\tgetField(\"%1\").setValue(%2);\n")
|
||||
initfields.append( QString("\t\tgetField(\"%1\").setValue(\"%2\");\n")
|
||||
.arg( info->fields[n]->name )
|
||||
.arg( info->fields[n]->options.indexOf( info->fields[n]->defaultValues[0] ) ) );
|
||||
.arg( info->fields[n]->defaultValues[0] ) );
|
||||
}
|
||||
else if ( info->fields[n]->type == FIELDTYPE_FLOAT32 )
|
||||
{
|
||||
@ -233,10 +233,10 @@ bool UAVObjectGeneratorJava::process_object(ObjectInfo* info)
|
||||
for (int idx = 0; idx < info->fields[n]->numElements; ++idx)
|
||||
{
|
||||
if ( info->fields[n]->type == FIELDTYPE_ENUM ) {
|
||||
initfields.append( QString("\t\tgetField(\"%1\").setValue(%3,%2);\n")
|
||||
initfields.append( QString("\t\tgetField(\"%1\").setValue(\"%3\",%2);\n")
|
||||
.arg( info->fields[n]->name )
|
||||
.arg( idx )
|
||||
.arg( info->fields[n]->options.indexOf( info->fields[n]->defaultValues[idx] ) ) );
|
||||
.arg( info->fields[n]->defaultValues[idx] ) );
|
||||
}
|
||||
else if ( info->fields[n]->type == FIELDTYPE_FLOAT32 ) {
|
||||
initfields.append( QString("\t\tgetField(\"%1\").setValue(%3,%2);\n")
|
||||
|
Loading…
Reference in New Issue
Block a user