Ejemplo n.º 1
0
    public static byte[] ToByteArray(DieSettings settings)
    {
        int size = Marshal.SizeOf <DieSettings>();

        System.IntPtr ptr = Marshal.AllocHGlobal(size);
        Marshal.StructureToPtr(settings, ptr, false);
        byte[] ret = new byte[size];
        Marshal.Copy(ptr, ret, 0, size);
        Marshal.FreeHGlobal(ptr);
        return(ret);
    }
Ejemplo n.º 2
0
    IEnumerator UploadSettingsCr(DieSettings settings)
    {
        // Prepare the die
        var prepareDie = new DieMessageTransferSettings();

        yield return(StartCoroutine(SendMessageWithAckRetryCr(prepareDie, DieMessageType.TransferSettingsAck, null)));

        // Die is ready, perform bulk transfer of the settings
        byte[] settingsBytes = DieSettings.ToByteArray(settings);
        yield return(StartCoroutine(UploadBulkDataCr(settingsBytes)));

        // We're done!
    }
Ejemplo n.º 3
0
    IEnumerator DownloadSettingsCr(System.Action <DieSettings> settingsReadCallback)
    {
        // Request the settings from the die
        yield return(StartCoroutine(SendMessageWithAckRetryCr(new DieMessageRequestSettings(), DieMessageType.TransferSettings, null)));

        // Got the message, acknowledge it
        PostMessage(new DieMessageTransferSettingsAck());

        byte[] settingsBytes = null;
        yield return(StartCoroutine(DownloadBulkDataCr((buf) => settingsBytes = buf)));

        var newSettings = DieSettings.FromByteArray(settingsBytes);

        // We've read the settings
        settingsReadCallback.Invoke(newSettings);
    }
Ejemplo n.º 4
0
    public IEnumerator DownloadSettings(System.Action <DieSettings> settingsReadCallback)
    {
        // Request the settings from the die
        SendMessage(new DieMessageRequestSettings());

        // Now wait for the setup message back
        yield return(StartCoroutine(WaitForMessage(DieMessageType.TransferSettings, null)));

        // Got the message, acknowledge it
        StartCoroutine(SendMessage(new DieMessageTransferSettingsAck()));

        byte[] settingsBytes = null;
        yield return(StartCoroutine(DownloadBulkData((buf) => settingsBytes = buf)));

        var newSettings = DieSettings.FromByteArray(settingsBytes);

        // We've read the settings
        settingsReadCallback.Invoke(newSettings);
    }
Ejemplo n.º 5
0
    //public IEnumerator DownloadAnimationSet(AnimationSet outSet)
    //{
    //    // Request the anim set from the die
    //    SendMessage(new DieMessageRequestAnimSet());

    //    // Now wait for the setup message back
    //    int animCount = 0;
    //    yield return StartCoroutine(WaitForMessage(DieMessageType.TransferAnimSet, (msg) =>
    //    {
    //        var setupMsg = (DieMessageTransferAnimSet)msg;
    //        animCount = setupMsg.count;
    //    }));

    //    // Got the message, acknowledge it
    //    StartCoroutine(SendMessage(new DieMessageTransferAnimSetAck()));

    //    outSet.animations = new RGBAnimation[animCount];
    //    for (int i = 0; i < animCount; ++i)
    //    {
    //        byte[] animData = null;
    //        yield return StartCoroutine(DownloadBulkData((buf) => animData = buf));
    //        outSet.animations[i] = RGBAnimation.FromByteArray(animData);

    //        // Tell die we're ready for next anim
    //        StartCoroutine(SendMessage(new DieMessageTransferAnimReadyForNextAnim()));
    //    }

    //    // We've read all the anims!
    //}


    public Coroutine UploadSettings(DieSettings settings)
    {
        return(PerformBluetoothOperation(UploadSettingsCr(settings)));
    }