DDC
  • Welcome
    • Introduction
    • Supported hardware
  • 1: Project planning
    • Switch inputs
      • Switch table
      • Direct
      • Shift register
      • Port expander
    • Analog inputs
      • External ADC
    • RGB LED
    • Digital outputs
    • PWM / Circuit control
    • EEPROM
    • Processing and memory
  • 2. Wiring
    • Switch inputs
      • Matrix
      • Direct
      • Shift register
      • Port expander
    • Analog
      • Analog switches
      • External ADC
    • RGB LED
    • Digital outputs
    • PWM / Circuit control
    • EEPROM
  • 3. Coding
    • Essentials
      • 02_Board.ino
      • 08_Joystick
      • 10_TableAndAnalog.ino
        • Switch table
        • Analog channels
      • 30_Switches.ino
    • Peripherals
      • RGB LED
        • Firmware control
          • LED functions
          • Color
          • Brightness
          • Presets
        • SimHub control
      • Digital outputs
        • Setup
        • SimHub control
        • Firmware control
      • PWM / Circuit control
        • Setup
        • Calibrate
        • Switch control
        • Trigger control
      • Shift register
      • I2C devices
        • ADS1115
        • PCA9555
        • CAT24C512
    • Advanced
      • Analog inject
      • Conditional coding
        • Triggers
        • Editors
      • Field placement
      • Presets
        • 31_RunningPresets.ino
        • 32_Presets.ino
        • Example
    • Upload
    • Naming the controller
  • 4. Connect to SimHub
    • LED control
    • Controller settings and properties
      • How to connect?
      • How does it work?
      • How to control it?
      • Property list
  • Switch library
    • Pushbutton
    • Function switches
    • Toggle switches
    • Hat switches
    • Car control functions
      • QuickSwitch
      • BrakeMagic
      • ThrottleHold
      • Handbrake
    • Pedals & paddles
      • Brake/throttle
      • Clutch
      • Bite point & launch
      • Filtered curves
      • Shifter
    • Funky switch
      • Directional
      • Center push
    • Encoders
      • rotary2Bit
      • rotary4Bit
      • funkyRotary
      • wildEncoder
      • E18
      • rotaryPulse
      • PEC11
    • Rotary switches
      • rotaryAnalog
      • quickRotary
      • SW1
      • Editing functions
    • Multiswitch complexes
      • Hybrid rotary
      • Multifunction rotary
      • Modded encoder
      • Stacked encoder
    • Preset
    • DDS
    • RGB LED control
    • PWM / Circuit control
    • Utility
  • Fast DDC
    • Buttons and LED
    • 4 encoders, buttons and LED
    • Dual clutches, 4 encoders, buttons and LED
    • Dual clutches, 6 encoders, button matrix and LED
  • CB1
    • Ordering
      • Order together
      • Order yourself
        • 1. Open in EasyEDA
        • 2. Export files
        • 3. Edit Pick&Place
        • 4. Pin headers and jumper
        • 5. Order from JLCPCB
    • Wiring
    • Code
      • Essentials
      • Complete project
      • Settings
    • Circuit
    • Shields
      • Robin
  • Collaboration
Powered by GitBook
On this page
  • Bit fields
  • Bit fields in DDC
  1. 4. Connect to SimHub
  2. Controller settings and properties

How does it work?

PreviousHow to connect?NextHow to control it?

Last updated 4 months ago

Bit fields

The controller settings are sent over USB as two bit fields.

To explain what a bit field is, I'll have to explain a few other things first.

Bits are the building blocks, the currency and the language in computing. A single bit is essentially an on/off-switch. The bit is a logical state 0 or 1. On or off. Often, it represents a physical component, such as the charge of a capacitor or the conduction properties of a transistor. A flash memory drive has millions of transistors, each representing a bit, each possible to change between two states.

In programming, a single bit is usually too small to work with. If you want to express a number of a certain size, you'll need a bunch of bits. So we're working with several bits at the time.

When programming microcontrollers, typically the smallest package of bits is 8 (such as a byte). When programming applications it is usually 16. Everything is built around using these different sized packages of bits. Think of it like buying a pack of cigarettes. Buying single sigarettes is not possible (at least not where I'm from), you'll have to adhere to the system and buy 20 at the time.

This means that if I have eight different settings in my firmware that is either on or off, and I want to express this in code, I'll have to pop an 8-pack of bits (byte) for each one. Since I'm only trying to express on/off (1 or 0), I'll only be using the first bit in each byte. The remaining 7 bits are never used. The equivalent in cigarettes is that if you need 8 cigarettes, you'll buy 8 packets of cigarettes and only take a single cigarette from each. Sounds crazy? Well this is how it works. It is more convenient this way, and trying to make use of every bit in every byte will require more processing power.

However, if we're going to send information somewhere, it is not necessarily convenient anymore. We'd like the information to be as condensed as possible, since sending stuff both takes time and processing power. In that case it might be worth trying to make use of every bit. Instead of using 8 bytes for my 8 on/off-settings, I'll try to use every bit of a single byte.

Before I had 8 bytes that had a value of either 1 or 0. Now I have a single byte who's value doesn't make much sense anymore. Lets say that setting number 1, 4 and 8 are on, and the others are off. The bits in the byte would spell out like 10001001. In decimal number this is 137. But in this context, the number 137 doesn't mean anything. This byte is only useful if it comes with an explaination:

And now we have a bit field; a package of bits with more information that just the total value of the package. Bit fields have to come with an explaination, or else you wont know which bit means what.

Bit fields in DDC

DDC sends controller settings in two 16-bit packages. 32 bits total, 32 settings on/off. These two fields are named rotaryField and buttonField. Don't mind the names, they don't mean anything. You can have a look at 19_Bitfields to see how they are structured:

//-------------------------------------
//--BIT FIELDS FOR SIMHUB PROPERTIES---
//-------------------------------------

int rotaryField = 0;

/*
 * First field, pushed to joysick axis Z

 Most significant
 16 - Unused because of bug in joystick library
 15 - Bite button pressed
 14 - Dual clutches
 13 - Dual clutches
 12 - Bite point setting
 11 - Bite point setting
 10 - DDS switch
 9 -- DDS switch
 8 -- Calibration active
 7
 6
 5
 4
 3
 2
 1
 Least significant

 */
 

int buttonField = 0;

/*
 * Second field, pushed to joysick axis Y

 Most significant
 16 - Unused because of joystick library bug
 15 - Neutral mode
 14 - Presets 4th bit
 13 - Presets 3rd bit
 12 - Presets 2nd bit
 11 - Presets 1st bit
 10 - Handbrake active
 9 -- QuickSwitch active
 8 -- QuickSwitch mode
 7 -- Magic button active
 6 -- Throttle Hold active
 5 -- Neutral active
 4
 3
 2
 1
 Least significant

 */

```

The top one is rotaryField, the bottom one is buttonField. As you can see, many of the bits in each field is already in use. Only 4 bits available in buttonField and 7 in rotaryField. This is because many of the DDC functions will automatically send info to these fields. Such as magic button activation, dual clutches modes and current preset selected. However, if you're not using any of these functions, you can overwrite their place in the fields. Feel free to edit these comments in 19_Bitfields and set up the fields the way you like.

In the plugin, the fields are displayed at the bottom:

The colored boxes are the ones that are reserved for specific functions.