Skip to content

unit-system-exports/unit-system-arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unit-system arduino

arduino-library-badge

As of version 0.6.0 all the source code is generated by python scripts. This repository only contains the generated source files. If you want to report a bug or change something check the generator repository.

This is an implementation of the SI unit system for C++17 development. All units, combinations, literals and constants are generated from templates. If you feel something is missing open an issue or a pull request on the generator repository.

Usage examples

#include "unit_system.hpp"

using namespace sakurajin::unit_system;
using namespace sakurajin::unit_system::literals;

void setup(){
    const auto t2 = 10.0_h;
    const auto s2 = 250.0_km;
    const auto v2 = s2/t2;
    
    Serial.begin(9600);
    
    Serial.print(s2.value);
    Serial.print("km driven in ");
    Serial.print(t2.value);
    Serial.print("h is an average speed of:");
    Serial.print(v2.value);
    Serial.println("km/h");
}

void loop(){}

Including the unit-system library

Depending on your build system you might have to figure out how to include and link this library by yourself.

Arduino IDE

Just install the library from the library manager. All you have to do is include the unit_system.hpp header file, and you are good to go. To simplify the class names, you can add the following two lines to your code:

using namespace sakurajin::unit_system;
using namespace sakurajin::unit_system::literals;

Units that are currently supported

  • time_si -> time with seconds as base unit
  • length -> length with meter as base unit
  • mass -> mass with kg as base unit
  • temperature -> temperature with K as base unit
  • amount -> amount of substance with mole as base unit
  • electric_current -> electric current with Ampere as base unit
  • luminous_intensity -> luminous intensity with candela as base unit
  • area -> area with m^2 as base unit
  • speed -> speed with m / s as base unit
  • acceleration -> acceleration with m / s^2 as base unit
  • momentum -> momentum with kg * m / s as base unit
  • force -> force with kg * m / s^2 (Newton) as base unit
  • energy -> energy with kg * m^2 / s^2 (Joules) as base unit
  • power -> power with kg * m^2 / s^3 (Watts) as base unit

Upgrade Instructions

from version 0.7.x to 0.8.x

Most code should still work.

However, there are two major changes. The first one is that there is only one header now. All declarations are now in the unit_system.hpp header. If you only included some parts of the library you have to change that.

The second major change is the removal of the unit_t template class. This means all custom types are now broken. This is done to simplify the code and make it easier to maintain. Now all units have to be created by using the generator script. If you want to add a new unit you have to add it to the generator script and run it.

from version 0.6.x to 0.7.x

Nothing much changed in the API. The most important change is that when using meson, the std is now required and the fallbacks are removed. This means that you have to use a compiler that supports C++14 or higher. In addition to that the generator repository and the unit-system repository are now split. This means that python is no longer required to build the code. The unit-system repository now only contains the generated code.

One other major change is that Arduino and C++17 have separate templates. Because of this the Arduino API is slightly different but should work on almost every board.

from version pre 0.6.0 to 0.6.x

As of version 0.6.0 there are no longer sub namespaces for base and common units. Just change sakurajin::unit_system::base and sakurajin::unit_system::common to sakurajin::unit_system. This also affects literals and constants so they are now all under sakurajin::unit_system::literals and sakurajin::unit_system::constants.

In addition to that a lot of data was moved around in the headers. Because of that it is no longer recommended to include only some parts of the library. So instead of including the units directly just include the main header for this library #include "unit_system.hpp".