Changes
16 changed files (+366/-102)
-
.editorconfig (new)
-
@@ -0,0 +1,33 @@# Copyright (C) 2025 Shota FUJI # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # # SPDX-License-Identifier: GPL-3.0-only [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.{zig,zon}] # Zig compiler can't handle tab character indent_style = space indent_size = 4 [*.nix] # Nix's string interpolation does not work well with tab character indent_style = space indent_size = 2
-
-
-
@@ -1,61 +1,26 @@# Prerequisites *.d # Copyright (C) 2025 Shota FUJI # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # # SPDX-License-Identifier: GPL-3.0-only # Object files *.o *.ko *.obj *.elf # Zig's build cache directory. .zig-cache # Linker output *.ilk *.map *.exp # Precompiled Headers *.gch *.pch # Zig compiler emits build artifacts under this directory. zig-out # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ *.su *.idb *.pdb # Kernel Module Compile Results *.mod* *.cmd .tmp_versions/ modules.order Module.symvers Mkfile.old dkms.conf /.vs /Debug /Release /*.vcxproj.filters /*.vcxproj.user /obj /x64 *.tlog # Nix creates this super generic name directory on build. # They seems to have no way to change the name or suppress the creation. /result
-
-
-
@@ -1,19 +1,44 @@<!-- Copyright (C) 2025 Shota FUJI This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. SPDX-License-Identifier: GPL-3.0-only --> # sunwait Sunwait calculates sunrise or sunset times with civil, nautical, astronomical and custom twilights. Sunwait calculates sunrise or sunset times and blocks until next sunrise/sunwait event. This software is a fork of [Dan Risacher's original sunwait program](https://github.com/risacher/sunwait). ## Install using Nix Flake This repository contains [`flake.nix`](./flake.nix) file that builds and provides `sunwait` executable file. It is intended for use in home automation with Windows Task Scheduler or cron. Use it to turn lights on *before* it gets dark! The program can wait from invocation until the event specified on the command line occurs or it can return immediately indicating if it is day or night. It's best to schedule Sunwait to run a little before the earliest opportunity for the event to occur each year - ie dusk range is 3:30pm to 10:30pm here, so it reasonable to schedule a dusk task at 3pm and allow Sunwait to pause the task for between 30mins and 7 and a half hours. If you scheduled the task for 6pm, then your lights will come on no earlier than 6pm. ## Build from source The sun's position is calculated using time, and position - latitude and longitude should be specified on the command line. You need Zig compiler v0.14.x. Features: ```sh zig build ``` * Calculates sunrise and sunset for given coordinates * Can wait for sunrise/sunset, or return DAY or NIGHT codes * Works with Windows Task Scheduler (or cron) * Supports custom twilight angles * Used to automate domestic lighting with Arduino transmitter and radio controlled sockets To build and run the built application in one go, use this command instead: History: ```sh zig build run This project is a "reclaimed fork". I (Dan Risacher) wrote the original version around 2000, and maintained it until 2004. In 2013, Ian Craig made a version that compiled cleanly on Windows and added some useful features. In 2019, I'm moving it to GitHub as a better collaborative development platform. If you have feature requests or issues, please report them here. # To pass arguments to the program, set them after "--" zig build run -- poll ```
-
-
-
@@ -2,14 +2,11 @@ version = 1[[annotations]] path = [ ".gitignore", "examples.txt", "makefile", "print.c", "print.h", "README.md", "sunwait.c", "sunwait.h", "src/print.c", "src/print.h", "src/sunwait.c", "src/sunwait.h", "USAGE.txt", ] SPDX-FileCopyrightText = [
-
@@ -19,7 +16,7 @@ ]SPDX-License-Identifier = "GPL-3.0-only" [[annotations]] path = ["sunriset.c", "sunriset.h"] path = ["src/sunriset.c", "src/sunriset.h"] SPDX-FileCopyrightText = [ "(c) Paul Schlyter, 1989, 1992", "(c) 2000,2004,2022 Daniel Risacher",
-
-
build.zig (new)
-
@@ -0,0 +1,60 @@// Copyright (C) 2025 Shota FUJI // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. // // SPDX-License-Identifier: GPL-3.0-only const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const exe = exe: { const exe = b.addExecutable(.{ .name = "sunwait", .target = target, .optimize = optimize, }); exe.linkLibC(); exe.addCSourceFiles(.{ .files = &.{ "src/print.c", "src/sunriset.c", "src/sunwait.c", }, }); exe.addIncludePath(b.path("src")); break :exe exe; }; // Default step b.installArtifact(exe); // "zig build run" { const step = b.step("run", "Build and run sunwait"); const run = b.addRunArtifact(exe); if (b.args) |args| { run.addArgs(args); } step.dependOn(&run.step); } }
-
-
dprint.jsonc (new)
-
@@ -0,0 +1,54 @@// Copyright (C) 2025 Shota FUJI // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. // // SPDX-License-Identifier: GPL-3.0-only { "excludes": [".zig-cache", "zig-out"], "plugins": [ "https://plugins.dprint.dev/markdown-0.19.0.wasm", "https://plugins.dprint.dev/toml-0.7.0.wasm", "https://plugins.dprint.dev/json-0.20.0.wasm", "https://plugins.dprint.dev/exec-0.5.1.json@492414e39dea4dccc07b4af796d2f4efdb89e84bae2bd4e1e924c0cc050855bf", ], // Common options "lineWidth": 90, "indentWidth": 2, "newLineKind": "lf", "useTabs": true, // Plugins "markdown": {}, "toml": {}, "json": {}, "exec": { "cwd": "${configDir}", "commands": [ { "exts": ["zig"], "command": "zig fmt --stdin", }, { "exts": ["zon"], "command": "zig fmt --zon --stdin", }, { "exts": ["nix"], "command": "nixfmt --strict --width={{line_width}} --indent={{indent_width}}", }, ], }, }
-
-
flake.lock (new)
-
@@ -0,0 +1,61 @@{ "nodes": { "flake-utils": { "inputs": { "systems": "systems" }, "locked": { "lastModified": 1731533236, "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { "owner": "numtide", "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { "lastModified": 1751949589, "narHash": "sha256-mgFxAPLWw0Kq+C8P3dRrZrOYEQXOtKuYVlo9xvPntt8=", "owner": "nixos", "repo": "nixpkgs", "rev": "9b008d60392981ad674e04016d25619281550a9d", "type": "github" }, "original": { "owner": "nixos", "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } }, "systems": { "locked": { "lastModified": 1681028828, "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "owner": "nix-systems", "repo": "default", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { "owner": "nix-systems", "repo": "default", "type": "github" } } }, "root": "root", "version": 7 }
-
-
flake.lock.license (new)
-
@@ -0,0 +1,16 @@Copyright (C) 2025 Shota FUJI This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. SPDX-License-Identifier: GPL-3.0-only
-
-
flake.nix (new)
-
@@ -0,0 +1,78 @@# Copyright (C) 2025 Shota FUJI # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. # # SPDX-License-Identifier: GPL-3.0-only { inputs = { nixpkgs = { url = "github:nixos/nixpkgs/nixpkgs-unstable"; }; flake-utils = { url = "github:numtide/flake-utils"; }; }; outputs = { self, nixpkgs, flake-utils, }: flake-utils.lib.eachDefaultSystem ( system: let pkgs = nixpkgs.legacyPackages.${system}; nativeBuildInputs = with pkgs; [ zig ]; in { packages.default = pkgs.stdenvNoCC.mkDerivation { pname = "sunwaitz"; version = "0.91.0"; src = ./.; meta = { mainProgram = "sunwait"; }; nativeBuildInputs = nativeBuildInputs ++ [ pkgs.zig.hook ]; }; devShell = pkgs.mkShell { inherit nativeBuildInputs; packages = with pkgs; [ # Code formatter # https://dprint.dev/ dprint # Official formatter for Nix code # https://hackage.haskell.org/package/nixfmt nixfmt-rfc-style # Copyright and license linter based on SPDX # https://github.com/fsfe/reuse-tool reuse # For text editors, optional. # > ZLS is a non-official implementation of the Language Server Protocol for Zig # https://github.com/zigtools/zls zls ]; }; } ); }
-
-
makefile (deleted)
-
@@ -1,25 +0,0 @@# sunwait # # 08/12/2014 IFC 0.6 No changes since 0.5 # 02/05/2015 IFC 0.7 No changes since 0.5, still # 10/03/2020 TLJ 0.9 Move headers to fix build on osx # 2022-09-16 DRR 0.91 Accept changes from @mstilkerich Michael Stilkerich switches to C from C++ # CFLAGS=-c -Wall -std=c99 -O2 -Wextra -pedantic CXXFLAGS=-c -Wall LDFLAGS= -lm SOURCES=sunwait.c sunriset.c print.c HEADERS=sunwait.h sunriset.h print.h OBJECTS=$(SOURCES:.c=.o) EXECUTABLE=sunwait all: $(EXECUTABLE) .c.o: $(CC) $(CFLAGS) $< -o $@ $(EXECUTABLE): $(OBJECTS) $(CC) $(OBJECTS) -o $@ $(LDFLAGS) clean: rm -f *.o sunwait
-
-
-
-
-
-
-