Skip to content

Commit 7501b70

Browse files
committed
Code reformatting
1 parent 7c3b061 commit 7501b70

32 files changed

+364
-324
lines changed

Ev3LangScala/src/ev3dev4s/JarRunner.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ object JarRunner {
4141
}
4242

4343
@tailrec
44-
def runIt(jarFile:Path,className:String):Unit = {
44+
def runIt(jarFile: Path, className: String): Unit = {
4545
try {
4646
Log.log(s"Start run() of $className from $jarFile")
4747
val classLoader = new URLClassLoader(Array(jarFile.toUri.toURL))
4848
classLoader.loadClass(className + "$").getField("MODULE$").get(Array.empty[Object]).asInstanceOf[Runnable].run()
4949
}
5050
catch {
5151
case x: Throwable =>
52-
Log.log("Caught in top-level",x)
52+
Log.log("Caught in top-level", x)
5353
MotorPortScanner.stopAllMotors()
5454
Ev3Led.writeBothRed()
5555
Lcd.clear()
5656
x.getMessage.grouped(11).take(3).zipWithIndex.foreach { chunk =>
5757
Lcd.set(chunk._2, chunk._1)
5858
}
59-
Lcd.set(3,"Push Button")
59+
Lcd.set(3, "Push Button")
6060
Lcd.flush()
6161
Sound.playTone(55.Hz, 200.milliseconds)
6262
Ev3KeyPad.blockUntilAnyKey()

Ev3LangScala/src/ev3dev4s/Log.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import java.io.PrintStream
1111
object Log {
1212
private val logStream: PrintStream = Option(System.getProperty("logFile")).map(new PrintStream(_)).getOrElse(System.out)
1313

14-
def log(text: String): Unit = logStream.println(s"${System.currentTimeMillis()} $text")
14+
def log(text: String): Unit = logStream.println(s"${System.currentTimeMillis()} $text")
1515

1616
def log(text: String, x: Throwable): Unit = {
1717
logStream.println(s"${System.currentTimeMillis()} $text")
1818
x.printStackTrace(logStream)
1919
}
20+
2021
}

Ev3LangScala/src/ev3dev4s/actuators/Ev3Led.scala

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,44 @@ import ev3dev4s.scala2measure.Conversions._
1212
* @author David Walend
1313
*/
1414

15-
sealed case class Ev3Led(side:Int) extends AutoCloseable {
16-
import ev3dev4s.actuators.Ev3Led.{Color,brightest, darkest,Off,Red,Green,Yellow}
15+
sealed case class Ev3Led(side: Int) extends AutoCloseable {
16+
17+
import ev3dev4s.actuators.Ev3Led.{Color, brightest, darkest, Off, Red, Green, Yellow}
1718

1819
val rootName = "/sys/class"
1920
//noinspection SpellCheckingInspection
2021
val redName = s"leds/led$side:red:brick-status/brightness"
2122
//noinspection SpellCheckingInspection
2223
val greenName = s"leds/led$side:green:brick-status/brightness"
2324

24-
private val redPath = Path.of (rootName, redName)
25-
private val greenPath = Path.of (rootName, greenName)
25+
private val redPath = Path.of(rootName, redName)
26+
private val greenPath = Path.of(rootName, greenName)
2627

27-
private val redWriter: ChannelRewriter = ChannelRewriter (redPath)
28-
private val greenWriter: ChannelRewriter = ChannelRewriter (greenPath)
28+
private val redWriter: ChannelRewriter = ChannelRewriter(redPath)
29+
private val greenWriter: ChannelRewriter = ChannelRewriter(greenPath)
2930
//todo add readers to read brightness from the same paths maybe someday - it will work, not sure if it has any value
3031

31-
def writeBrightness (red: LedIntensity, green: LedIntensity): Unit = this.synchronized {
32-
redWriter.writeAsciiInt (red.round)
33-
greenWriter.writeAsciiInt (green.round)
32+
def writeBrightness(red: LedIntensity, green: LedIntensity): Unit = this.synchronized {
33+
redWriter.writeAsciiInt(red.round)
34+
greenWriter.writeAsciiInt(green.round)
3435
}
3536

36-
override def close (): Unit = this.synchronized {
37-
redWriter.close ()
38-
greenWriter.close ()
37+
override def close(): Unit = this.synchronized {
38+
redWriter.close()
39+
greenWriter.close()
3940
}
4041

41-
def writeColor(color:Color) = {
42-
writeBrightness(color.red,color.green)
42+
def writeColor(color: Color): Unit = {
43+
writeBrightness(color.red, color.green)
4344
}
4445

45-
def writeOff (): Unit = writeColor(Off)
46-
def writeRed (): Unit = writeColor(Red)
47-
def writeGreen (): Unit = writeColor(Green)
48-
def writeYellow (): Unit = writeColor(Yellow)
46+
def writeOff(): Unit = writeColor(Off)
47+
48+
def writeRed(): Unit = writeColor(Red)
49+
50+
def writeGreen(): Unit = writeColor(Green)
51+
52+
def writeYellow(): Unit = writeColor(Yellow)
4953
}
5054

5155
object Ev3Led {
@@ -57,10 +61,10 @@ object Ev3Led {
5761

5862
case class Color(red: LedIntensity, green: LedIntensity)
5963

60-
val Red: Color = Color(brightest,darkest)
61-
val Yellow: Color = Color(brightest,brightest)
62-
val Green: Color = Color(darkest,brightest)
63-
val Off: Color = Color(darkest,darkest)
64+
val Red: Color = Color(brightest, darkest)
65+
val Yellow: Color = Color(brightest, brightest)
66+
val Green: Color = Color(darkest, brightest)
67+
val Off: Color = Color(darkest, darkest)
6468

6569
def writeBothGreen(): Unit = writeBothColor(Green)
6670

@@ -81,17 +85,17 @@ object Ev3Led {
8185
* Yellow Red
8286
* Yellow Off
8387
* */
84-
def writeBothColor(leftColor:Color,rightColor:Color):Unit = {
88+
def writeBothColor(leftColor: Color, rightColor: Color): Unit = {
8589
Left.writeColor(leftColor)
8690
Right.writeColor(rightColor)
8791
}
8892

89-
def writeBothColor(colors:(Color,Color)): Unit = {
93+
def writeBothColor(colors: (Color, Color)): Unit = {
9094
Left.writeColor(colors._1)
9195
Right.writeColor(colors._2)
9296
}
9397

94-
def writeBothColor(color:Color):Unit = {
95-
writeBothColor(color,color)
98+
def writeBothColor(color: Color): Unit = {
99+
writeBothColor(color, color)
96100
}
97101
}

Ev3LangScala/src/ev3dev4s/actuators/Motor.scala

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import ev3dev4s.scala2measure.MilliSeconds
1616
* @author David Walend
1717
* @since v0.0.0
1818
*/
19-
sealed abstract class Motor(port: MotorPort,motorFS:Option[MotorFS]) extends Gadget(port,motorFS){
19+
sealed abstract class Motor(port: MotorPort, motorFS: Option[MotorFS]) extends Gadget(port, motorFS) {
2020

21-
def writeCommand(command: MotorCommand):Unit = checkPort(_.writeCommand(command))
21+
def writeCommand(command: MotorCommand): Unit = checkPort(_.writeCommand(command))
2222

23-
def writeStopAction(command:MotorStopCommand):Unit = checkPort(_.writeStopAction(command))
23+
def writeStopAction(command: MotorStopCommand): Unit = checkPort(_.writeStopAction(command))
2424

25-
def writeDutyCycle(dutyCycle:DutyCycle):Unit = checkPort(_.writeDutyCycle(dutyCycle))
25+
def writeDutyCycle(dutyCycle: DutyCycle): Unit = checkPort(_.writeDutyCycle(dutyCycle))
2626

27-
def maxSpeed:DegreesPerSecond
27+
def maxSpeed: DegreesPerSecond
2828

29-
def observedMaxSpeed:DegreesPerSecond
29+
def observedMaxSpeed: DegreesPerSecond
3030

31-
def writeSpeed(speed:DegreesPerSecond):Unit = {
32-
val safeSpeed = if(speed.abs < maxSpeed ) speed
31+
def writeSpeed(speed: DegreesPerSecond): Unit = {
32+
val safeSpeed = if (speed.abs < maxSpeed) speed
3333
else {
3434
Log.log(s"requested speed $speed is greater than $maxSpeed - using $maxSpeed")
3535
(speed.sign * maxSpeed).degreesPerSecond
@@ -45,25 +45,25 @@ sealed abstract class Motor(port: MotorPort,motorFS:Option[MotorFS]) extends Gad
4545
checkPort(_.writeRampDownSpeed(fromMaxToZero))
4646
}
4747

48-
def writePosition(degrees:Degrees):Unit = checkPort(_.writePosition(degrees))
48+
def writePosition(degrees: Degrees): Unit = checkPort(_.writePosition(degrees))
4949

50-
def resetPosition():Unit = writePosition(0.degrees)
50+
def resetPosition(): Unit = writePosition(0.degrees)
5151

52-
def writeGoalPosition(degrees:Degrees):Unit = checkPort(_.writeGoalPosition(degrees))
52+
def writeGoalPosition(degrees: Degrees): Unit = checkPort(_.writeGoalPosition(degrees))
5353

54-
def writeDuration(milliseconds:MilliSeconds):Unit = checkPort(_.writeDuration(milliseconds))
54+
def writeDuration(milliseconds: MilliSeconds): Unit = checkPort(_.writeDuration(milliseconds))
5555

5656
/**
5757
* @return position in degrees
5858
*/
59-
def readPosition():Degrees = checkPort(_.readPosition())
59+
def readPosition(): Degrees = checkPort(_.readPosition())
6060

6161
def readState(): Array[MotorState] = checkPort(_.readState())
6262

63-
def readIsStalled():Boolean =
63+
def readIsStalled(): Boolean =
6464
readState().contains(MotorState.STALLED)
6565

66-
def readIsRunning():Boolean =
66+
def readIsRunning(): Boolean =
6767
readState().contains(MotorState.RUNNING)
6868

6969
def coast(): Unit = {
@@ -75,40 +75,42 @@ sealed abstract class Motor(port: MotorPort,motorFS:Option[MotorFS]) extends Gad
7575
writeStopAction(MotorStopCommand.BRAKE)
7676
writeCommand(MotorCommand.STOP)
7777
}
78+
7879
def hold(): Unit = {
7980
writeStopAction(MotorStopCommand.HOLD)
8081
writeCommand(MotorCommand.STOP)
8182
}
82-
def runDutyCycle(dutyCycle:DutyCycle):Unit = {
83+
84+
def runDutyCycle(dutyCycle: DutyCycle): Unit = {
8385
writeDutyCycle(dutyCycle)
8486
writeCommand(MotorCommand.RUN_DIRECT)
8587
}
8688

87-
def run(speed:DegreesPerSecond):Unit = {
89+
def run(speed: DegreesPerSecond): Unit = {
8890
writeSpeed(speed)
8991
writeCommand(MotorCommand.RUN)
9092
}
9193

92-
def runToAbsolutePosition(speed:DegreesPerSecond,degrees:Degrees):Unit = {
94+
def runToAbsolutePosition(speed: DegreesPerSecond, degrees: Degrees): Unit = {
9395
writeSpeed(speed)
9496
writeGoalPosition(degrees)
9597
writeCommand(MotorCommand.RUN_TO_ABSOLUTE_POSITION)
9698
}
9799

98-
def runToRelativePosition(speed:DegreesPerSecond,degrees:Degrees):Unit = {
100+
def runToRelativePosition(speed: DegreesPerSecond, degrees: Degrees): Unit = {
99101
writeSpeed(speed)
100102
writeGoalPosition(degrees)
101103
writeCommand(MotorCommand.RUN_TO_RELATIVE_POSITION)
102104
}
103105

104-
def runForDuration(speed:DegreesPerSecond,milliseconds:MilliSeconds):Unit = {
106+
def runForDuration(speed: DegreesPerSecond, milliseconds: MilliSeconds): Unit = {
105107
writeSpeed(speed)
106108
writeDuration(milliseconds)
107109
writeCommand(MotorCommand.RUN_TIME)
108110
}
109111
}
110112

111-
sealed case class Ev3LargeMotor(override val port:MotorPort, md: Option[MotorFS]) extends Motor(port,md) {
113+
sealed case class Ev3LargeMotor(override val port: MotorPort, md: Option[MotorFS]) extends Motor(port, md) {
112114
override def findGadgetFS(): Option[MotorFS] =
113115
MotorPortScanner.findGadgetDir(port, Ev3LargeMotor.driverName)
114116
.map(MotorFS)
@@ -121,7 +123,7 @@ object Ev3LargeMotor {
121123
val driverName = "lego-ev3-l-motor"
122124
}
123125

124-
sealed case class Ev3MediumMotor(override val port:MotorPort, md: Option[MotorFS]) extends Motor(port,md) {
126+
sealed case class Ev3MediumMotor(override val port: MotorPort, md: Option[MotorFS]) extends Motor(port, md) {
125127
override def findGadgetFS(): Option[MotorFS] =
126128
MotorPortScanner.findGadgetDir(port, Ev3MediumMotor.driverName)
127129
.map(MotorFS)
@@ -134,7 +136,7 @@ object Ev3MediumMotor {
134136
val driverName = "lego-ev3-m-motor"
135137
}
136138

137-
sealed case class MotorCommand(command:String)
139+
sealed case class MotorCommand(command: String)
138140

139141
object MotorCommand {
140142
/**
@@ -148,11 +150,11 @@ object MotorCommand {
148150
val RUN_TO_ABSOLUTE_POSITION: MotorCommand = MotorCommand("run-to-abs-pos")
149151

150152
/**
151-
run-to-rel-pos: Runs the motor to a position relative to the current position v. The new position will be current position + position_sp. When the new position is reached, the motor will stop using the command specified by stop_action. */
153+
* run-to-rel-pos: Runs the motor to a position relative to the current position v. The new position will be current position + position_sp. When the new position is reached, the motor will stop using the command specified by stop_action. */
152154
val RUN_TO_RELATIVE_POSITION: MotorCommand = MotorCommand("run-to-rel-pos")
153155

154156
/**
155-
run-timed: Run the motor for the amount of time specified in time_sp and then stops the motor using the command specified by stop_action.
157+
* run-timed: Run the motor for the amount of time specified in time_sp and then stops the motor using the command specified by stop_action.
156158
*/
157159
val RUN_TIME: MotorCommand = MotorCommand("run-timed")
158160

@@ -166,15 +168,16 @@ object MotorCommand {
166168
val STOP: MotorCommand = MotorCommand("stop")
167169

168170
/**
169-
reset: Resets all of the motor parameter attributes to their default values. This will also have the effect of stopping the motor.
171+
* reset: Resets all of the motor parameter attributes to their default values. This will also have the effect of stopping the motor.
170172
*/
171173
}
174+
172175
/**
173176
* Determines the motors behavior when command is set to stop. Possible values are:
174177
*/
175-
sealed case class MotorStopCommand(command:String)
178+
sealed case class MotorStopCommand(command: String)
176179

177-
object MotorStopCommand{
180+
object MotorStopCommand {
178181
/**
179182
* Removes power from the motor. The motor will freely coast to a stop.
180183
*/
@@ -191,29 +194,29 @@ object MotorStopCommand{
191194
val HOLD: MotorStopCommand = MotorStopCommand("hold")
192195
}
193196

194-
sealed case class MotorState(name:String)
197+
sealed case class MotorState(name: String)
195198

196-
object MotorState{
199+
object MotorState {
197200
/**
198-
running: Power is being sent to the motor.
201+
* running: Power is being sent to the motor.
199202
*/
200203
val RUNNING: MotorState = MotorState("running")
201204
/**
202-
ramping: The motor is ramping up or down and has not yet reached a constant output level.
205+
* ramping: The motor is ramping up or down and has not yet reached a constant output level.
203206
*/
204207
val RAMPING: MotorState = MotorState("ramping")
205208
/**
206-
holding: The motor is not turning, but rather attempting to hold a fixed position.
209+
* holding: The motor is not turning, but rather attempting to hold a fixed position.
207210
*/
208211
val HOLDING: MotorState = MotorState("holding")
209212
/**
210-
overloaded: The motor is turning as fast as possible, but cannot reach its speed_sp.
213+
* overloaded: The motor is turning as fast as possible, but cannot reach its speed_sp.
211214
*/
212215
val OVERLOADED: MotorState = MotorState("overloaded")
213216
/**
214-
stalled: The motor is trying to run but is not turning at all.
217+
* stalled: The motor is trying to run but is not turning at all.
215218
*/
216219
val STALLED: MotorState = MotorState("stalled")
217220

218-
val values: Array[MotorState] = Array(RUNNING,RAMPING,HOLDING,OVERLOADED,STALLED)
221+
val values: Array[MotorState] = Array(RUNNING, RAMPING, HOLDING, OVERLOADED, STALLED)
219222
}

0 commit comments

Comments
 (0)