-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More deck-chair shuffling, as well as a failed attempt to use a stepper as a lift driver without limit switches (and noisy af, as well).
- Loading branch information
1 parent
cfb2dff
commit 70477e2
Showing
9 changed files
with
434 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
armthing/src/main/kotlin/crackers/kobots/app/arm/LiftStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2022-2024 by E. A. Graham, Jr. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package crackers.kobots.app.arm | ||
|
||
import com.diozero.devices.oled.MonochromeSsdOled | ||
import com.diozero.devices.oled.SH1106 | ||
import com.diozero.devices.oled.SSD1306 | ||
import com.diozero.devices.oled.SsdOledCommunicationChannel | ||
import crackers.kobots.app.multiplexor | ||
import crackers.kobots.graphics.toRadians | ||
import crackers.kobots.graphics.widgets.VerticalPercentageIndicator | ||
import java.awt.Font | ||
import java.awt.Graphics2D | ||
import java.awt.geom.AffineTransform | ||
import java.awt.image.BufferedImage | ||
|
||
/** | ||
* Displays the lift status (0-100 percent) on a rotated 132x32 display. | ||
*/ | ||
object LiftStatus { | ||
private val DISPLAY_HEIGHT = MonochromeSsdOled.Height.SHORT.lines | ||
|
||
private val screen: SSD1306 by lazy { | ||
val i2CDevice = multiplexor.getI2CDevice(2, SH1106.DEFAULT_I2C_ADDRESS) | ||
val channel = SsdOledCommunicationChannel.I2cCommunicationChannel(i2CDevice) | ||
SSD1306(channel, MonochromeSsdOled.Height.SHORT).apply { setContrast(0f) } | ||
} | ||
private var ready = false | ||
private var screenOn = false | ||
|
||
// set up the vertical thingie and then rotate it to display | ||
val rotatedGraphics: Graphics2D | ||
val rotatedImage = | ||
BufferedImage(MonochromeSsdOled.DEFAULT_WIDTH, DISPLAY_HEIGHT, BufferedImage.TYPE_BYTE_BINARY).also { | ||
rotatedGraphics = (it.graphics as Graphics2D).apply { | ||
val theRotation = AffineTransform().apply { | ||
rotate(-90.toRadians()) | ||
translate(-DISPLAY_HEIGHT.toDouble(), 0.0) | ||
} | ||
transform(theRotation) | ||
} | ||
} | ||
val vpd = VerticalPercentageIndicator( | ||
rotatedGraphics, | ||
Font(Font.SANS_SERIF, Font.BOLD, 10), | ||
MonochromeSsdOled.DEFAULT_WIDTH, | ||
label = "Lift" | ||
) | ||
|
||
fun update(percent: Int) { | ||
if (!ready) { | ||
vpd.drawStatic() | ||
ready = true | ||
} | ||
if (!screenOn) { | ||
screen.setDisplayOn(true) | ||
screenOn = true | ||
} | ||
vpd.updateValue(percent) | ||
screen.display(rotatedImage) | ||
} | ||
|
||
fun sleep() { | ||
screenOn = false | ||
screen.setDisplayOn(false) | ||
screen.clear() | ||
} | ||
|
||
fun close() { | ||
sleep() | ||
screen.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.