Skip to content

Commit

Permalink
Add missing Color methods, SDK color samples & Gamepad stub in OpModes
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Sep 27, 2024
1 parent 72fa9fd commit 3610615
Show file tree
Hide file tree
Showing 12 changed files with 984 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
/*
Copyright (c) 2016 Robert Atkinson
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted (subject to the limitations in the disclaimer below) provided that
the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of Robert Atkinson nor the names of his contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
Expand All @@ -26,6 +32,7 @@ are permitted (subject to the limitations in the disclaimer below) provided that
*/
package org.firstinspires.ftc.robotcore.external;

import androidx.annotation.Nullable;

import java.util.Locale;

Expand All @@ -43,12 +50,18 @@ are permitted (subject to the limitations in the disclaimer below) provided that
* telemetry.update();
* </pre>
*
* <p>In the 2015/16 season, the call to {@link #update()} was not required; now, however,
* in a LinearOpMode, unless {@link #update()} is called, nothing will appear on the
* driver station screen. In other, loop-based OpModes, {@link #update()} continues to be called
* automatically at the end of OpMode#loop() and OpMode#init_loop(); no call to
* {@link #update()} is required in loop-based OpModes.</p>
*
* <pre>
* // loop-based opmode
* // loop-based OpMode
* telemetry.addData("count", currentCount);
* telemetry.addData("elapsedTime", "%.3f", elapsedSeconds);
* </pre>
* <p>By default (but see {@link #setAutoClear(boolean) setAutoClear()}), data is cleared from the
* telemetry after each call to {@link #update()}; thus, you need to issue {@link #addData(String,
* Object) addData()} for the entire contents of the telemetry screen on each update cycle.
Expand All @@ -69,6 +82,7 @@ are permitted (subject to the limitations in the disclaimer below) provided that
* telemetry.update();
* ...
* }
* void anotherPartOfYourCode() {
* ...
* elapsedItem.setValue("%.3f", elapsedSeconds);
Expand Down Expand Up @@ -268,6 +282,30 @@ public interface Telemetry
*/
boolean removeAction(Object token);

//----------------------------------------------------------------------------------------------
// Text to Speech
//----------------------------------------------------------------------------------------------

/**
* Directs the Driver Station device to speak the given text using TextToSpeech functionality,
* with the same language and country codes that were previously used, or the default language
* and country.
*
* @param text the text to be spoken
*/
void speak(String text);

/**
* Directs the Driver Station device to speak the given text using TextToSpeech functionality,
* with the given language and country codes.
*
* @param text the text to be spoken
* @param languageCode an ISO 639 alpha-2 or alpha-3 language code, or a language subtag up to
* 8 characters in length
* @param countryCode an ISO 3166 alpha-2 country code, or a UN M.49 numeric-3 area code
*/
void speak(String text, String languageCode, String countryCode);

//----------------------------------------------------------------------------------------------
// Transmission
//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -339,7 +377,7 @@ interface Line
/**
* Instances of {@link Item} represent an item of data on the drive station telemetry display.
*
* @see {@link #addData(String, Object)}
* @see #addData(String, Object)
*/
interface Item
{
Expand Down Expand Up @@ -404,7 +442,7 @@ interface Item
* @see #clear()
* @see #isRetained()
*/
Item setRetained(Boolean retained);
Item setRetained(@Nullable Boolean retained);

/**
* Returns whether the item is to be retained in a clear() operation.
Expand Down Expand Up @@ -498,6 +536,30 @@ interface Item
*/
void setCaptionValueSeparator(String captionValueSeparator);

enum DisplayFormat
{
CLASSIC, // What you've all come to know and love (or not) since 2015
MONOSPACE, // Same as classic, except uses a monospaced font so you can column align data
HTML; // Allows use of a subset of HTML tags, enabling "rich text" display (e.g. color & size)
}

/**
* Sets the telemetry display format on the Driver Station. See the comments on {@link DisplayFormat}.
*
* @param displayFormat the telemetry display format the Driver Station should use
*/
void setDisplayFormat(DisplayFormat displayFormat);

/**
* Sets the number of decimal places for Double and Float
*
* @param minDecimalPlaces - the minimum number of places to show when Double or Float is passed in without a Format
* @param maxDecimalPlaces - the maximum number of places to show when Double or Float is passed in without a Format
*/
default void setNumDecimalPlaces(int minDecimalPlaces, int maxDecimalPlaces){
// does nothing just so we don't break existing Telemetry
}

//----------------------------------------------------------------------------------------------
// Properties
//----------------------------------------------------------------------------------------------
Expand All @@ -516,9 +578,9 @@ interface Log
enum DisplayOrder { NEWEST_FIRST, OLDEST_FIRST }

/**
* Returns the maximum number of lines which will be retained in a {@link #log()()} and
* Returns the maximum number of lines which will be retained in a {@link #log()} and
* shown on the driver station display.
* @return the maximum number of lines which will be retained in a {@link #log()()}
* @return the maximum number of lines which will be retained in a {@link #log()}
* @see #setCapacity(int)
*/
int getCapacity();
Expand Down Expand Up @@ -567,4 +629,4 @@ enum DisplayOrder { NEWEST_FIRST, OLDEST_FIRST }
* @see Log#addData(String, Object)
*/
Log log();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.firstinspires.ftc.robotcore.robocol;

/**
* Placeholder for telemetry message constants
*/
public class TelemetryMessage {

static final int cbTimestamp = 8;
static final int cbSorted = 1;
static final int cbRobotState = 1;
static final int cbTagLen = 1;
static final int cbCountLen = 1;
static final int cbKeyLen = 2;
static final int cbValueLen = 2;
static final int cbFloat = 4;

public final static int cbTagMax = (1 << (cbTagLen*8)) - 1;
public final static int cCountMax = (1 << (cbCountLen*8)) - 1;
public final static int cbKeyMax = (1 << (cbKeyLen*8)) - 1;
public final static int cbValueMax = (1 << (cbValueLen*8)) - 1;

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,22 @@ import com.github.serivesmejia.eocvsim.pipeline.util.PipelineSnapshot
import com.github.serivesmejia.eocvsim.util.ReflectUtil
import com.github.serivesmejia.eocvsim.util.StrUtil
import com.github.serivesmejia.eocvsim.util.event.EventHandler
import com.github.serivesmejia.eocvsim.util.exception.MaxActiveContextsException
import com.github.serivesmejia.eocvsim.util.fps.FpsCounter
import com.github.serivesmejia.eocvsim.util.loggerForThis
import io.github.deltacv.common.image.MatPoster
import io.github.deltacv.common.pipeline.util.PipelineStatisticsCalculator
import io.github.deltacv.eocvsim.virtualreflect.VirtualField
import io.github.deltacv.eocvsim.virtualreflect.VirtualReflectContext
import io.github.deltacv.eocvsim.virtualreflect.VirtualReflection
import io.github.deltacv.eocvsim.virtualreflect.jvm.JvmVirtualReflection
import kotlinx.coroutines.*
import org.firstinspires.ftc.robotcore.external.Telemetry
import org.firstinspires.ftc.robotcore.internal.opmode.TelemetryImpl
import org.firstinspires.ftc.robotcore.internal.opmode.EOCVSimTelemetryImpl
import org.firstinspires.ftc.vision.VisionProcessor
import org.opencv.core.Mat
import org.openftc.easyopencv.OpenCvPipeline
import org.openftc.easyopencv.OpenCvViewport
import org.openftc.easyopencv.processFrameInternal
import java.lang.RuntimeException
import java.lang.reflect.Constructor
import java.lang.reflect.Field
import java.util.*
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.math.roundToLong
Expand Down Expand Up @@ -202,7 +198,7 @@ class PipelineManager(
openedPipelineOutputCount++
}

if(telemetry is TelemetryImpl) {
if(telemetry is EOCVSimTelemetryImpl) {
telemetry.errItem.caption = "[/!\\]"
telemetry.errItem.setValue("Uncaught exception thrown, check Workspace -> Output.")
telemetry.forceTelemetryTransmission()
Expand All @@ -212,7 +208,7 @@ class PipelineManager(
pipelineExceptionTracker.onPipelineExceptionClear {
val telemetry = currentTelemetry

if(telemetry is TelemetryImpl) {
if(telemetry is EOCVSimTelemetryImpl) {
telemetry.errItem.caption = ""
telemetry.errItem.setValue("")
telemetry.forceTelemetryTransmission()
Expand Down Expand Up @@ -275,7 +271,7 @@ class PipelineManager(
}
}

if(telemetry is TelemetryImpl) {
if(telemetry is EOCVSimTelemetryImpl) {
if (compiledPipelineManager.isBuildRunning) {
telemetry.infoItem.caption = "[>]"
telemetry.infoItem.setValue("Building java files in workspace...")
Expand Down Expand Up @@ -581,7 +577,7 @@ class PipelineManager(
val instantiator = getInstantiatorFor(pipelineClass)

try {
nextTelemetry = TelemetryImpl().apply {
nextTelemetry = EOCVSimTelemetryImpl().apply {
// send telemetry updates to the ui
addTransmissionReceiver(eocvSim.visualizer.telemetryPanel)
}
Expand Down
Loading

0 comments on commit 3610615

Please sign in to comment.