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)

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

Warning

This setting will consume a significant amount of memory.

#include "elpekenin/sync.h"

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

// time in milliseconds
const sync_config_t PROGMEM sync_configs[] = {
    SYNC_TIMER(foo, 200),
    SYNC_CHANGE(bar),
};
SYNC_TIMER(variable, ms_rate)
[source]

Synch a variable on a timely basis.

SYNC_CHANGE(variable)
[source]

Synch a variable upon its value changing.