Created
October 18, 2016 12:38
-
-
Save hoiberg/9d041623506970e927461051c16678e2 to your computer and use it in GitHub Desktop.
MSP_SET_RAW_RC in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ********** Here's the javascript version ************* | |
// /** | |
// * Set raw Rx values over MSP protocol. | |
// * | |
// * Channels is an array of 16-bit unsigned integer channel values to be sent. 8 channels is probably the maximum. | |
// **/ | |
// | |
//MSP.setRawRx = function(channels) { | |
// var buffer = []; | |
// | |
// for (var i = 0; i < channels.length; i++) { | |
// buffer.push(specificByte(channels[i], 0)); | |
// buffer.push(specificByte(channels[i], 1)); | |
// } | |
// | |
// MSP.send_message(MSP_codes.MSP_SET_RAW_RC, buffer, false); | |
//} | |
// ************** Sample swift notation ************** | |
func sendRawRC(channels: [UInt16]) { | |
var bytes: [UInt8] = [] | |
for chan in channels { | |
bytes.append(chan.lowByte) // lower first, small endian notation | |
bytes.append(chan.highByte) // ..if I'm correct :) | |
} | |
sendMSP(MSP_SET_RAW_RC, bytes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!! I will try this out!