Skip to content

Commit

Permalink
Big Update!
Browse files Browse the repository at this point in the history
 - Annotation processor works now, and now also makes sure it can access fields/properties
 - CommandScheduler is now a singleton! This allows for a lot of helpful features
 - CommandInterface allows easy access to CommandScheduler
 - New CommandOpMode in case you don't like using Robots
 - Fixes to SuperTelemetry
 - Robot no longer needs an OpMode as a constructor parameter
 - Motor gearRatio and distancePerOutputRev separated, allowing for setTargetAngle and goToAngle
 - New Motor.Kind for easy construction
 - Servo range set to 300 degrees by default because all the goBILDA servos have that range
 - command module now requires minSdkVersion of 24
  • Loading branch information
amarcolini committed Jun 3, 2022
1 parent 9e65a6a commit d88ac2c
Show file tree
Hide file tree
Showing 29 changed files with 755 additions and 212 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
}
dependencies {
implementation "com.github.amarcolini.joos:$module:0.4.5-alpha"
implementation "com.github.amarcolini.joos:$module:0.4.6-alpha"
}
```

Expand All @@ -52,6 +52,6 @@ java {
dependencies {
//Gradle will automatically retrieve the correct dependencies based on your operating system
implementation "com.github.amarcolini.joos:gui:0.4.5-alpha"
implementation "com.github.amarcolini.joos:gui:0.4.6-alpha"
}
````
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
kotlin_version = "1.6.21"
lib_version = "0.4.5-alpha"
lib_version = "0.4.6-alpha"
}

repositories {
Expand Down
9 changes: 3 additions & 6 deletions command/annotation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
plugins {
id "kotlin"
id "java"
id 'com.google.devtools.ksp' version '1.6.21-1.0.5'
id 'maven-publish'
}

Expand All @@ -17,6 +15,8 @@ compileKotlin {
}
}

group = group + ".command"

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
Expand All @@ -25,9 +25,6 @@ dependencies {

implementation "com.squareup:javapoet:1.13.0"
implementation "com.squareup:kotlinpoet:1.11.0"

ksp 'com.google.auto.service:auto-service:1.0.1'
implementation 'com.google.auto.service:auto-service-annotations:1.0.1'
}

publishing {
Expand All @@ -52,7 +49,7 @@ publishing {
repositories {
maven {
name = 'testRepo'
url = '../testRepo'
url = '../../testRepo'
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.amarcolini.joos.dashboard

import com.google.auto.service.AutoService
import com.squareup.javapoet.*
import com.squareup.kotlinpoet.asTypeName
import java.util.*
import javax.annotation.processing.*
import javax.lang.model.SourceVersion
import javax.lang.model.element.*
import kotlin.collections.ArrayList

@AutoService(Processor::class)
@SupportedSourceVersion(SourceVersion.RELEASE_8)
class ConfigProcessor : AbstractProcessor() {
private val results = ArrayList<Pair<String, Pair<String, String>>>()
Expand Down Expand Up @@ -64,9 +61,10 @@ class ConfigElementVisitor : ElementVisitor<List<Pair<String, Pair<String, Strin
emptyList()

override fun visitType(p0: TypeElement?, p1: TypeElement?): List<Pair<String, Pair<String, String>>> {
if (p0?.modifiers?.contains(Modifier.PUBLIC) != true) return emptyList()
val configMembers = ArrayList<Pair<String, Pair<String, String>>>()
val name = getAltName(p0, p1) ?: p0?.simpleName.toString()
p0?.enclosedElements?.forEach { member ->
val name = getAltName(p0, p1) ?: p0.simpleName.toString()
p0.enclosedElements?.forEach { member ->
if (member.kind == ElementKind.FIELD && member.modifiers.containsAll(
listOf(
Modifier.PUBLIC, Modifier.STATIC
Expand Down Expand Up @@ -98,6 +96,7 @@ class ConfigElementVisitor : ElementVisitor<List<Pair<String, Pair<String, Strin
}
}
val parent = possibleParent ?: return emptyList()
if (!parent.modifiers.contains(Modifier.PUBLIC)) return emptyList()
return listOf(
(getAltName(p0, p1) ?: getAltName(parent, p1)
?: parent.simpleName.toString()) to (parent.qualifiedName.toString() to p0.simpleName.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.amarcolini.joos.dashboard

import com.google.auto.service.AutoService
import com.google.devtools.ksp.*
import com.google.devtools.ksp.processing.*
import com.google.devtools.ksp.symbol.*
import com.google.devtools.ksp.visitor.KSEmptyVisitor
import com.squareup.kotlinpoet.*
import kotlin.reflect.KProperty0
import kotlin.io.*
import kotlin.reflect.KClass

class ConfigSymbolProcessor(
private val environment: SymbolProcessorEnvironment,
Expand Down Expand Up @@ -79,6 +77,7 @@ class ConfigSymbolProcessor(
inner class ConfigVisitor : KSEmptyVisitor<Resolver, Unit>() {
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Resolver) {
processedClasses += classDeclaration
if (!classDeclaration.modifiers.contains(Modifier.PUBLIC)) return
when (classDeclaration.classKind) {
ClassKind.INTERFACE, ClassKind.ENUM_CLASS, ClassKind.ENUM_ENTRY, ClassKind.ANNOTATION_CLASS -> return
ClassKind.OBJECT -> {
Expand Down Expand Up @@ -112,6 +111,7 @@ class ConfigSymbolProcessor(
if (closestClass?.classKind != ClassKind.OBJECT && !property.modifiers.contains(Modifier.JAVA_STATIC)) return
val parentClass =
if (closestClass?.isCompanionObject == true) closestClass.parentDeclaration as KSClassDeclaration else closestClass
if (!property.isPublic()) return
val name = property.qualifiedName ?: return
val parentClassName = parentClass?.simpleName?.asString()?.ifEmpty { null }
val parentClassAltName = parentClass?.let { getAltName(it)?.ifEmpty { null } }
Expand All @@ -133,7 +133,6 @@ class ConfigSymbolProcessor(
}
}

@AutoService(SymbolProcessorProvider::class)
class ConfigSymbolProcessorProvider : SymbolProcessorProvider {
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
return ConfigSymbolProcessor(environment)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.amarcolini.joos.dashboard.ConfigSymbolProcessorProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.amarcolini.joos.dashboard.ConfigProcessor
2 changes: 1 addition & 1 deletion command/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
test.java.srcDirs += 'src/test/kotlin'
}
defaultConfig {
minSdkVersion 23
minSdkVersion 24
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@ package com.amarcolini.joos.command
* An abstract version of [Component] with more quality of life features.
*/
abstract class AbstractComponent : Component {
/**
* The scheduler currently using this component.
*/
var scheduler: CommandScheduler? = null
internal set(value) {
subcomponents.forEach {
if (it is AbstractComponent) it.scheduler = value
}
field = value
}

/**
* A list of subcomponents that this component may use. All subcomponents are
* updated as well, as long as there is a call to `super.update()`.
*/
@JvmField
protected val subcomponents: MutableList<Component> = ArrayList()
protected val subcomponents: MutableSet<Component> = HashSet()

override fun update() {
subcomponents.forEach { it.update() }
Expand Down
Loading

2 comments on commit d88ac2c

@omagarwal25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing! I'm going to be working on a feature soon where you can pass in an updater for SuperTelemetry. I made a wrapper this year where you could just do RobotTelemetry.addData("name") { motor.power } and it automatically updates every cycle.

@amarcolini
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s really neat. I think the OpMode telemetry already has something like this, so I’ll see what I can do.

Please sign in to comment.