Fix stored int offset bug

This commit is contained in:
Astatin3
2024-09-14 18:02:31 -06:00
parent 6eff9179f4
commit 4f4c39bc92
14 changed files with 124 additions and 74 deletions
@@ -26,9 +26,11 @@ public class ScoutingDataWriter {
switch (data[i].getValueType()){
case NUM:
bb.addInt((int) data[i].forceGetValue());
System.out.println("Saved INT: " + data[i].getName() + ", ("+ data[i].get() +")");
break;
case STRING:
bb.addString((String) data[i].forceGetValue());
System.out.println("Saved STR: " + data[i].getName() + ", ("+ data[i].get() +")");
break;
}
}
@@ -64,12 +66,12 @@ public class ScoutingDataWriter {
case 1: // Int
dataTypes[i] = intType.newNull(values[version][i].name);
dataTypes[i].forceSetValue(objects.get(i+2).get());
//System.out.println("Loaded INT: " + values[version][i].name + ", ("+ dataTypes[i].get() +")");
System.out.println("Loaded INT: " + values[version][i].name + ", ("+ dataTypes[i].get() +")");
break;
case 2: // String
dataTypes[i] = stringType.newNull(values[version][i].name);
dataTypes[i].forceSetValue(objects.get(i+2).get());
//System.out.println("Loaded STR: " + values[version][i].name + ", ("+ dataTypes[i].get() +")");
System.out.println("Loaded STR: " + values[version][i].name + ", ("+ dataTypes[i].get() +")");
break;
}
}
@@ -23,28 +23,28 @@ public class fields {
public static final inputType[][] default_match_fields = new inputType[][] {
{
new tallyType("Auto Notes", 0),
new sliderType("Auto Performance", 5, 1, 10),
new textType("Auto Comments", "None"),
new sliderType("Auto Performance", 5, 0, 10),
new textType("Auto Comments", ""),
new tallyType("Teleop Notes", 0),
new sliderType("Teleop Performance", 5, 1, 10),
new textType("Teleop Comments", "None"),
new sliderType("Overall Driving Performance", 5, 1, 10),
new textType("Overall Driving Comments", "None"),
new sliderType("Score area (AMP <-> Speaker)", 5, 1, 10),
new dropdownType("End Condition", new String[]{"Nothing", "Attempted Climb", "Successful Climbed", "Climbed with multiple robots", "Climbed with trap"}, 1),
new dropdownType("Robot Condition", new String[]{"Everything was working", "Something seemed to be broken", "Something was broken", "Missing robot (Joe Johnson)"}, 1),
new textType("Other Comments", "None")
new sliderType("Teleop Performance", 5, 0, 10),
new textType("Teleop Comments", ""),
new sliderType("Overall Driving Performance", 5, 0, 10),
new textType("Overall Driving Comments", ""),
new sliderType("Score area (AMP <-> Speaker)", 5, 0, 10),
new dropdownType("End Condition", new String[]{"Nothing", "Attempted Climb", "Successful Climbed", "Climbed with multiple robots", "Climbed with trap"}, 0),
new dropdownType("Robot Condition", new String[]{"Everything was working", "Something seemed to be broken", "Something was broken", "Missing robot (Joe Johnson)"}, 0),
new textType("Other Comments", "")
}
};
public static final inputType[][] default_pit_fields = new inputType[][] {
{
new sliderType("How good is robot", 5, 0, 10),
new textType("notes", "<no-notes>"),
new textType("notes", ""),
},{
new sliderType("How good is robot", 5, 0, 10),
new sliderType("Test", 1, 0, 10),
new textType("notes", "<no-notes>"),
new textType("notes", ""),
}
};
@@ -88,11 +88,9 @@ public class fields {
return values;
// return true;
} catch (Exception e) {
AlertManager.error(e);
return null;
// return false;
}
}
@@ -82,9 +82,9 @@ public class ScoutingArray {
inputType it = get_input_type_by_name(version+1, tv.name);
switch (it.getValueType()){
case NUM:
return new intType(it.name, (int) it.default_value);
return intType.newNull(it.name);
case STRING:
return new stringType(it.name, (String) it.default_value);
return stringType.newNull(it.name);
}
return null;
}
@@ -21,7 +21,7 @@ public abstract class dataType {
// public abstract Object getUnselectedValue();
public abstract boolean isNull();
public abstract boolean isUnselected();
// public abstract boolean isUnselected();
public String getName() {return name;}
@@ -1,9 +1,8 @@
package com.astatin3.scoutingapp2025.types.data;
public class intType extends dataType {
public static final int nullval = 0;
public static final int unselectedval = 1;
public static final int offset = 2;
public static final int nullval = 255;
// public static final int unselectedval = 1;
public valueTypes getValueType() {
return valueTypes.NUM;
@@ -17,11 +16,11 @@ public class intType extends dataType {
// }
public Object get(){
return (int) forceGetValue()-2;
return (int) forceGetValue();
}
public void set(Object value){
forceSetValue((int) value + 2);
forceSetValue((int) value);
}
public intType(String name, int value) {
@@ -35,11 +34,11 @@ public class intType extends dataType {
return a;
}
public static intType newUnselected(String name){
final intType a = new intType(name, 0);
a.forceSetValue(unselectedval);
return a;
}
// public static intType newUnselected(String name){
// final intType a = new intType(name, 0);
// a.forceSetValue(unselectedval);
// return a;
// }
public static boolean isNull(int obj){
return obj == nullval;
@@ -48,10 +47,10 @@ public class intType extends dataType {
return isNull((int) forceGetValue());
}
public static boolean isUnselected(int obj){
return obj == unselectedval;
}
public boolean isUnselected() {
return isUnselected((int) forceGetValue());
}
// public static boolean isUnselected(int obj){
// return obj == unselectedval;
// }
// public boolean isUnselected() {
// return isUnselected((int) forceGetValue());
// }
}
@@ -1,8 +1,8 @@
package com.astatin3.scoutingapp2025.types.data;
public class stringType extends dataType{
public static final String nullval = "ƒ";
public static final String unselectedval = "";
public static final String nullval = "null";
// public static final String unselectedval = "■";
public valueTypes getValueType() {
return valueTypes.STRING;
@@ -34,11 +34,11 @@ public class stringType extends dataType{
return a;
}
public static stringType newUnselected(String name){
final stringType a = new stringType(name, "");
a.forceSetValue(unselectedval);
return a;
}
// public static stringType newUnselected(String name){
// final stringType a = new stringType(name, "");
// a.forceSetValue(unselectedval);
// return a;
// }
public static boolean isNull(String obj){
return obj.equals(nullval);
@@ -48,10 +48,10 @@ public class stringType extends dataType{
}
public static boolean isUnselected(String obj){
return obj.equals(unselectedval);
}
public boolean isUnselected() {
return isUnselected((String) forceGetValue());
}
// public static boolean isUnselected(String obj){
// return obj.equals(unselectedval);
// }
// public boolean isUnselected() {
// return isUnselected((String) forceGetValue());
// }
}
@@ -8,6 +8,7 @@ import android.widget.LinearLayout;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.astatin3.scoutingapp2025.types.data.dataType;
import com.astatin3.scoutingapp2025.ui.data.FieldEditorHelper;
import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder;
@@ -35,19 +36,6 @@ public abstract class inputType {
this.name = name;
}
// public enum parameterType {
// NUMBER,
// STRING,
// STRINGARRAY
// }
// public static parameterType[] parameterTypeByInputType(inputTypes t){
// switch (t){
// case SLIDER:
// return new parameterType[]{parameterType.NUMBER, };
// }
// }
public abstract String get_type_name();
public abstract byte[] encode() throws ByteBuilder.buildingException;
@@ -64,6 +52,48 @@ public abstract class inputType {
public abstract dataType getViewValue();
// private enum parameterTypeEnum {
// paramNumber,
// paramString,
// paramStringArray
// }
//
// public static class parameterType {
// public String name;
// public parameterTypeEnum id;
// }
//
// public static class paramNumber extends parameterType {
// public int val;
// public paramNumber(String name, int val){
// this.name = name + " (Number)";
// this.val = val;
// this.id = parameterTypeEnum.paramNumber;
// }
// }
//
// public static class paramString extends parameterType {
// public String val;
// public paramString(String name, String val){
// this.name = name + " (String)";
// this.val = val;
// this.id = parameterTypeEnum.paramString;
// }
// }
//
// public static class paramStringArray extends parameterType {
// public String[] val;
// public paramStringArray(String name, String[] val){
// this.name = name + " (String array)";
// this.val = val;
// this.id = parameterTypeEnum.paramStringArray;
// }
// }
// public abstract parameterType[] getDefaultParameters();
public abstract void add_individual_view(LinearLayout parent, dataType data);
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import com.astatin3.scoutingapp2025.types.data.dataType;
import com.astatin3.scoutingapp2025.types.data.intType;
import com.astatin3.scoutingapp2025.types.data.stringType;
import com.astatin3.scoutingapp2025.utility.AlertManager;
import com.astatin3.scoutingapp2025.utility.BuiltByteParser;
import com.astatin3.scoutingapp2025.utility.ByteBuilder;
import com.github.mikephil.charting.charts.LineChart;
@@ -91,8 +92,17 @@ public class sliderType extends inputType {
float step_size = (float) 1/(max-min);
int round_position = Math.round(slider_position / step_size);
isBlank = false;
float slidervalue = round_position*step_size;
if(slidervalue > 1 || slidervalue < 0) {
AlertManager.error("Error loading slider " + name);
slider.setValue(0);
}else{
slider.setValue(slidervalue);
}
slider.setVisibility(View.VISIBLE);
slider.setValue(round_position*step_size);
}
public dataType getViewValue(){
if(slider == null) return null;
@@ -116,9 +126,15 @@ public class sliderType extends inputType {
float slider_position = (float) ((int) data.get()-min) / (max-min);
float step_size = (float) 1/(max-min);
int round_position = Math.round(slider_position / step_size);
slider.setValue(round_position*step_size);
float value = round_position*step_size;
if(value > 1 || value < 0) {
AlertManager.error("Error loading slider " + name);
slider.setValue(0);
}else{
slider.setValue(value);
slider.setStepSize((float) 1 / (max-min));
}
slider.setStepSize((float) 1 / (max-min));
slider.setEnabled(false);
parent.addView(slider);
}
@@ -73,14 +73,14 @@ public class tallyType extends inputType {
public void setViewValue(Object value) {
if(tally == null) return;
System.out.println(value);
if((int)value == intType.nullval || (int)value == intType.unselectedval){
if(intType.isNull((int)value)){
nullify();
return;
}
isBlank = false;
tally.setVisibility(View.VISIBLE);
tally.setValue((int) value-2);
tally.setValue((int) value);
}
public void nullify(){
isBlank = true;
@@ -88,7 +88,7 @@ public class tallyType extends inputType {
}
public dataType getViewValue(){
if(tally == null) return null;
if(tally.getVisibility() == View.GONE) return new intType(name, 0);
if(tally.getVisibility() == View.GONE) return intType.newNull(name);
return new intType(name, tally.getValue());
}
@@ -1,7 +1,5 @@
package com.astatin3.scoutingapp2025.types.input;
import static com.astatin3.scoutingapp2025.types.data.intType.offset;
import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
@@ -340,7 +340,13 @@ public class MatchScoutingFragment extends Fragment {
for(int i = 0; i < DataManager.match_latest_values.length; i++){
// types[i] = latest_values[i].getViewValue();
DataManager.match_latest_values[i].setViewValue(types[i].get());
try {
DataManager.match_latest_values[i].setViewValue(types[i].get());
} catch (Exception e){
AlertManager.error(e);
DataManager.match_latest_values[i].setViewValue(DataManager.match_latest_values[i].default_value);
}
if(DataManager.match_latest_values[i].isBlank){
titles[i].setBackgroundColor(0xffff0000);
@@ -18,7 +18,7 @@ public class BuiltByteParser {
}
public static String unBlankStrNull(String str){
if(str.equals("null")){
if(str.equals("ƒ")){
return "";
}
else return str;
@@ -27,7 +27,7 @@ public class ByteBuilder {
public static String blankStrNull(String str){
if(str.isEmpty() || str.isEmpty()){
return "null";
return "ƒ";
}
else return str;
}