A simple clock daemon that works with a character device created by the tm1637-kmod kernel driver or the tm1637-cuse service. It is a successor of my other project digitalclock based on a library tm1637-display. Brightness control can be done through the sysctl variables of the kernel driver "tm1637.ko" or by sending control strings to the character display device.
The daemon:
- creates a
pidfile
and usesdaemon
(8) if run with-b
parameter for detach from a terminal; - uses
timer_create
(2) for output time and marking seconds by colon (1, 2 times per second or always on); - uses a signal interception for stopping itself correctly;
- interacts with device /dev/tm1637 by writing digits to it and using ioctl calls;
I wrote this program for my little-task server on Raspberry Pi 2 (Another task is a NTPD service for getting a time from GLONASS).
For the tm1637-clock
program You need:
- ARM SoC, e.g. Raspberry Pi 2 or 3 (Orange or Banana also is good);
- FreeBSD 12 operating system;
- C compatible compilator (FreeBSD already has a native
clang
); - An installed and loaded the tm1637-kmod kernel driver.
git clone https://gitlab.com/alexandermishin13/tm1637-clock.git
As desribed above, You need firstly to install and load the tm1637 kernel module. For a description of how to do this, refer to the tm1637-kmod project page
For the program installation type:
make
sudo make install
The executable file will be installed as /usr/local/sbin/tm1637clock and the service file as /usr/local/etc/rc.d/tm1637clock. You also can a copy a /rc.conf.d/tm1637clock.example to /usr/local/etc/rc.conf.d/tm1637clock to control the service.
For deinstallation type:
sudo make uninstall
The program can be run either as a daemon (with -b
parameter) and as a
standalone program.
A clock point change mode can be set by a -p
key followed by integer. Possible
values are 0
-always on, 1
-blinks once a second and 2
-blinks twice per
second. Least processor efficient mode is 2
, although it was optimized. Almost
two times more efficient mode is 1
as it less often writes to the display.
And even more efficient mode is 0
as it writes to the display just once a
minute.
Typical it is run as a daemon by a service startup script:
./tm1637clock -b [-p <mode>]
but You can run it like a regular program by omitting the -b
option.
You can turn on, off or set brightness of the display by interacting with the tm1637 kernel driver using sysctl variables. No special privileges required for it:
sysctl dev.tm1637.0.brightness=3
sysctl dev.tm1637.0.on=0
If You wish to start service automatically with a boot of operating system, You can:
- add to a file /etc/rc.conf
- create a new file /usr/local/etc/rc.conf.d/tm1637clock and add a followed string to it (Or just copy its example from sources):
tm1637clock_enable="YES"
tm1637clock_flags="-b -p 2"
Then You can manage the service by one of a command:
service tm1637clock start
service tm1637clock stop
service tm1637clock status