Hint

Refer to QMK’s documentation for details on how to use community modules

sync

Synchronize variables over split comms.

Values are synchronized by writing to their memory addresses. As such, the variables need to be on the same address on both sides.
  • ☑ Global variables

  • ☐ Local variables (stack memory)

  • ☑ Local variables in a function marked as static

  • ☐ Dynamically-allocated variables (heap)

NOTE: Community modules don’t yet support custom IDs, you must add ELPEKENIN_SYNC_ID to your SPLIT_TRANSACTION_IDS_USER in config.h

SYNC_VARIABLE(variable)
[source]

Sync the value of variable to slave side.

#include "elpekenin/sync.h"

uint8_t my_variable = 0;

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    if (keycode == MY_KEYCODE && record->event.pressed) {
        my_variable += 1;
        SYNC_VARIABLE(my_variable);
        return false;
    }

    return true;
}

You can also define a list of variables to be synched automatically by the module.

For this, you need to add #define AUTO_SYNC_ENABLE on config.h

The sync will happen at a timely rate, and module won’t check whether the value has changed. As such, be careful not to use too-low of a value, slowing your keyboard down.

NOTE: Because the array has to be global, it can only reference/sync other global variables.

#include "elpekenin/sync.h"

size_t foo = 0;
struct { uint8_t x; bool y; } bar = {0};

// time in milliseconds
const sync_variable_t PROGMEM sync_variables[] = {
    AUTO_SYNC_VARIABLE(foo, 200),
    AUTO_SYNC_VARIABLE(bar, 1000),
};