2012年3月21日 星期三

[Linux] 強制設定x window解析度

OS: ubuntu 11.04版
HW: disktop VIA VX900 內建顯卡
在x window裡因為讀不到顯示器的EDID,所以需要強制設定輸出解析度
How change display resolution settings using xrandr
1.查詢預設定解析度的內容
nash@ubuntu:/$ cvt 1920 1080 57
# 1920x768 56.9 Hz (CVT) hsync: 63.67 kHz; pclk: 163.0 MHz
Modeline "1920x1080_57.00" 163.00 1920 2042 2240 2560 1080 1083 1088 1119 -hsync +vsync
2.加入新的解析度到linux中
nash@ubuntu:/$ xrandr --newmode "1920x1080_57.00" 163.00 1920 2042 2240 2560 1080 1083 1088 1119 -hsync +vsync
3.查詢顯示器名稱
nash@ubuntu:/$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maxumum 4096 x 4096
VGA-1 connected 1920x1080+0+0(normal left inverted right x axis y axis)0mm x 0mm
1360x768 59.8
1024x768 60 * #表示目前使用中的解析度
800x600  60.3    56.2
848x480  60
640x480  59.6    59.9
4.加入預設定解析度到linux中
nash@ubuntu:/$ xrandr --addmode VGA-1 1920x1080_57.00
5.查詢解析度是否加入
nash@ubuntu:/$ xrandr
Screen 0: minimum 320 x 200, current 1920 x 1080, maxumum 4096 x 4096
VGA-1 connected 1920x1080+0+0(normal left inverted right x axis y axis)0mm x 0mm
1360x768 59.8
1024x768 60 * #表示目前使用中的解析度
800x600  60.3    56.2
848x480  60
640x480  59.6    59.9
1920x1080_57.00  57.0 #新增的解析度
6.輸出
建議用x window裡面system->Preferences->Monitors去設定新增的解析度,因為如果新增解析度不支援他在30秒後會回復到原本的設定解析度,不會一直卡在黑畫面,然後要重開機進到single去修改
如果有支援可用command line設定輸出

nash@ubuntu:/$ xrandr --output VGA-1 --mode 1920x1080_57.00 #此時畫面解析度就會變化了
7.以上設定均為暫時性所以需要寫到開機時執行以求每次開機都會設定此解析度
nash@ubuntu:/$ gksudo gedit /etc/gdm/Init/Default
..........
..........
PATH=/usr/bin:$PAT  #找到此兩行把指令加入到他下面即可
OLD_IFS=$IFS
xrandr --newmode "1920x1080_57.00" 163.00 1920 2042 2240 2560 1080 1083 1088 1119 -hsync +vsync
xrandr --addmode VGA-1 1920x1080_57.00
xrandr --output VGA-1 --mode 1920x1080_57.00
8.重新開機檢查是否成功

參考資料:
http://www.ubuntugeek.com/how-change-display-resolution-settings-using-xrandr.html
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?topic_id=34432&forum=3&post_id=159036#forumpost159036
https://wiki.ubuntu.com/X/Config/Resolution
http://shanereustle.com/blog/force-screen-resolutions-on-ubuntu.html


2012年3月19日 星期一

[Linux] mplayer play video in text mode(console)

OS: ubuntu 11.04
HW: VIA VX900
1.安裝mplayer
nash@ubuntu:/$ sudo apt-get install mplayer*  
2.安裝mplayer framebuffer套件
nash@ubuntu:/$ sudo apt-get install xine*  
3.檢查自身電腦的能力到哪
    一:下載軟體
nash@ubuntu:/$ sudo apt-get install hwinfo  
   二:下command查看
nash@ubuntu:/$ sudo hwinfo --framebuffer | grep Mode  
 可以看到list可支援的解析度有幾種


接下來就是下command來播播看
nash@ubuntu:/$ sudo mplayer -vo fbdev -vf scale=1280:1024 aaa.avi  
or
nash@ubuntu:/$ sudo mplayer -vo fbdev -zoom -x 1280 -y 1024 aaa.avi  
    


參考資料:
http://jamyy.dyndns.org/blog/2008/12/419.html
http://keykusosrw.blogspot.com/2011/08/framebuffer-console-2011-1.html
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=89685
http://ubuntu543.blogspot.com/2010/08/blog-post.html
https://wiki.ubuntu.com/FrameBuffer
http://www.tldp.org/HOWTO/Framebuffer-HOWTO/index.html
http://ubuntuforums.org/archive/index.php/t-258484.html
http://wiki.robotz.com/index.php/Framebuffer_Console

2012年3月16日 星期五

[Linux] ubuntu 11.04 autologin text mode

ubuntu 11.04
一:開機自動login到文字模式                    
1.修改/etc/defautle/grub
nash@ubuntu:/$ sudo vi /etc/default/grub 

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX_DEFAULT="quiet text"
GRUB_CMDLINE_LINUX=""
..........
..........
..........
更新
nash@ubuntu:/$ sudo update-grub

2.下載mingetty,and修改tty1.conf
nash@ubuntu:/$ sudo apt-get install mingetty
nash@ubuntu:/$ sudo vi /etc/init/tty1.conf
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system  is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 tty1
exec /sbin/mingetty --autologin username tty1 #username=自己的帳號

3.重開機
nash@ubuntu:/$ sudo reboot

二:取消sudo密碼
nash@ubuntu:/$ sudo vi /etc/sudoers

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
USERNAME ALL=(ALL) NOPASSWD: ALL
#includedir /etc/sudoers.d


參考文章:
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?viewmode=compact&topic_id=43964&forum=22
http://www.gnu.org/software/grub/manual/grub.html
http://ecken-tw.blogspot.com/2009/12/ubuntu-910-desktop-console-mode.html
http://www.linuxquestions.org/questions/linux-desktop-74/%5Bubuntu-10-04%5D-root-auto-login-to-console-mode-806030/
http://chiahu.com/blog/?p=456

2012年3月15日 星期四

[Linux] CentOS Disable power button in text mode

原因: 當按下power key後系統會自動關機
目的: 取消這個功能
OS: CentOS 6.2
1.先檢查BIOS中的電源管理item是否有Soft-Off by PWR-BTTN選項
    Soft-Off by PWR-BTTN < Instant-Off >
2.在/etc/acpi/events/ 中把powerbtn.conf裡的action mark就可以了

[root@localhost /]# vi /etc/acpi/events/powerbtn.conf
event=button/power.*
#action=.....
參考:http://www.centos.org/docs/5/html/5.1/Cluster_Administration/s2-bios-setting-CA.html
         http://bluequiet.blogspot.com/2009/05/linuxacpid.html

2012年3月14日 星期三

[Linux] how to login centos 6 text mode by user

記錄一下
在centos 6.2裡開機自動login user in text mode

for text based autologin in RHEL6, edit /etc/init/tty.conf

[user@localhost /]# sudo vi /etc/init/tty.conf
# tty  - getty 
#
# This service starts the configured number of gettys.


stop on RUNLEVEL=[S016]

respawn
instance $TTY
#exec /sbin/mingeety $TTY
exec /sbin/mingetty --autologin username $TTY //改成這樣


參考: http://sudhaker.com/23/centos-rhel-6-autologin

2012年3月12日 星期一

[Linux] read / write serial port

這幾天在CentOS 6.2裡練習寫 USB轉serial port功能記錄一下以免以後忘記


#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

int fd;
#define DEVICE "/dev/ttyUSB0"

int writeport(int fd, unsigned char *chars, int numBytes)
{
//show array contents
//printf("write array contents:\n");
int counter = 0;
printf("write array = ");
while(counter < numBytes)
{
printf("%x,", chars[counter]);
counter++;
}
printf("\n");

int n = write(fd, chars, numBytes);
if (n < 0) {
fputs("write failed!\n", stderr);
return 0;
}
//all good
return 1;
}

int readport(int fd, unsigned char *result)
{
int iIn = read(fd, result, 254); //13); //254);

//show result array
int counter = 0;
printf("read array = ");
while(counter < iIn)
{
printf("%x,",result[counter]);
counter++;
}
printf("\n");

if (iIn < 0) {
if (errno == EAGAIN) {
printf("SERIAL EAGAIN ERROR\n");
return 0;
} else {
printf("SERIAL read error %d %s\n", errno, strerror(errno));
return 0;
}
}
return 1;
}

int getbaud(int fd)
{
struct termios termAttr;
int inputSpeed = -1;
speed_t baudRate;
tcgetattr(fd, &termAttr);
/* Get the input speed.                              */
baudRate = cfgetispeed(&termAttr);
switch (baudRate) {
case B0:      inputSpeed = 0; break;
case B50:     inputSpeed = 50; break;
case B110:    inputSpeed = 110; break;
case B134:    inputSpeed = 134; break;
case B150:    inputSpeed = 150; break;
case B200:    inputSpeed = 200; break;
case B300:    inputSpeed = 300; break;
case B600:    inputSpeed = 600; break;
case B1200:   inputSpeed = 1200; break;
case B1800:   inputSpeed = 1800; break;
case B2400:   inputSpeed = 2400; break;
case B4800:   inputSpeed = 4800; break;
case B9600:   inputSpeed = 9600; break;
case B19200:  inputSpeed = 19200; break;
case B38400:  inputSpeed = 38400; break;
case B115200:  inputSpeed = 115200; break;
}
return inputSpeed;
}

int initport(int fd)
{
struct termios options;
// Get the current options for the port...
tcgetattr(fd, &options);

// Set the baud rates to 115200...
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);

// Enable the receiver and set local mode...
options.c_cflag |= (CLOCAL | CREAD);

//disable hardware flow control
options.c_cflag &= ~CRTSCTS;

//disable software flow control
options.c_iflag &= ~(IXON | IXOFF | IXANY);

//raw input
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

//raw output
options.c_oflag &= ~OPOST;

//No parity - 8N1
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;

// Set the new options for the port...
tcsetattr(fd, TCSANOW, &options);

return 1;
}

int main(void)
{
unsigned char command[7];
unsigned char sResult[7];

printf("Start open port...\n");
fd = open(DEVICE, O_RDWR);
//fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
return 1;
}
else
{
fcntl(fd, F_SETFL, 0);
}

initport(fd);
printf("baud=%d\n", getbaud(fd));

command[0]=0xC0;
command[1]=0x73;
command[2]=0x07;
command[3]=0x0A;
command[4]=0x00;
command[5]=0x00;
command[6]=0xBE;

if (!writeport(fd, command, 7))
{
printf("write failed\n");
close(fd);
return 1;
}

sleep(2);

fcntl(fd, F_SETFL, 0);    

if (!readport(fd,sResult))
{
printf("read failed\n");
close(fd);
return 1;
}

close(fd);
return 0;
}

參考網站: http://forums.devx.com/showthread.php?t=170839