macbook pro as a light meter!

milehigh_7

Mister 500,000
Messages
4,920
Reaction score
6,096
Location
Somewhere South of Phoenix
USDA Zone
Hot
I began wondering about indoor lighting levels after that thread on it the other day. Light meters can be pricey but I knew that my macbook pro had ambient light sensors (beautiful machine!) so I began looking for applications that could access these sensors.

As it turns out I found a small chunk of code that when compiled and executed in a terminal window returns the value in lux for in real time for the right and left sensors. Very nerdy I know but I thought it was cool. Here is a screen shot:
 

Attachments

  • luxMeter.jpg
    luxMeter.jpg
    11.7 KB · Views: 63

Bonsai Nut

Nuttier than your average Nut
Messages
12,421
Reaction score
27,872
Location
Charlotte area, North Carolina
USDA Zone
8a
Don't get me wrong, but I wonder how accurate it is? I think the idea is awesome!

And don't forget - for plants it is really important to get spectral intensities. Some meters are set up just to measure PAR (photosynthetically available radiation) for growing setups using artificial light.
 

Dr.GreenThumb

Sapling
Messages
41
Reaction score
0
Location
Norway
USDA Zone
6
I have a mac book pro and I want the code :)
Please send it to me asap.
Excellent !
 
Last edited:

milehigh_7

Mister 500,000
Messages
4,920
Reaction score
6,096
Location
Somewhere South of Phoenix
USDA Zone
Hot
Nut is right I have no idea how accurate it is as I do not have another meter to verify the readings. In any case here it is. Put these two files in a directory then rename the files and take off the .txt extension.

From a terminal window from the directory that contains your files type this compile command:
gcc -o lmutracker lmutracker.c -framework IOKit -framework CoreFoundation

execute by typing this in that same directory:
./lmutracker


NOTE: You will need the gcc compiler on your computer.
 

Attachments

  • lmucommon.h.txt
    557 bytes · Views: 11
  • lmutracker.c.txt
    1.8 KB · Views: 11

ccbaker17

Seed
Messages
1
Reaction score
0
when compiling the code you attached i get this error:

Imutracker.c:22: error: ‘IOConnectMethodScalarIScalarO’ was not declared in this scope

not too savvy with this stuff...any input?
 

edprocoat

Masterpiece
Messages
3,423
Reaction score
378
Location
Ohio/Florida
USDA Zone
6
when compiling the code you attached i get this error:

Imutracker.c:22: error: ‘IOConnectMethodScalarIScalarO’ was not declared in this scope

not too savvy with this stuff...any input?

This is the code posted->// lmutracker.c
//
// gcc -o lmutracker lmutracker.c -framework IOKit -framework CoreFoundation

#include <mach/mach.h>
#include <IOKit/IOKitLib.h>
#include <CoreFoundation/CoreFoundation.h>
#include "lmucommon.h"

static double updateInterval = 0.1;
static io_connect_t dataPort = 0;

void
updateTimerCallBack(CFRunLoopTimerRef timer, void *info)
{
kern_return_t kr;
IOItemCount scalarInputCount = 0;
IOItemCount scalarOutputCount = 2;
SInt32 left = 0, right = 0;

kr = IOConnectMethodScalarIScalarO(dataPort, kGetSensorReadingID,
scalarInputCount, scalarOutputCount, &left, &right);

if (kr == KERN_SUCCESS) {
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%8ld %8ld", left, right);
return;
}

if (kr == kIOReturnBusy)
return;

mach_error("I/O Kit error:", kr);
exit(kr);
}

int
main(void)
{
kern_return_t kr;
io_service_t serviceObject;
CFRunLoopTimerRef updateTimer;

// Look up a registered IOService object whose class is AppleLMUController
serviceObject = IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("AppleLMUController"));
if (!serviceObject) {
fprintf(stderr, "failed to find ambient light sensor\n");
exit(1);
}

// Create a connection to the IOService object
kr = IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort);
IOObjectRelease(serviceObject);
if (kr != KERN_SUCCESS) {
mach_error("IOServiceOpen:", kr);
exit(kr);
}

setbuf(stdout, NULL);
printf("%8ld %8ld", 0L, 0L);

// Set up the loop and let it run...
updateTimer = CFRunLoopTimerCreate(kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent() + updateInterval,
updateInterval, 0, 0, updateTimerCallBack, NULL);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), updateTimer, kCFRunLoopDefaultMode);
CFRunLoopRun();

exit(0);
}
That was from a cut and paste, when I opened it from the attachment above I immediately could see what code was showing was incomplete, but when I copied it and pasted here, to show you where the missing bracket was, the point where the code was incomplete, this whole code showed in the paste. If you manually copied it from the link, at least what I seen of it, that may have been your problem, try copying it by cutting and then pasting it in your compiler.

I am happy to hear that somebody finally found a use for a mac !! ;)

ed
 
Last edited:
Top Bottom