Skip to content

Instantly share code, notes, and snippets.

@seth10
Created October 7, 2016 15:19
Show Gist options
  • Save seth10/84736ff67cca303f26d06f8e51351e08 to your computer and use it in GitHub Desktop.
Save seth10/84736ff67cca303f26d06f8e51351e08 to your computer and use it in GitHub Desktop.
A summary of how the coordinates for the battery indicator in the PiStorms browser were derived
# trial and error
scrn.fillRect(x=293, y=180, width=13, height=20, fill=batteryFill, display=False)
scrn.fillRect(x=293+3, y=180-3, width=13-3*2, height= 3, fill=batteryFill, display=False)
scrn.drawAutoText("%.1f V" % (mindsensors_i2c(0x34 >> 1).readByte(0x6E)*.040), xpos+width+(scrn.PS_SCREENHEIGHT-(xpos+width))/2, y=initialYpos+height*4-16, size=16, display=False)
# substituting with how I got these numbers
scrn.fillRect(x=xpos+width+(scrn.PS_SCREENHEIGHT-(xpos+width)-13)/2, y=initialYpos+height*4-16-1-20-5, width=13, height=20, fill=batteryFill, display=False)
scrn.fillRect(x=xpos+width+(scrn.PS_SCREENHEIGHT-(xpos+width)-13)/2+3, y=initialYpos+height*4-16-1-20-5-3, width=13-3*2, height= 3, fill=batteryFill, display=False)
scrn.drawAutoText(("%1.1f V" if battVoltage < 10 else "%2.0f V") % battVoltage, xpos+width+6, y=initialYpos+height*4-16-1, size=16, display=False)
# factoring out magic numbers
batteryGraphicHeight = 20
batteryGraphicWidth = 13
batteryGraphicTerminalHeight = 3
batteryGraphicTerminalWidthDiff = 3 # difference between the left/right edge of the battery and the terminal
batteryGraphicTextPadding = 5
rightMarginStartX = xpos + width
rightMarginWidth = scrn.PS_SCREENHEIGHT - rightMarginStartX
batteryTextHeight = 16
batteryTextBottomPadding = 1 # looks better one pixel up, buttons look like they have a 1px border
batteryTextLeftOffset = 6 # for centering
batteryTopY = initialYpos + height * counter - batteryTextHeight - batteryTextBottomPadding
scrn.fillRect(x = rightMarginStartX + (rightMarginWidth - batteryGraphicWidth)/2,
y = batteryTopY - batteryGraphicHeight - batteryGraphicTextPadding,
width = batteryGraphicWidth,
height = batteryGraphicHeight,
fill = batteryFill,
display = False)
scrn.fillRect(x = rightMarginStartX + (rightMarginWidth - batteryGraphicWidth)/2 + batteryGraphicTerminalWidthDiff,
y = batteryTopY - batteryGraphicHeight - batteryGraphicTextPadding - batteryGraphicTerminalHeight,
width = batteryGraphicWidth - batteryGraphicTerminalWidthDiff*2,
height = batteryGraphicTerminalHeight,
fill = batteryFill,
display = False)
scrn.drawAutoText(("%1.1f V" if battVoltage < 10 else "%2.0f V") % battVoltage,
x = xpos + width + batteryTextLeftOffset, # width and height defined above, just under def
y = batteryTopY,
size = batteryTextHeight,
display = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment