Home
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- Firmware/App/Version.h
- Firmware/App/Service/DataProc/DP_Shell.cpp
- Firmware/App/Utils/Shell/Shell.h
- Firmware/App/Config/Config.h
- Firmware/Vendor/Artery/Application/HAL/HAL_Config.h
- Firmware/App/Service/DataProc/DP_Version.cpp
- Firmware/App/Service/DataProc/Def/Power.h
- Firmware/App/Utils/Shell/license.txt
The DutyCycle project is a "Work-Life Duty Cycle Clock," an embedded system designed to represent the passage of time on an analog power meter. It aims to provide a unique and artistic interpretation of time and life's energy consumption. The firmware runs on an AT32F421 microcontroller and is developed using the ArteryTek firmware library and a custom HAL.
The system's primary user interaction and configuration are handled through a command-line shell interface accessible via a standard serial terminal. This allows for setting the time, controlling device functions, and performing diagnostics. The project is licensed under the GNU General Public License, Version 3.
Sources: README.md, Firmware/App/Version.h, Firmware/Vendor/Artery/Platform/AT32F421/MDK-ARM/RTE/_AT32F421/RTE_Components.h, Firmware/App/Utils/Shell/license.txt
Project Overview
The firmware provides the core logic for the clock's functionality, including timekeeping, motor control for the analog dial, and user interaction.
| Item | Value | Source |
|---|---|---|
| Firmware Name | DutyCycle | Firmware/App/Version.h:29 |
| Software Version | v1.2 | Firmware/App/Version.h:30 |
| Hardware Version | v1.3 | Firmware/App/Version.h:31 |
| Author | _VIFEXTech | Firmware/App/Version.h:32 |
| Website | `https://github.com/FASTSHIFT/DutyCycle%60 | Firmware/App/Version.h:33 |
| Build Information | Captured at compile time (__DATE__, __TIME__) | Firmware/App/Service/DataProc/DP_Version.cpp:100-101 |
| License | GNU GPL v3 | Firmware/App/Utils/Shell/license.txt |
Sources: Firmware/App/Version.h, Firmware/App/Service/DataProc/DP_Version.cpp, Firmware/App/Utils/Shell/license.txt
System Architecture
The DutyCycle firmware is built upon a Hardware Abstraction Layer (HAL) that interfaces with the AT32F421 microcontroller peripherals. Above the HAL, a service layer contains data processing modules (DataProc) that manage the device's state and logic. The DP_Shell module is a key component, providing a command-line interface over the serial port.
This diagram illustrates the high-level architecture of the firmware.
Core Features
Button Operations
The device supports several functions through a single physical button.
| Action | Result |
|---|---|
| Single-click (from off) | Powers on the device. The default time is set to the firmware's compile time. |
| Long-press (>10s) | Powers off the device and resets the meter needle to zero. |
| Short-press (from on) | Displays the remaining battery level. 100% is at the top 0.5 mark, 0% is at the bottom 0.5 mark. |
| Quick double-click | Toggles mute mode, which silences all operational sounds, alarms, and hourly chimes. |
Sources: README.md
Time Display Modes
The clock can represent time in two distinct modes, mapping hours to different positions on the analog dial.
Power Factor Meter Mode
This mode uses a non-linear scale, similar to a power factor meter, to display time.
| Dial Value | Time |
|---|---|
| 0.5 (upper) | 05:00 |
| 0.7 (upper) | 07:00 |
| 0.9 (upper) | 09:00 |
| 1.0 | 12:00 |
| 0.9 (lower) | 21:00 |
| 0.7 (lower) | 01:00 |
| 0.5 (lower) | 04:59 |
Sources: README.md
Linear Voltage/Current Meter Mode
This mode uses a linear scale from 0 to 24 to represent the 24-hour clock.
| Dial Value | Time |
|---|---|
| 0 | 00:00 |
| 5 | 05:00 |
| 10 | 10:00 |
| 15 | 15:00 |
| 20 | 20:00 |
| 24 | 23:59 |
Sources: README.md
Shell Interface
The primary method for configuring and interacting with the device is through a command-line shell. This shell is implemented using a generic shell utility and is managed by the DP_Shell data processing module.
Sources: Firmware/App/Service/DataProc/DP_Shell.cpp, Firmware/App/Utils/Shell/Shell.h
Initialization and Task Loop
The shell is initialized once at startup. The shell_init function sets up the necessary callbacks for reading from and writing to the serial device. The main application loop continuously calls shell_task() to process incoming characters and execute commands.
This diagram shows the initialization and command registration sequence.
Command Registration
Commands are added to the shell using the shell_register function, which maps a command string to a C function pointer.
// Firmware/App/Service/DataProc/DP_Shell.cpp:240-244
shell_register(cmdHelp, "help");
shell_register(cmdLogLevel, "loglevel");
shell_register(cmdPs, "ps");
shell_register(cmdPublish, "publish");
shell_register(cmdClock, "clock");
Sources: Firmware/App/Service/DataProc/DP_Shell.cpp:240-248, Firmware/App/Utils/Shell/Shell.h:177-187
Shell Commands
The shell provides several commands for system control and configuration.
| Command | Description |
|---|---|
help | Lists all available commands. |
loglevel | Sets the logging verbosity level (0-4). |
ps | Dumps memory usage information (stack and heap). |
publish | Publishes a message to a data processing topic. |
clock | Gets or sets the system's real-time clock. |
power | Issues power commands like SHUTDOWN or REBOOT. |
ctrl | Controls the motor, display mode, and other hardware features. |
alarm | Manages alarms, hourly chimes, and custom tones. |
kvdb | Manages the key-value database for persistent storage. |
Sources: Firmware/App/Service/DataProc/DP_Shell.cpp:286-599
The flow for executing the power command is shown below.
Firmware Configuration
The firmware's behavior is controlled by several compile-time macros defined in various configuration headers.
Application Configuration
File: Firmware/App/Config/Config.h
| Macro | Default Value | Description |
|---|---|---|
CONFIG_WATCHDOG_TIMEOUT | 10 | Watchdog timeout in seconds. |
Sources: Firmware/App/Config/Config.h:28-31
Hardware Abstraction Layer (HAL) Configuration
File: Firmware/Vendor/Artery/Application/HAL/HAL_Config.h
| Macro | Value | Description |
|---|---|---|
CONFIG_LOG_SERIAL | Serial | The serial interface used for logging. |
CONFIG_MOTOR_OUT1_PIN | PA2 | Motor driver output pin 1. |
CONFIG_MOTOR_OUT2_PIN | PA3 | Motor driver output pin 2. |
CONFIG_BUZZ_PIN | HAL_PinRemap(CONFIG_BUZZ_V1_2_PIN) | Buzzer control pin, remapped for HW version. |
CONFIG_BATT_DET_PIN | HAL_PinRemap(CONFIG_BATT_DET_V1_2_PIN) | Battery voltage detection pin. |
CONFIG_PWR_EN_PIN | HAL_PinRemap(CONFIG_PWR_EN_V1_2_PIN) | Power enable control pin. |
CONFIG_BUTTON_SEL_PIN | HAL_PinRemap(CONFIG_BUTTON_SEL_V1_2_PIN) | Button input pin. |
CONFIG_MEMORY_STACK_INFO | 1 | Enable stack usage monitoring. |
CONFIG_MEMORY_HEAP_INFO | 1 | Enable heap usage monitoring. |
Sources: Firmware/Vendor/Artery/Application/HAL/HAL_Config.h
Conclusion
The DutyCycle project is a creative fusion of hardware and software to create a functional piece of art. Its firmware is built on a structured, service-oriented architecture with a clear separation between hardware control (HAL) and application logic (DataProc). The shell interface stands out as the central point for configuration and advanced control, making the device flexible and developer-friendly. The use of a real-time clock, power management, and persistent storage demonstrates a robust embedded system design.
Sources: README.md, Firmware/App/Service/DataProc/DP_Shell.cpp