Download Yocto-MiniDisplay, user manual
Transcript
12. Using Yocto-MiniDisplay with Objective-C
NSString *serial_or_name =[NSString stringWithUTF8String:argv[1]];
YModule *module = [YModule FindModule:serial_or_name]; // use serial or logical
name
if ([module isOnline]) {
if (argc > 2) {
if (strcmp(argv[2], "ON")==0)
[module setBeacon:Y_BEACON_ON];
else
[module setBeacon:Y_BEACON_OFF];
}
NSLog(@"serial:
%@\n", [module serialNumber]);
NSLog(@"logical name: %@\n", [module logicalName]);
NSLog(@"luminosity:
%d\n", [module luminosity]);
NSLog(@"beacon:
");
if ([module beacon] == Y_BEACON_ON)
NSLog(@"ON\n");
else
NSLog(@"OFF\n");
NSLog(@"upTime:
%d sec\n", [module upTime]/1000);
NSLog(@"USB current: %d mA\n", [module usbCurrent]);
NSLog(@"logs: %@\n", [module get_lastLogs]);
} else {
NSLog(@"%@ not connected (check identification and USB cable)\n",serial_or_name
);
}
}
return 0;
}
Each property xxx of the module can be read thanks to a method of type get_xxxx, and
properties which are not read-only can be modified with the help of the set_xxx: method. For
more details regarding the used functions, refer to the API chapters.
Changing the module settings
When you want to modify the settings of a module, you only need to call the corresponding
set_xxx: function. However, this modification is performed only in the random access memory
(RAM) of the module: if the module is restarted, the modifications are lost. To memorize them
persistently, it is necessary to ask the module to save its current configuration in its permanent
memory. To do so, use the saveToFlash method. Inversely, it is possible to force the module to
forget its current settings by using the revertFromFlash method. The short example below
allows you to modify the logical name of a module.
#import <Foundation/Foundation.h>
#import "yocto_api.h"
static void usage(const char *exe)
{
NSLog(@"usage: %s <serial> <newLogicalName>\n",exe);
exit(1);
}
int main (int argc, const char * argv[])
{
NSError *error;
@autoreleasepool {
// Setup the API to use local USB devices
if(yRegisterHub(@"usb", &error) != YAPI_SUCCESS) {
NSLog(@"RegisterHub error: %@", [error localizedDescription]);
return 1;
}
if(argc < 2)
usage(argv[0]);
NSString *serial_or_name =[NSString stringWithUTF8String:argv[1]];
YModule *module = yFindModule(serial_or_name); // use serial or logical name
if (module.isOnline) {
if (argc >= 3){
NSString *newname = [NSString stringWithUTF8String:argv[2]];
if (!yCheckLogicalName(newname)){
64
www.yoctopuce.com