[Armadeus-commitlog] SF.net SVN: armadeus: [814] trunk/target/demos/backlight_control
Brought to you by:
sszy
|
From: <ar...@us...> - 2008-06-01 09:43:33
|
Revision: 814
http://armadeus.svn.sourceforge.net/armadeus/?rev=814&view=rev
Author: artemys
Date: 2008-06-01 02:43:34 -0700 (Sun, 01 Jun 2008)
Log Message:
-----------
[DEMOS] Improve backlight tool (compiling and running on target
Modified Paths:
--------------
trunk/target/demos/backlight_control/Makefile
trunk/target/demos/backlight_control/README
trunk/target/demos/backlight_control/backlight.c
trunk/target/demos/backlight_control/backlight_sysctl.c
trunk/target/demos/backlight_control/backlight_sysctl.h
Added Paths:
-----------
trunk/target/demos/backlight_control/data/
trunk/target/demos/backlight_control/data/cursor.bmp
trunk/target/demos/backlight_control/data/empty.bmp
trunk/target/demos/backlight_control/data/empty_end.bmp
trunk/target/demos/backlight_control/data/full.bmp
trunk/target/demos/backlight_control/data/full_end.bmp
Removed Paths:
-------------
trunk/target/demos/backlight_control/cursor.bmp
trunk/target/demos/backlight_control/empty.bmp
trunk/target/demos/backlight_control/empty_end.bmp
trunk/target/demos/backlight_control/full.bmp
trunk/target/demos/backlight_control/full_end.bmp
Modified: trunk/target/demos/backlight_control/Makefile
===================================================================
--- trunk/target/demos/backlight_control/Makefile 2008-05-31 09:38:57 UTC (rev 813)
+++ trunk/target/demos/backlight_control/Makefile 2008-06-01 09:43:34 UTC (rev 814)
@@ -7,20 +7,22 @@
SDL_DIR:=$(BUILD_DIR)/SDL-1.2.11/
STAGING_DIR:=$(BUILD_DIR)/staging_dir/
ROOT_DIR:=$(BUILDROOT_DIR)/project_$(BUILD_DIR_EXT)/armadeus/root/
- INSTALL_DIR:=$(ROOT_DIR)/usr/bin/
CC:=$(STAGING_DIR)/bin/arm-linux-gcc
DEFINES="TARGET"
CFLAGS:=$(shell STAGING_DIR=$(STAGING_DIR) sh $(SDL_DIR)/sdl-config --cflags)
LIBS:=$(shell STAGING_DIR=$(STAGING_DIR) sh $(SDL_DIR)/sdl-config --libs)
else
- INSTALL_DIR="./install"
+ ROOT_DIR:="/"
CFLAGS=`/usr/bin/sdl-config --cflags`
LIBS=`/usr/bin/sdl-config --libs`
CC=gcc
DEFINES="HOST"
endif
+INSTALL_DIR:=$(ROOT_DIR)/usr/bin/
+INSTALL_DIR_DATA:=$(ROOT_DIR)/usr/share/apps/backlight/data
+
CFLAGS+="-g"
default: backlight
@@ -37,10 +39,16 @@
backlight: backlight.o backlight_sysctl.o
$(CC) $(LIBS) -o $@ $^
-install: backlight cursor.bmp empty.bmp empty_end.bmp full.bmp full_end.bmp
+install: install_tool install_data
+
+install_tool: backlight
mkdir -p $(INSTALL_DIR)
cp $^ $(INSTALL_DIR)
+install_data: data/cursor.bmp data/empty.bmp data/empty_end.bmp data/full.bmp data/full_end.bmp
+ mkdir -p $(INSTALL_DIR_DATA)
+ cp $^ $(INSTALL_DIR_DATA)
+
clean:
rm -rf backlight
rm -rf *.o
Modified: trunk/target/demos/backlight_control/README
===================================================================
--- trunk/target/demos/backlight_control/README 2008-05-31 09:38:57 UTC (rev 813)
+++ trunk/target/demos/backlight_control/README 2008-06-01 09:43:34 UTC (rev 814)
@@ -2,5 +2,5 @@
* ARM compiling:
$ make clean; make install
* x86 compiling (SDL devt package should be installed on your system)
- $ make TARGET=x86 clean; make TARGET=x86
+ $ make TARGET=x86 clean; make TARGET=x86; sudo make TARGET=x86 install_data
Modified: trunk/target/demos/backlight_control/backlight.c
===================================================================
--- trunk/target/demos/backlight_control/backlight.c 2008-05-31 09:38:57 UTC (rev 813)
+++ trunk/target/demos/backlight_control/backlight.c 2008-06-01 09:43:34 UTC (rev 814)
@@ -1,5 +1,4 @@
/*
- *
* Small tool to demonstrate how to use (or not use ;-) ) Tslib + SDL library
* for the Armadeus project. www.armadeus.og
*
@@ -23,7 +22,6 @@
#include <unistd.h> // for sleep()
#include "SDL.h"
-// To
#include "backlight_sysctl.h"
@@ -44,6 +42,8 @@
#define false 0
#define true 1
+#define DEFAULT_DATA_DIR "/usr/share/apps/backlight/data/"
+
SDL_Surface *cursor;
SDL_Surface *full_end;
SDL_Surface *full;
@@ -61,11 +61,11 @@
{
int result = 0;
- full_end = SDL_LoadBMP("./full_end.bmp");
- full = SDL_LoadBMP("./full.bmp");
- cursor = SDL_LoadBMP("./cursor.bmp");
- empty = SDL_LoadBMP("./empty.bmp");
- empty_end = SDL_LoadBMP("./empty_end.bmp");
+ full_end = SDL_LoadBMP( DEFAULT_DATA_DIR "full_end.bmp" );
+ full = SDL_LoadBMP( DEFAULT_DATA_DIR "full.bmp" );
+ cursor = SDL_LoadBMP( DEFAULT_DATA_DIR "cursor.bmp" );
+ empty = SDL_LoadBMP( DEFAULT_DATA_DIR "empty.bmp" );
+ empty_end = SDL_LoadBMP( DEFAULT_DATA_DIR "empty_end.bmp" );
// Check if we got all images
if( full_end == NULL || full == NULL || cursor == NULL || empty == NULL || empty_end == NULL )
@@ -83,7 +83,7 @@
return(result);
}
-//
+//
static void freeRessources()
{
SDL_FreeSurface( screen );
@@ -171,7 +171,7 @@
int x=0;
x = paddXPos( xpos );
- drawImage( cursor, x, BAR_YPOSITION-5);
+ drawImage( cursor, x, BAR_YPOSITION-5 );
}
//
@@ -183,6 +183,13 @@
SDL_Flip( screen );
}
+void cleanup( void )
+{
+ // Cleanup what we used
+ releaseBacklightControl();
+ freeRessources();
+ SDL_Quit();
+}
//---- Main ----
@@ -190,34 +197,22 @@
int main(int argc, char *argv[])
{
Uint8* keys;
- int nbFrames = 0;
int cursorPos = 0;
- //Timer fps, update;
- //Sint8 xspeed = 1, yspeed =1;
// Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER /*| SDL_INIT_EVENTTHREAD |SDL_INIT_NOPARACHUTE*/) < 0 )
{
- printf("Unable to init SDL: %s\n", SDL_GetError());
+ fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
- if (SDL_InitSubSystem(SDL_INIT_TIMER) == -1)
- {
- fprintf(stderr, "SDL timer failed to initialize! Error: %s\n", SDL_GetError());
- exit(1);
- }
- else
- {
- fprintf(stdout, "SDL timer initialized properly!\n");
- }
// Ask SDL to cleanup when exiting
- atexit(SDL_Quit);
+ atexit(cleanup);
// Get a screen to display our game
screen=SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0/*SDL_HWPALETTE*//*SDL_HWSURFACE|| SDL_DOUBLEBUF*/ );
if( screen == NULL )
{
- printf("Unable to set %dx%dvideo mode: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
+ fprintf(stderr, "Unable to set %dx%dvideo mode: %s\n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
exit(1);
}
@@ -233,16 +228,12 @@
{
printf("Unable to find Backlight control on your system -> won't be activated\n");
}
- updateCursor( (getBacklight() * BAR_WIDTH / 100) + BAR_MIN_XPOSITION );
+ updateCursor( (getBrightness() * BAR_WIDTH / 100) + BAR_MIN_XPOSITION );
int done=0, move=0;
// Hide mouse
SDL_ShowCursor(0);
- /* // Start timer for Frame Rate calculation
- update.start();
- fps.start();*/
-
// Main loop
while(done == 0)
{
@@ -280,36 +271,15 @@
}
if( cursorPos != 0 && move == 1 ) {
-
//
- setBacklight( calculateBacklight( cursorPos ) );
+ setBrightness( calculateBacklight( cursorPos ) );
// Update screen
updateCursor( cursorPos );
- nbFrames++;
}
- // Calculate and stabilize Frame Rate
-/* if( update.getTicks() > 1000 )
- {
- printf("FPS: %f\n", (float)nbFrames );
- update.start();
- nbFrames = 0;
- }
- while( fps.getTicks() < (1000 / NB_FRAMES_PER_SECOND) )
- {
- ;
- }
- fps.start();
-*/
SDL_Delay(50);
}
- // Cleanup what we used
- releaseBacklightControl();
- freeRessources();
- SDL_QuitSubSystem( SDL_INIT_TIMER );
- SDL_Quit();
-
return 0;
}
Modified: trunk/target/demos/backlight_control/backlight_sysctl.c
===================================================================
--- trunk/target/demos/backlight_control/backlight_sysctl.c 2008-05-31 09:38:57 UTC (rev 813)
+++ trunk/target/demos/backlight_control/backlight_sysctl.c 2008-06-01 09:43:34 UTC (rev 814)
@@ -2,62 +2,65 @@
#include <stdio.h>
#include <stdlib.h>
-#include "backlight_sysctl.h"
-int playing, initialized = 0;
-FILE* fd;
-FILE* fda;
-unsigned char currentBacklight = 0;
+int initialized = 0;
+FILE* fd_bright;
+FILE* fd_max;
+unsigned char current_brightness = 0;
+int max_brightness = 255;
#ifdef TARGET
-#define FREQ_SYS_FILE "/sys/class/pwm/pwm0/frequency"
-#define ACTIVE_SYS_FILE "/sys/class/pwm/pwm0/active"
+#define BRIGHTNESS_SYS_FILE "/sys/class/backlight/imxl-bl/brightness"
+#define MAX_BRIGHTNESS_SYS_FILE "/sys/class/backlight/imxl-bl/max_brightness"
#else
-#define FREQ_SYS_FILE "./backlight.dat"
-#define ACTIVE_SYS_FILE "./active"
+#define BRIGHTNESS_SYS_FILE "./backlight.dat"
+#define MAX_BRIGHTNESS_SYS_FILE "./backlight.dat"
#endif // TARGET
-SDL_TimerID myTimerID;
-
/*
* Initialize the system
- *
*/
int initBacklightControl()
{
int result = -1;
+ int size = 0;
+ char buffer[6];
if( !initialized )
{
- playing = 0;
- fd = fopen( FREQ_SYS_FILE, "w+" );
- fda = fopen( ACTIVE_SYS_FILE, "w" );
+ fd_bright = fopen( BRIGHTNESS_SYS_FILE, "w+" );
+ fd_max = fopen( MAX_BRIGHTNESS_SYS_FILE, "r" );
- if( (fd != NULL) && (fda != NULL) )
+ if( (fd_bright != NULL) && (fd_max != NULL) )
{
result = 0;
initialized = 1;
#ifdef TARGET
-
+ size = fread( buffer, 1, 6, fd_max );
+ max_brightness = atoi(buffer);
+ printf("Max: %i\n", max_brightness);
+ size = fread( buffer, 1, 6, fd_bright );
+ current_brightness = atoi(buffer);
+ printf("Current: %i\n", current_brightness);
#else
- currentBacklight = 50; // %
+ current_brightness = 50; // %
#endif // TARGET
- } else
- printf("Buzzer: can't open /sys interface\n");
+ } else {
+ printf("Backlight: can't open %s interface\n", BRIGHTNESS_SYS_FILE);
+ }
}
return( result );
}
/*
* Free ressources allocated by the "library"
- *
*/
void releaseBacklightControl()
{
if( initialized )
{
- fclose( fd );
- fclose( fda );
+ fclose( fd_bright );
+ fclose( fd_max );
initialized = 0;
}
}
@@ -65,25 +68,27 @@
/*
* 0-100 %
*/
-void setBacklight( unsigned char aValue )
+void setBrightness( unsigned char aValue )
{
if( initialized )
{
char value[4]; int nchar;
+ if( aValue > 100 ) aValue = 100;
+ aValue = (aValue * max_brightness) / 100;
- // Program PWM with given frequency
+ // Send it to hardware
nchar = sprintf( value, "%d", aValue);
- fwrite( value, 1, nchar, fd );
- fflush( fd );
- currentBacklight = aValue;
+ fwrite( value, 1, nchar, fd_bright );
+ fflush( fd_bright );
+ current_brightness = aValue;
}
}
/*
* 0-100 %
*/
-unsigned char getBacklight( void )
+unsigned char getBrightness( void )
{
- return( currentBacklight );
+ return( (current_brightness * 100) / max_brightness );
}
Modified: trunk/target/demos/backlight_control/backlight_sysctl.h
===================================================================
--- trunk/target/demos/backlight_control/backlight_sysctl.h 2008-05-31 09:38:57 UTC (rev 813)
+++ trunk/target/demos/backlight_control/backlight_sysctl.h 2008-06-01 09:43:34 UTC (rev 814)
@@ -5,9 +5,12 @@
// Initialize the Backlight control library
int initBacklightControl( void );
-// Play a sound on buzzer at given frequency (Hz) and during given time (ms)
-void setBacklight( unsigned char aValue );
+// Set brightness to given value (0-100 %)
+void setBrightness( unsigned char );
+// Get current brightness (0-100 %)
+unsigned char getBrightness( void );
+
// Free ressources allocated by the Backlight control library
void releaseBacklightControl( void );
Deleted: trunk/target/demos/backlight_control/cursor.bmp
===================================================================
(Binary files differ)
Copied: trunk/target/demos/backlight_control/data/cursor.bmp (from rev 806, trunk/target/demos/backlight_control/cursor.bmp)
===================================================================
(Binary files differ)
Copied: trunk/target/demos/backlight_control/data/empty.bmp (from rev 806, trunk/target/demos/backlight_control/empty.bmp)
===================================================================
(Binary files differ)
Copied: trunk/target/demos/backlight_control/data/empty_end.bmp (from rev 806, trunk/target/demos/backlight_control/empty_end.bmp)
===================================================================
(Binary files differ)
Copied: trunk/target/demos/backlight_control/data/full.bmp (from rev 806, trunk/target/demos/backlight_control/full.bmp)
===================================================================
(Binary files differ)
Copied: trunk/target/demos/backlight_control/data/full_end.bmp (from rev 806, trunk/target/demos/backlight_control/full_end.bmp)
===================================================================
(Binary files differ)
Deleted: trunk/target/demos/backlight_control/empty.bmp
===================================================================
(Binary files differ)
Deleted: trunk/target/demos/backlight_control/empty_end.bmp
===================================================================
(Binary files differ)
Deleted: trunk/target/demos/backlight_control/full.bmp
===================================================================
(Binary files differ)
Deleted: trunk/target/demos/backlight_control/full_end.bmp
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|