![]() |
2010-06-08
, 02:55
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#52
|
![]() |
2010-06-08
, 04:58
|
Posts: 254 |
Thanked: 122 times |
Joined on Nov 2009
|
#53
|
![]() |
2010-06-08
, 05:28
|
|
Posts: 4,930 |
Thanked: 2,272 times |
Joined on Oct 2007
|
#54
|
Benson, battery is not needed. Only dry reed and two resistors. Link to description and photos are in my previous post.
![]() |
2010-06-12
, 13:11
|
|
Posts: 1,559 |
Thanked: 1,786 times |
Joined on Oct 2009
@ Boston
|
#55
|
![]() |
2010-06-12
, 19:55
|
Posts: 254 |
Thanked: 122 times |
Joined on Nov 2009
|
#56
|
![]() |
2010-06-12
, 20:31
|
|
Posts: 1,559 |
Thanked: 1,786 times |
Joined on Oct 2009
@ Boston
|
#57
|
#include <sys/time.h> /* Headset button (AKA sensor) device file */ static const char *button_filename = "/sys/devices/platform/nokia-av/detect"; int read_button() { FILE *fd; char button = 0; fd = fopen(button_filename, "r"); button = fgetc(fd); // 4 is open, 2 (or 0 for hacked wiring) is closed fclose(fd); if (button == '4') return 0; else if (button == '2' || button == '0') return 1; else return -1; } int do_poll(int samples) { int presses = 0, button_status, old_button_status = 0; // WARNING: Assuming button is open at start could lead to overcounting presses by 1/frame for (int i=samples; i > 0; i--) { button_status = read_button(); if (!old_button_status && button_status > 0) presses++; // No error checking old_button_status = button_status; } return presses; int main(int argc, char **argv) { struct timeval start_poll, end_poll; float elapsed_time; while(1) { // Begin main loop. This only exits if a trigger file that was specified is deleted. gettimeofday( &start_poll, NULL ); presses = do_poll( 60 ); gettimeofday( &end_poll, NULL ); elapsed_time = (float)(end_poll.tv_usec - start_poll.tv_usec)/1000000.0; elapsed_time += end_poll.tv_sec - start_poll.tv_sec; printf("Revolutions: %i Elapsed: %0.2fs Hertz: %0.2f Approx. speed: %0.1fm/s\n", presses, elapsed_time, (float)presses/elapsed_time, presses*2.0/elapsed_time); } // End main loop return 0; }
![]() |
2010-06-12
, 21:01
|
Posts: 254 |
Thanked: 122 times |
Joined on Nov 2009
|
#58
|
![]() |
2010-06-23
, 13:52
|
Posts: 254 |
Thanked: 122 times |
Joined on Nov 2009
|
#59
|
The Following User Says Thank You to KiberGus For This Useful Post: | ||
![]() |
2010-06-23
, 17:17
|
Posts: 254 |
Thanked: 122 times |
Joined on Nov 2009
|
#60
|
Unofficial PR1.3/Meego 1.1 FAQ
Accelemymote: make your accelerometer more joy-ful