allow CLI configuration of the case battery

This commit is contained in:
2024-02-08 01:39:00 +00:00
parent 8e5c94894a
commit fe05ec2e7c
2 changed files with 17 additions and 5 deletions

View File

@@ -2,7 +2,9 @@ this is a 3d-printable case designed for the PinePhone,
but implemented with an eye towards generalizing beyond just that model
and supporting future phones/preferences alongside this first model.
as an example, the default case (pictured below) includes a pouch for carrying an external battery: a quick solution to achieve all-day battery life with any of the stock OSes. the back of this case prints flat, with a mesh that stretches to fit the battery upon installation.
as an example, the default case (pictured below) includes a pouch for carrying an external battery, but if you don't want the pouch then you can build with `CASE_BATTERY=none make` (or edit with `CASE_BATTERY=none cq-toplevel.py --editor`, etc).
the battery pouch is the defining feature of this case though. it's a quick solution to achieve all-day battery life without any special requirements from the OS, and it requires no supports to print: it's a simple mesh which prints flat with the rest of the case, but deforms to fit the battery upon installation.
## Images

View File

@@ -25,6 +25,8 @@ from cadquery.vis import _to_assy
from vtkmodules.vtkRenderingCore import vtkRenderWindow, vtkWindowToImageFilter
from vtkmodules.vtkIOImage import vtkPNGWriter
DEFAULT_BATTERY = "ldtek"
logger = logging.getLogger(__name__)
@@ -69,6 +71,7 @@ def export_png_image(obj, file_: str, orientation: str):
def _model(as_assy: bool=False):
logger.info("computing model ...")
battery_name = os.environ.get("CASE_BATTERY", DEFAULT_BATTERY)
render_phone = os.environ.get("CASE_RENDER_PHONE", "") not in ("", "0")
render_phone_only = os.environ.get("CASE_RENDER_PHONE_ONLY", "") not in ("", "0")
@@ -77,16 +80,19 @@ def _model(as_assy: bool=False):
if render_phone_only:
return case.orient_for_printing(phone)
battery = ldtek_battery.LdtekBattery()
battery = None
if battery_name == "ldtek":
battery = ldtek_battery.LdtekBattery()
return case.case(phone, battery=battery, render_phone=render_phone, as_assy=as_assy)
_computedModels = {}
def model(as_assy: bool=False):
""" memoized wrapper around `_model` """
global _computedModels
if as_assy not in _computedModels:
_computedModels[as_assy] = _model(as_assy=as_assy)
return _computedModels[as_assy]
key = (as_assy, )
if key not in _computedModels:
_computedModels[key] = _model(as_assy=as_assy)
return _computedModels[key]
def main():
logging.basicConfig()
@@ -95,6 +101,7 @@ def main():
parser = argparse.ArgumentParser(description="toplevel cadquery interface")
parser.add_argument("--render-phone", action="store_true", help="render the case and also the phone within it; useful to confirm fit visually before printing")
parser.add_argument("--render-phone-only", action="store_true", help="render *only* the phone, not even the case")
parser.add_argument("--battery", choices=["none", "ldtek"], help="name of the battery for which to create a pocket cutout, or 'none'")
parser.add_argument("--export-stl")
parser.add_argument("--export-png")
parser.add_argument("--export-vtk")
@@ -108,6 +115,9 @@ def main():
if args.render_phone_only:
os.environ["CASE_RENDER_PHONE_ONLY"] = "1"
if args.battery:
os.environ["CASE_BATTERY"] = args.battery
if args.export_stl:
model_ = model()
logger.info("exporting stl to %s", args.export_stl)