Documentation ¶
Overview ¶
Package physic declares types for physical input, outputs and measurement units.
This includes temperature, humidity, pressure, tension, current, etc.
Index ¶
- type Angle
- type Distance
- type ElectricCurrent
- type ElectricPotential
- type ElectricResistance
- type ElectricalCapacitance
- type Energy
- type Env
- type Force
- type Frequency
- type LuminousFlux
- type LuminousIntensity
- type Mass
- type Power
- type Pressure
- type RelativeHumidity
- type SenseEnv
- type Speed
- type Temperature
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Angle ¶
type Angle int64
Angle is the measurement of the difference in orientation between two vectors stored as an int64 nano radian.
A negative angle is valid.
The highest representable value is a bit over 500,000,000,000°.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(physic.Degree) fmt.Println(physic.Pi) fmt.Println(physic.Theta) }
Output: 1.000° 180.0° 360.0°
const ( NanoRadian Angle = 1 MicroRadian Angle = 1000 * NanoRadian MilliRadian Angle = 1000 * MicroRadian Radian Angle = 1000 * MilliRadian // Theta is 2π. This is equivalent to 360°. Theta Angle = 6283185307 * NanoRadian Pi Angle = 3141592653 * NanoRadian Degree Angle = 17453293 * NanoRadian )
type Distance ¶
type Distance int64
Distance is a measurement of length stored as an int64 nano metre.
This is one of the base unit in the International System of Units.
The highest representable value is 9.2Gm.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(physic.Inch) fmt.Println(physic.Foot) fmt.Println(physic.Mile) }
Output: 25.400mm 304.800mm 1.609km
const ( NanoMetre Distance = 1 MicroMetre Distance = 1000 * NanoMetre MilliMetre Distance = 1000 * MicroMetre Metre Distance = 1000 * MilliMetre KiloMetre Distance = 1000 * Metre MegaMetre Distance = 1000 * KiloMetre GigaMetre Distance = 1000 * MegaMetre // Conversion between Metre and imperial units. Thou Distance = 25400 * NanoMetre Inch Distance = 1000 * Thou Foot Distance = 12 * Inch Yard Distance = 3 * Foot Mile Distance = 1760 * Yard )
type ElectricCurrent ¶
type ElectricCurrent int64
ElectricCurrent is a measurement of a flow of electric charge stored as an int64 nano Ampere.
This is one of the base unit in the International System of Units.
The highest representable value is 9.2GA.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10010 * physic.MilliAmpere) fmt.Println(10 * physic.Ampere) fmt.Println(-10 * physic.MilliAmpere) }
Output: 10.010A 10A -10mA
const ( NanoAmpere ElectricCurrent = 1 MicroAmpere ElectricCurrent = 1000 * NanoAmpere MilliAmpere ElectricCurrent = 1000 * MicroAmpere Ampere ElectricCurrent = 1000 * MilliAmpere KiloAmpere ElectricCurrent = 1000 * Ampere MegaAmpere ElectricCurrent = 1000 * KiloAmpere GigaAmpere ElectricCurrent = 1000 * MegaAmpere )
func (ElectricCurrent) String ¶
func (e ElectricCurrent) String() string
String returns the current formatted as a string in Ampere.
type ElectricPotential ¶
type ElectricPotential int64
ElectricPotential is a measurement of electric potential stored as an int64 nano Volt.
The highest representable value is 9.2GV.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10010 * physic.MilliVolt) fmt.Println(10 * physic.Volt) fmt.Println(-10 * physic.MilliVolt) }
Output: 10.010V 10V -10mV
const ( // Volt is W/A, kg⋅m²/s³/A. NanoVolt ElectricPotential = 1 MicroVolt ElectricPotential = 1000 * NanoVolt MilliVolt ElectricPotential = 1000 * MicroVolt Volt ElectricPotential = 1000 * MilliVolt KiloVolt ElectricPotential = 1000 * Volt MegaVolt ElectricPotential = 1000 * KiloVolt GigaVolt ElectricPotential = 1000 * MegaVolt )
func (ElectricPotential) String ¶
func (e ElectricPotential) String() string
String returns the tension formatted as a string in Volt.
type ElectricResistance ¶
type ElectricResistance int64
ElectricResistance is a measurement of the difficulty to pass an electric current through a conductor stored as an int64 nano Ohm.
The highest representable value is 9.2GΩ.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10010 * physic.MilliOhm) fmt.Println(10 * physic.Ohm) fmt.Println(24 * physic.MegaOhm) }
Output: 10.010Ω 10Ω 24MΩ
const ( // Ohm is V/A, kg⋅m²/s³/A². NanoOhm ElectricResistance = 1 MicroOhm ElectricResistance = 1000 * NanoOhm MilliOhm ElectricResistance = 1000 * MicroOhm Ohm ElectricResistance = 1000 * MilliOhm KiloOhm ElectricResistance = 1000 * Ohm MegaOhm ElectricResistance = 1000 * KiloOhm GigaOhm ElectricResistance = 1000 * MegaOhm )
func (ElectricResistance) String ¶
func (e ElectricResistance) String() string
String returns the resistance formatted as a string in Ohm.
type ElectricalCapacitance ¶
type ElectricalCapacitance int64
ElectricalCapacitance is a measurement of capacitance stored as a pico farad.
The highest representable value is 9.2MF.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(1 * physic.Farad) fmt.Println(22 * physic.PicoFarad) }
Output: 1F 22pF
const ( // Farad is a unit of capacitance. kg⁻¹⋅m⁻²⋅s⁴A² PicoFarad ElectricalCapacitance = 1 NanoFarad ElectricalCapacitance = 1000 * PicoFarad MicroFarad ElectricalCapacitance = 1000 * NanoFarad MilliFarad ElectricalCapacitance = 1000 * MicroFarad Farad ElectricalCapacitance = 1000 * MilliFarad KiloFarad ElectricalCapacitance = 1000 * Farad MegaFarad ElectricalCapacitance = 1000 * KiloFarad )
func (ElectricalCapacitance) String ¶
func (c ElectricalCapacitance) String() string
String returns the energy formatted as a string in Farad.
type Energy ¶
type Energy int64
Energy is a measurement of work stored as a nano joules.
The highest representable value is 9.2GJ.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(1 * physic.Joule) }
Output: 1J
type Env ¶
type Env struct { Temperature Temperature Pressure Pressure Humidity RelativeHumidity }
Env represents measurements from an environmental sensor.
type Force ¶
type Force int64
Force is a measurement of interaction that will change the motion of an object stored as an int64 nano Newton.
A measurement of Force is a vector and has a direction but this unit only represents the magnitude. The orientation needs to be stored as a Quaternion independently.
The highest representable value is 9.2TN.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10 * physic.MilliNewton) fmt.Println(physic.EarthGravity) fmt.Println(physic.PoundForce) }
Output: 10mN 9.807N 4.448kN
const ( // Newton is kg⋅m/s². NanoNewton Force = 1 MicroNewton Force = 1000 * NanoNewton MilliNewton Force = 1000 * MicroNewton Newton Force = 1000 * MilliNewton KiloNewton Force = 1000 * Newton MegaNewton Force = 1000 * KiloNewton GigaNewton Force = 1000 * MegaNewton EarthGravity Force = 9806650 * MicroNewton // Conversion between Newton and imperial units. // Pound is both a unit of mass and weight (force). The suffix Force is added // to disambiguate the measurement it represents. PoundForce Force = 4448221615261 * NanoNewton )
type Frequency ¶
type Frequency int64
Frequency is a measurement of cycle per second, stored as an int32 micro Hertz.
The highest representable value is 9.2THz.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10 * physic.MilliHertz) fmt.Println(101010 * physic.MilliHertz) fmt.Println(10 * physic.MegaHertz) }
Output: 10mHz 101.010Hz 10MHz
func PeriodToFrequency ¶
PeriodToFrequency returns the frequency for a period of this interval.
Example ¶
package main import ( "fmt" "time" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(physic.PeriodToFrequency(time.Microsecond)) fmt.Println(physic.PeriodToFrequency(time.Minute)) }
Output: 1MHz 16.666mHz
type LuminousFlux ¶
type LuminousFlux int64
LuminousFlux is a measurement of total quantity of visible light energy emitted with wavelength power weighted by a luminosity function which represents a model of the human eye's response to different wavelengths. The CIE 1931 luminosity function is the standard for lumens.
LuminousFlux is stored as nano lumens.
The highest representable value is 9.2Glm.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(18282 * physic.Lumen) }
Output: 18.282klm
const ( // Lumen is a unit of luminous flux. cd⋅sr NanoLumen LuminousFlux = 1 MicroLumen LuminousFlux = 1000 * NanoLumen MilliLumen LuminousFlux = 1000 * MicroLumen Lumen LuminousFlux = 1000 * MilliLumen KiloLumen LuminousFlux = 1000 * Lumen MegaLumen LuminousFlux = 1000 * KiloLumen GigaLumen LuminousFlux = 1000 * MegaLumen )
func (LuminousFlux) String ¶
func (f LuminousFlux) String() string
String returns the energy formatted as a string in Lumens.
type LuminousIntensity ¶
type LuminousIntensity int64
LuminousIntensity is a measurement of the quantity of visible light energy emitted per unit solid angle with wavelength power weighted by a luminosity function which represents the human eye's response to different wavelengths. The CIE 1931 luminosity function is the SI standard for candela.
LuminousIntensity is stored as nano candela.
This is one of the base unit in the International System of Units.
The highest representable value is 9.2Gcd.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(12 * physic.Candela) }
Output: 12cd
const ( // Candela is a unit of luminous intensity. cd NanoCandela LuminousIntensity = 1 MicroCandela LuminousIntensity = 1000 * NanoCandela MilliCandela LuminousIntensity = 1000 * MicroCandela Candela LuminousIntensity = 1000 * MilliCandela KiloCandela LuminousIntensity = 1000 * Candela MegaCandela LuminousIntensity = 1000 * KiloCandela GigaCandela LuminousIntensity = 1000 * MegaCandela )
func (LuminousIntensity) String ¶
func (l LuminousIntensity) String() string
String returns the energy formatted as a string in Candela.
type Mass ¶
type Mass int64
Mass is a measurement of mass stored as an int64 nano gram.
This is one of the base unit in the International System of Units.
The highest representable value is 9.2Gg.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10 * physic.MilliGram) fmt.Println(physic.OunceMass) fmt.Println(physic.PoundMass) fmt.Println(physic.Slug) }
Output: 10mg 28.350g 453.592g 14.594kg
const ( NanoGram Mass = 1 MicroGram Mass = 1000 * NanoGram MilliGram Mass = 1000 * MicroGram Gram Mass = 1000 * MilliGram KiloGram Mass = 1000 * Gram MegaGram Mass = 1000 * KiloGram GigaGram Mass = 1000 * MegaGram Tonne Mass = MegaGram // Conversion between Gram and imperial units. // Ounce is both a unit of mass, weight (force) or volume depending on // context. The suffix Mass is added to disambiguate the measurement it // represents. OunceMass Mass = 28349523125 * NanoGram // Pound is both a unit of mass and weight (force). The suffix Mass is added // to disambiguate the measurement it represents. PoundMass Mass = 16 * OunceMass Slug Mass = 14593903 * MilliGram )
type Power ¶
type Power int64
Power is a measurement of power stored as a nano watts.
The highest representable value is 9.2GW.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(1 * physic.Watt) fmt.Println(16 * physic.MilliWatt) fmt.Println(1210 * physic.MegaWatt) }
Output: 1W 16mW 1.210GW
type Pressure ¶
type Pressure int64
Pressure is a measurement of force applied to a surface per unit area (stress) stored as an int64 nano Pascal.
The highest representable value is 9.2GPa.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(101010 * physic.Pascal) fmt.Println(101 * physic.KiloPascal) }
Output: 101.010kPa 101kPa
const ( // Pascal is N/m², kg/m/s². NanoPascal Pressure = 1 MicroPascal Pressure = 1000 * NanoPascal MilliPascal Pressure = 1000 * MicroPascal Pascal Pressure = 1000 * MilliPascal KiloPascal Pressure = 1000 * Pascal MegaPascal Pressure = 1000 * KiloPascal GigaPascal Pressure = 1000 * MegaPascal )
type RelativeHumidity ¶
type RelativeHumidity int32
RelativeHumidity is a humidity level measurement stored as an int32 fixed point integer at a precision of 0.00001%rH.
Valid values are between 0% and 100%.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(506 * physic.MilliRH) fmt.Println(20 * physic.PercentRH) }
Output: 50.6%rH 20%rH
const ( TenthMicroRH RelativeHumidity = 1 // 0.00001%rH MicroRH RelativeHumidity = 10 * TenthMicroRH // 0.0001%rH MilliRH RelativeHumidity = 1000 * MicroRH // 0.1%rH PercentRH RelativeHumidity = 10 * MilliRH // 1%rH )
func (RelativeHumidity) String ¶
func (r RelativeHumidity) String() string
String returns the humidity formatted as a string.
type SenseEnv ¶
type SenseEnv interface { conn.Resource // Sense returns the value read from the sensor. Unsupported metrics are not // modified. Sense(env *Env) error // SenseContinuous initiates a continuous sensing at the specified interval. // // It is important to call Halt() once done with the sensing, which will turn // the device off and will close the channel. SenseContinuous(interval time.Duration) (<-chan Env, error) // Precision returns this sensor's precision. // // The env values are set to the number of bits that are significant for each // items that this sensor can measure. // // Precision is not accuracy. The sensor may have absolute and relative // errors in its measurement, that are likely well above the reported // precision. Accuracy may be improved on some sensor by using oversampling, // or doing oversampling in software. Refer to its datasheet if available. Precision(env *Env) }
SenseEnv represents an environmental sensor.
type Speed ¶
type Speed int64
Speed is a measurement of magnitude of velocity stored as an int64 nano Metre per Second.
The highest representable value is 9.2Gm/s.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(10 * physic.MilliMetrePerSecond) fmt.Println(physic.LightSpeed) fmt.Println(physic.KilometrePerHour) fmt.Println(physic.MilePerHour) fmt.Println(physic.FootPerSecond) }
Output: 10mm/s 299.792Mm/s 277.778mm/s 447.040mm/s 304.800mm/s
const ( // MetrePerSecond is m/s. NanoMetrePerSecond Speed = 1 MicroMetrePerSecond Speed = 1000 * NanoMetrePerSecond MilliMetrePerSecond Speed = 1000 * MicroMetrePerSecond MetrePerSecond Speed = 1000 * MilliMetrePerSecond KiloMetrePerSecond Speed = 1000 * MetrePerSecond MegaMetrePerSecond Speed = 1000 * KiloMetrePerSecond GigaMetrePerSecond Speed = 1000 * MegaMetrePerSecond LightSpeed Speed = 299792458 * MetrePerSecond KilometrePerHour Speed = 277777778 * NanoMetrePerSecond MilePerHour Speed = 447040 * MicroMetrePerSecond FootPerSecond Speed = 304800 * MicroMetrePerSecond )
type Temperature ¶
type Temperature int64
Temperature is a measurement of hotness stored as a nano kelvin.
Negative values are invalid.
The highest representable value is 9.2GK.
Example ¶
package main import ( "fmt" "periph.io/x/periph/conn/physic" ) func main() { fmt.Println(0 * physic.Kelvin) fmt.Println(23010*physic.MilliCelsius + physic.ZeroCelsius) fmt.Println(80*physic.Fahrenheit + physic.ZeroFahrenheit) }
Output: -273.150°C 23.010°C 26.666°C
const ( NanoKelvin Temperature = 1 MicroKelvin Temperature = 1000 * NanoKelvin MilliKelvin Temperature = 1000 * MicroKelvin Kelvin Temperature = 1000 * MilliKelvin KiloKelvin Temperature = 1000 * Kelvin MegaKelvin Temperature = 1000 * KiloKelvin GigaKelvin Temperature = 1000 * MegaKelvin // Conversion between Kelvin and Celsius. ZeroCelsius Temperature = 273150 * MilliKelvin MilliCelsius Temperature = MilliKelvin Celsius Temperature = Kelvin // Conversion between Kelvin and Fahrenheit. ZeroFahrenheit Temperature = 255372 * MilliKelvin MilliFahrenheit Temperature = 555555 * NanoKelvin Fahrenheit Temperature = 555555555 * NanoKelvin )
func (Temperature) String ¶
func (t Temperature) String() string
String returns the temperature formatted as a string in °Celsius.