MWX Library
latest_en
latest_en
  • The MWX Library
  • revision history
  • About the MWX library
    • License
    • Terms
    • The design policy
  • Install and Build
    • Environment (OS, etc.)
    • Installing the TWELITE SDK
    • Building ACT
    • Creating a new project
    • Installing VSCode
    • Build definition Makefile
    • Other platforms
  • Sample ACTs
    • act0 .. 4
    • Scratch
    • Slp_Wk_and_Tx
    • Parent_MONOSTICK
    • PingPong
    • BRD_APPTWELITE
    • BRD_I2C_TEMPHUMID
    • PAL_AMB
    • PAL_AMB-usenap
    • PAL_AMB-bhv
    • PAL_MAG
    • PAL_MOT-single
    • PAL_MOT-fifo
    • PulseCounter
    • WirelessUART
    • Rcv_Univsl
    • Unit_???
  • API
    • Definition.
    • class object
      • the_twelite
      • Analogue
      • Buttons
      • EEPROM
      • PulseCounter
      • Serial
      • SerialParser
      • SPI
        • SPI (using member functions)
        • SPI (using helper class)
      • TickTimer
      • Timer0 .. 4
      • Wire
        • Wire (using member functions))
        • Wire (using helper class)
    • Classes
      • MWX_APIRET
      • alloc
      • axis_xyzt
      • packet_rx
      • packet_tx
      • serparser
      • pktparser
        • E_PKT
        • idenify_packet_type()
        • TwePacket
          • TwePacketTwelite
          • TwePacketIO
          • TwePacketUART
          • TwePacketPAL
      • smplbuf
        • .get_stream_helper()
        • smplbuf_strm_u8
      • smplque
      • mwx::stream
        • format (mwx::mwx_format)
        • mwx::bigendian
        • mwx::crlf
        • mwx::flush
        • stream_helper
      • SM_SIMPLE state machine
    • Call back functions
      • setup()
      • begin()
      • loop()
      • wakeup()
      • init_coldboot()
      • init_warmboot()
      • on_rx_packet()
      • on_tx_comp()
    • BEHAVIOR
      • PAL_AMB-behavior
    • Functions
      • System Functions
        • millis()
        • delay()
        • delayMicroseconds()
        • random()
      • DIO General purpose IO
        • pinMode()
        • digitalWrite()
        • digitalRead()
        • attachIntDio()
        • detachIntDio()
        • digitalReadBitmap()
      • Utility Functions
        • Printf utils
        • pack_bits()
        • collect_bits()
        • Byte array utils
        • pack_bytes()
        • expand_bytes()
        • CRC8, XOR, LRC
        • div100()
        • Scale utils
        • pnew
    • External Libraries
      • EASTL
  • Board (BRD)
    • <BRD_APPTWELITE>
    • <MONOSTICK>
    • PAL
      • <PAL_AMB>
      • <PAL_MAG>
      • <PAL_MOT>
      • <PAL_NOTICE>
    • <CUE>
  • Sensor Devices (SNS)
    • SHTC3 - Temp/Humd sensor
    • SHT3x - Temp/Humd sensor
    • LTR-308ALS - Luminance Sensor
    • MC3630 - Accel sensor
    • BMx280 - Temp/Humd/Pressure Sensor
    • PCA9632 - LED Driver
  • Network (NWK)
    • Simple Relay Net <NWK_SIMPLE>
    • Layered Tree Net <NWK_LAYERED>
  • Settings (STG) - Interactive settings mode
    • <STG_STD>
GitBook提供
このページ内
  • scale_1000_to_127u8()
  • scale_127u8_to_1000()
  • scale_1000_to_255u8()
  • scale_255u8_to_1000()
  • scale_1000_to_256u8()
  • scale_256u16_to_1000()
  • Background
PDFとしてエクスポート
  1. API
  2. Functions
  3. Utility Functions

Scale utils

scaling function between 0..1000 and 0..255.

Scale (expand and contract) with 8-bit values (0..25, etc.) and user-friendly 0..1000 (thousandths, ‰) values. Approximate computation by multiplication and bit shift instead of division (x*1000/255) for low computational cost.

static inline uint8_t scale_1000_to_127u8(uint16_t x)
static inline uint16_t scale_127u8_to_1000(uint8_t x)
static inline uint8_t scale_1000_to_255u8(uint16_t x)
static inline uint16_t scale_255u8_to_1000(uint8_t x)
static inline uint8_t scale_1000_to_256u8(uint16_t x)
static inline uint16_t scale_256u16_to_1000(uint16_t x)

scale_1000_to_127u8()

Scale 0..1000 to 0..127. Approximate calculation using (16646*x+65000)>>17.

scale_127u8_to_1000()

Scale 0..127 to 0..1000. Approximate calculation using (2064000UL*x+131072)>>18.

scale_1000_to_255u8()

Scales 0..1000 to 0..255. Approximate calculation using (33423*x+65000)>>17.

scale_255u8_to_1000()

Scales 0..255 to 0..1000. Approximate calculation using (1028000UL*uint32_t(x)+131072)>>18.

scale_1000_to_256u8()

Scales 0..1000 to 0..256. Approximate calculation using (33554*x+66000) >> 17.

Note: x=999,1000 returns 255 as the range of uint8_t even though the calculated value is 256.

scale_256u16_to_1000()

Scale 0..256 to 0..1000. Approximate calculation using (1028000UL*uint32_t(x)+131072)>>18.

Background

Values to be set in hardware are often based on binary numbers such as 0...255, while numbers to be handled in user applications are easier to handle based on decimal numbers such as 0...1000. We defined an expression that does not perform division for these scale conversions.

前へdiv100()次へpnew

最終更新 2 年前