IoT_iOS source code issue

Learn MoreFAQsTutorials

4 posts / 0 new
Last post
pureform
Offline
Last seen:5 months 1 day ago
加入:2017-12-28 08:37
IoT_iOS source code issue

I'm building a new project with Swift 4, with reference to the source code.
I came across with a section that is written in Objective C.
Would like to know how to write that part in terms of Swift. Any help would be greatly appreciated.

############################################
Source code (in GyroscopeSensorViewController.m)
############################################

(void) parseData:(NSData*)data {
UInt8 reportID, sensorState, sensorEvent;
[[data subdataWithRange:NSMakeRange(0, 1)] getBytes:&reportID length:1];
[[data subdataWithRange:NSMakeRange(1, 1)] getBytes:&sensorState length:1];
[[data subdataWithRange:NSMakeRange(2, 1)] getBytes:&sensorEvent length:1];

int16_t x, y, z;
[[data subdataWithRange:NSMakeRange(3, 2)] getBytes:&x length:2];
[[data subdataWithRange:NSMakeRange(5, 2)] getBytes:&y length:2];
[[data subdataWithRange:NSMakeRange(7, 2)] getBytes:&z length:2];

float _x, _y, _z;
_x = (float) x / 16.4f;
_y = (float) y / 16.4f;
_z = (float) z / 16.4f;

lastValueX = _x;
lastValueY = _y;
lastValueZ = _z;

rotateX += (lastValueX) / self.gyroscopeRate;
rotateY += (lastValueY) / self.gyroscopeRate;
rotateZ += (lastValueZ) / self.gyroscopeRate;

//NSLog(@"ROT %.2f %.2f %.2f => %.2f %.2f %.2f (%d)", lastValueX, lastValueY, lastValueZ, rotateX, rotateY, rotateZ, self.gyroscopeRate);

FLog(@"GYR\t%.2fdeg\t%.2fdeg\t%.2fdeg", _x/self.gyroscopeRate, _y/self.gyroscopeRate, _z/self.gyroscopeRate);

isDirty = TRUE;
}

Keywords:
Device:
MT_dialog
Offline
Last seen:1 day 22 min ago
Staff
加入:2015-06-08 11:34
Hi pureform,

Hi pureform,

Sorry, but we are not able to provide coding advices in Android or iOS platforms, this question is out of scope of this forum.

Thanks MT_dialog

pureform
Offline
Last seen:5 months 1 day ago
加入:2017-12-28 08:37
Thank you for your prompt

Thank you for your prompt reply.

You mentioned that your team already has an updated source code in place but waiting for QA.
Is it possible to share just the updated version of this file instead?
This is very urgent for our project.

MT_dialog
Offline
Last seen:1 day 22 min ago
Staff
加入:2015-06-08 11:34
Hi pureform,

Hi pureform,

The new source code of the IoT is uploaded on the support site.

Thanks MT_dialog