Skip to content

Commit

Permalink
fix(klipper): mostly working camera
Browse files Browse the repository at this point in the history
  • Loading branch information
truelecter committed Sep 9, 2023
1 parent 23c787a commit 337c892
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 65 deletions.
11 changes: 8 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ workflows:
only:
- master
- auto/upgrade-dependencies

matrix:
parameters:
host: [voron, oracle]
orbs:
nix: eld/[email protected]

jobs:
build:
machine:
image: ubuntu-2204:2023.07.1
parameters:
host:
type: string
resource_class: arm.large
steps:
- nix/install:
channels: nixpkgs=https://nixos.org/channels/nixpkgs-unstable
channels: nixpkgs=https://nixos.org/channels/nixos-23.05
extra-conf: |
experimental-features = flakes nix-command
- nix/install-cachix
Expand All @@ -38,7 +43,7 @@ jobs:
- run:
name: Build system
command: |
nix build ".#nixosConfigurations.nixos-voron.config.system.build.toplevel"
nix build ".#nixosConfigurations.nixos-<< parameters.hots >>.config.system.build.toplevel"
- run:
name: Push cache
command: |
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This repository is home to the nix code that builds my systems.
[![nas](https://img.shields.io/github/actions/workflow/status/truelecter/hive/build-nas.yaml?event=push&logo=nixos&logoColor=white&label=nas)][nas]
[![squadbook](https://img.shields.io/cirrus/github/truelecter/hive?label=squadbook&logo=nixos&logoColor=white&task=Build%20squadbook)][squadbook]
[![oracle](https://img.shields.io/circleci/build/github/truelecter/hive/master?logo=nixos&logoColor=white&label=oracle)][oracle]
[![voron](https://img.shields.io/circleci/build/github/truelecter/hive/master?logo=nixos&logoColor=white&label=voron)][voron]

## Why Nix?

Expand Down Expand Up @@ -47,5 +48,9 @@ darwin-rebuild switch --flake .

<!-- CirrusCI -->

[oracle]: https://app.circleci.com/pipelines/github/truelecter/hive?branch=master
[squadbook]: https://cirrus-ci.com/github/truelecter/hive/

<!-- CircleCI -->

[voron]: https://app.circleci.com/pipelines/github/truelecter/hive?branch=master
[oracle]: https://app.circleci.com/pipelines/github/truelecter/hive?branch=master
79 changes: 79 additions & 0 deletions cells/klipper/packages/camera-streamer.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
lib,
stdenv,
sources,
# tools
pkg-config,
ccache,
unixtools,
cmake,
# dependencies
nlohmann_json,
ffmpeg,
libcamera,
live555,
gnutls,
# Build flags
useHWH264 ? true,
useFfmpeg ? false,
useLibcamera ? false,
useRtsp ? false,
useLibdatachannel ? true,
...
}: let
inherit (lib) optionals optional;
in
stdenv.mkDerivation rec {
pname = "camera-streamer";

inherit (sources.camera-streamer) version src;

# NIX_DEBUG = 1;
# NIX_CFLAGS_COMPILE = "-Wno-error";

hardeningDisable = ["all"];

makeFlags =
[
"GIT_VERSION=${version}"
"GIT_REVISION=${version}"
]
++ optional useHWH264 "USE_HW_H264=1"
++ optional useFfmpeg "USE_FFMPEG=1"
++ optional useLibcamera "USE_LIBCAMERA=1"
++ optional useRtsp "USE_RTSP=1";

nativeBuiltInputs = [pkg-config ccache unixtools.xxd cmake];

buildInputs =
[nlohmann_json]
++ optional useFfmpeg ffmpeg
++ optional useLibcamera libcamera
++ optional useRtsp live555
++ optional useLibdatachannel gnutls;

configurePhase = ''
echo '#define GIT_VERSION "${version}"' > version.h
echo '#define GIT_REVISION "${version}"' >> version.h
sed -i 's/all: version/all:/g' Makefile
export PATH="${pkg-config}/bin:${unixtools.xxd}/bin:${cmake}/bin::$PATH"
'';

installPhase = ''
$preInstallPhase
mkdir -p $out/bin
cp camera-streamer $out/bin/
$postInstallPhase
'';

meta = with lib; {
description = "Touchscreen GUI that interfaces with Klipper via Moonraker";
homepage = "https://klipperscreen.readthedocs.io/en/latest/";
platforms = platforms.linux;
license = licenses.gpl3Only;
};
}
36 changes: 28 additions & 8 deletions cells/klipper/sources/generated.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
{
"camera-streamer": {
"cargoLocks": null,
"date": null,
"extract": null,
"name": "camera-streamer",
"passthru": null,
"pinned": false,
"src": {
"deepClone": false,
"fetchSubmodules": true,
"leaveDotGit": false,
"name": null,
"owner": "ayufan",
"repo": "camera-streamer",
"rev": "v0.2.6",
"sha256": "sha256-m47fXOZuStaRPLJYGZKpg6RBPfFSkCafdqujagXTDXo=",
"type": "github"
},
"version": "v0.2.6"
},
"klipper": {
"cargoLocks": null,
"date": "2023-08-21",
Expand Down Expand Up @@ -41,7 +61,7 @@
},
"klipper-happy-hare": {
"cargoLocks": null,
"date": "2023-09-05",
"date": "2023-09-09",
"extract": null,
"name": "klipper-happy-hare",
"passthru": null,
Expand All @@ -53,11 +73,11 @@
"name": null,
"owner": "moggieuk",
"repo": "Happy-Hare",
"rev": "6416e02201701c6b8e63a18a32d9f046ce2e16a5",
"sha256": "sha256-W3v3aB8vhCPRKaoLMg1dxnHhHlHMANRSL4kmyvch2Qs=",
"rev": "bb8eef4e7741db91a11e932c23d9eb40cfffe3b5",
"sha256": "sha256-YU+okOaXoVCW9Df3mZRKKIyNQ8p99OsM/S8GXC2gvls=",
"type": "github"
},
"version": "6416e02201701c6b8e63a18a32d9f046ce2e16a5"
"version": "bb8eef4e7741db91a11e932c23d9eb40cfffe3b5"
},
"klipper-kamp": {
"cargoLocks": null,
Expand Down Expand Up @@ -121,7 +141,7 @@
},
"klipper-screen": {
"cargoLocks": null,
"date": "2023-09-06",
"date": "2023-09-09",
"extract": null,
"name": "klipper-screen",
"passthru": null,
Expand All @@ -133,11 +153,11 @@
"name": null,
"owner": "jordanruthe",
"repo": "KlipperScreen",
"rev": "14d3fca31c2157e505f332a94e2a1e3f528a00d4",
"sha256": "sha256-jZwCXgexupQRQ0gfxkWg/rShl2Ml3jZ88nmiXeIbD1w=",
"rev": "f8da43c37966287e1e026d30d1c28873c92a2dcb",
"sha256": "sha256-Sw/+8cMWHmn4dHY03oUmTV5F+BP1TSU7zadQx42vi8Y=",
"type": "github"
},
"version": "14d3fca31c2157e505f332a94e2a1e3f528a00d4"
"version": "f8da43c37966287e1e026d30d1c28873c92a2dcb"
},
"klipper-z-calibration": {
"cargoLocks": null,
Expand Down
27 changes: 19 additions & 8 deletions cells/klipper/sources/generated.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# This file was generated by nvfetcher, please do not modify it manually.
{ fetchgit, fetchurl, fetchFromGitHub, dockerTools }:
{
camera-streamer = {
pname = "camera-streamer";
version = "v0.2.6";
src = fetchFromGitHub {
owner = "ayufan";
repo = "camera-streamer";
rev = "v0.2.6";
fetchSubmodules = true;
sha256 = "sha256-m47fXOZuStaRPLJYGZKpg6RBPfFSkCafdqujagXTDXo=";
};
};
klipper = {
pname = "klipper";
version = "5f990f93d533247d3a675e8c423280f4333ad8ce";
Expand All @@ -27,15 +38,15 @@
};
klipper-happy-hare = {
pname = "klipper-happy-hare";
version = "6416e02201701c6b8e63a18a32d9f046ce2e16a5";
version = "bb8eef4e7741db91a11e932c23d9eb40cfffe3b5";
src = fetchFromGitHub {
owner = "moggieuk";
repo = "Happy-Hare";
rev = "6416e02201701c6b8e63a18a32d9f046ce2e16a5";
rev = "bb8eef4e7741db91a11e932c23d9eb40cfffe3b5";
fetchSubmodules = false;
sha256 = "sha256-W3v3aB8vhCPRKaoLMg1dxnHhHlHMANRSL4kmyvch2Qs=";
sha256 = "sha256-YU+okOaXoVCW9Df3mZRKKIyNQ8p99OsM/S8GXC2gvls=";
};
date = "2023-09-05";
date = "2023-09-09";
};
klipper-kamp = {
pname = "klipper-kamp";
Expand Down Expand Up @@ -74,15 +85,15 @@
};
klipper-screen = {
pname = "klipper-screen";
version = "14d3fca31c2157e505f332a94e2a1e3f528a00d4";
version = "f8da43c37966287e1e026d30d1c28873c92a2dcb";
src = fetchFromGitHub {
owner = "jordanruthe";
repo = "KlipperScreen";
rev = "14d3fca31c2157e505f332a94e2a1e3f528a00d4";
rev = "f8da43c37966287e1e026d30d1c28873c92a2dcb";
fetchSubmodules = false;
sha256 = "sha256-jZwCXgexupQRQ0gfxkWg/rShl2Ml3jZ88nmiXeIbD1w=";
sha256 = "sha256-Sw/+8cMWHmn4dHY03oUmTV5F+BP1TSU7zadQx42vi8Y=";
};
date = "2023-09-06";
date = "2023-09-09";
};
klipper-z-calibration = {
pname = "klipper-z-calibration";
Expand Down
5 changes: 5 additions & 0 deletions cells/klipper/sources/nvfetcher.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ fetch.pypi = "wsaccel"
src.manual = "13.5"
fetch.pypi = "python-telegram-bot"

[camera-streamer]
src.github = "ayufan/camera-streamer"
fetch.github = "ayufan/camera-streamer"
git.fetchSubmodules = true

# mainsail
[mainsail]
src.git = "https://github.com/mainsail-crew/mainsail"
Expand Down
5 changes: 3 additions & 2 deletions cells/nixos/hosts/voron/_camera.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
}: {
environment.systemPackages = [
pkgs.v4l-utils
pkgs.camera-streamer
];

tl.services.tailscale-tls.enable = true;
Expand All @@ -16,8 +17,8 @@
settings = {
ffmpeg.bin = "${lib.getBin pkgs.ffmpeg_6-full}/bin/ffmpeg";
streams = {
nozzle = "ffmpeg:device?video=/dev/v4l/by-id/usb-XCG-221208-J_3DO_NOZZLE_CAMERA_4K_01.00.00-video-index0&video_size=800x600#video=h264";
printer = "ffmpeg:device?video=/dev/v4l/by-id/usb-046d_HD_Pro_Webcam_C920_89E7787F-video-index0&video_size=800x600#rotate=180#video=h264";
nozzle = "ffmpeg:device?video=/dev/v4l/by-id/usb-XCG-221208-J_3DO_NOZZLE_CAMERA_4K_01.00.00-video-index0&video_size=640x480&framerate=30&input_format=yuyv422#video=h264#hardware=v4l2m2m";
printer = "ffmpeg:device?video=/dev/v4l/by-id/usb-046d_HD_Pro_Webcam_C920_89E7787F-video-index0&video_size=640x480&framerate=30&input_format=h264#rotate=180#video=h264#hardware=v4l2m2mls";
};
log = {
format = "text";
Expand Down
53 changes: 17 additions & 36 deletions cells/nixos/hosts/voron/_hardware-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
...
}: {
boot = {
kernelPackages = pkgs.linuxPackages_rpi4.extend (lib.const (ksuper: {
kernel = ksuper.kernel.override {
autoModules = false;
structuredExtraConfig = with lib.kernel; {
CONFIG_USB_XHCI_PCI = yes;
CONFIG_USB_XHCI_PCI_RENESAS = yes;
};
};
}));
# kernelPackages = pkgs.linuxPackages_rpi4;
kernelPackages = pkgs.linuxPackages_rpi4;
loader = {
grub.enable = false;
generic-extlinux-compatible = {
Expand All @@ -32,23 +23,27 @@
};
consoleLogLevel = 7;
initrd.availableKernelModules = [
"xhci_hcd"
"xhci-pci-renesas"

"usbhid"
"usb_storage"

"sdhci_pci"
"mmc_block"

"simplefb"
"pcie-brcmstb"

"vc4"
"pcie_brcmstb" # required for the pcie bus to work
"reset-raspberrypi" # required for vl805 firmware to load
];
kernelParams = ["console=ttyS0,115200n8" "console=tty1" "video=DSI-1:800x480@60" "cma=448M"];
# kernelPatches = [
# {
# name = "xhci";
# patch = null;
# extraStructuredConfig = {
# CONFIG_USB_XHCI_PCI = lib.kernel.yes;
# CONFIG_USB_XHCI_PCI_RENESAS = lib.kernel.yes;
# };
# }
# ];
kernelParams = [
"console=ttyS0,115200n8"
"console=tty1"
"video=DSI-1:800x480@60"
];
};

fileSystems = {
Expand All @@ -63,16 +58,9 @@
};
};

# powerManagement.cpuFreqGovernor = "performance";
powerManagement.cpuFreqGovernor = "performance";

hardware = {
# raspberry-pi."4" = {
# i2c0.enable = false;
# i2c1.enable = false;
# fkms-3d.enable = false;
# touch-ft5406.enable = false;
# };

enableRedistributableFirmware = true;
};

Expand All @@ -84,14 +72,7 @@

environment.etc."u-boot-cm4".source = pkgs.ubootRaspberryPi4_64bit.override {
extraConfig = ''
#CONFIG_CMD_NVME=y
#CONFIG_NVME=y
#CONFIG_NVME_PCI=y
CONFIG_USB_STORAGE=y
CONFIG_USB_FUNCTION_MASS_STORAGE=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_GENERIC=y
CONFIG_USB_OHCI_HCD=y
CONFIG_USB_XHCI_BRCM=y
'';
extraPatches = [
Expand Down
Loading

0 comments on commit 337c892

Please sign in to comment.