Just to add on to the comments I have made earlier that the SMS sensor of the Macbook could be turned OFF by issuing the following command to the terminal
> sudo pmset -a sms 0
I was being asked if it is possible to read the value and used it as an accelerometer. The answer is Yes.
Here is a simple application that reads the accelerometer reading from a Snow leopard based Macbook
*tested on Macbook Pro*
//
// mainDisplay.m
// SMS_sensor3
//
// Created by Percy on 10/14/10.
// Copyright 2010 Minoyo. All rights reserved.
//
#import “mainDisplay.h”
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
@implementation mainDisplay
@synthesize x_Coord;
@synthesize y_Coord;
@synthesize z_Coord;
@synthesize auto_CheckBox;
@synthesize timer;
– (id)init {
structureInputSize = sizeof(struct motion_data);
structureOutputSize = sizeof(struct motion_data);
result = IOMasterPort(MACH_PORT_NULL, &masterPort);
CFMutableDictionaryRef matchingDictionary = IOServiceMatching(“SMCMotionSensor”);
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
if (result != KERN_SUCCESS)
{
NSLog(@”IOServiceGetMatchingServices returned error.\n”, stderr);
return 0;
}
aDevice = IOIteratorNext(iterator);
IOObjectRelease(iterator);
if(aDevice == 0)
{
NSLog(@”No motion sensor available\n”, stderr);
return 0;
}
else
{
NSLog(@”Motion sensor device id = %d\n”, aDevice);
}
result = IOServiceOpen(aDevice, mach_task_self(), 0, &dataPort);
IOObjectRelease(aDevice);
if(result != KERN_SUCCESS)
{
NSLog(@”Could not open motion sensor device\n”, stderr);
return 0;
}
else
{
NSLog(@”Sucessfully open motion sensor device\n”);
}
return self;
}
-(IBAction) update_reading: (id) sender{
//x_Coord.text = @”Hello”;
//[x_Coord setTitleWithMnemonic:@”Hello”];
result = IOConnectCallStructMethod(dataPort,
5,
&inputStructure,
structureInputSize,
&outputStructure,
&structureOutputSize);
if(result != KERN_SUCCESS)
{
NSLog(@”no coords\n”);
}
else {
NSLog(@”%d %d %d\n”, outputStructure.x, outputStructure.y, outputStructure.z);
[x_Coord setTitleWithMnemonic:[NSString stringWithFormat:@”X Coord = %d”,outputStructure.x]];
[y_Coord setTitleWithMnemonic:[NSString stringWithFormat:@”Y Coord = %d”,outputStructure.y]];
[z_Coord setTitleWithMnemonic:[NSString stringWithFormat:@”Z Coord = %d”,outputStructure.z]];
}
}
-(IBAction) checkbox_clicked: (id) sender{
if ([auto_CheckBox state] == NSOnState){
timer = [NSTimer scheduledTimerWithTimeInterval: 0.5
target: self
selector: @selector(handleTimer🙂
userInfo: nil
repeats: YES];
}
else
[timer invalidate];
}
– (void) handleTimer: (NSTimer *) timer{
[self update_reading:NULL];
}
@end
Wow! Finally I got a webpage from where I can actually
take helpful facts regarding my study and knowledge.
Check out my site :: search engine
I have learn a few excellent stuff here. Certainly price
bookmarking for revisiting. I wonder how much effort you set to make this sort
of magnificent informative website.
My blog post: clinical negligence legal aid
Today, I went to the beachfront with my children. I found a sea shell and
gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the
shell to her ear and screamed. There was a hermit crab inside and it
pinched her ear. She never wants to go back! LoL I know this is entirely off
topic but I had to tell someone!
My homepage – site search irresistible
Awesome! Its actually remarkable article, I have got much clear idea about from this post.
Check out my website :: medical negligence firms
I really like what you guys tend to be up too. This type of clever work and exposure!
Keep up the very good works guys I’ve you guys to blogroll.
Also visit my site: business person spends