2014年1月22日 星期三

ubuntu acer notebook brightness not work

    If you use ubuntu with acer notebook, and you fint that you can't change brightness using hotkey. Hot to solve it?

First edit the file, "/etc/default/grub". Add "acpi_osi=Linux acpi_backlight=vendor" to GRUB_CMDLINE_LINUX_DEFAULT. So the setting should look like below.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=Linux               acpi_backlight=vendor"

After saving the file, you should type the below command. And reboot.
sudo update-grub
Now you should change brightness using hotkey.


2014年1月20日 星期一

how to compile i3 window manager (i3 wm) 4.6

1.  Install the below packages.

sudo apt-get install -y libxcb1-dev libxcb-keysyms1-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-xinerama0-dev libpango1.0-dev libxcursor-dev libxcb-keysyms1-dev libpango1.0-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libev-dev libxcb-xkb-dev libxcb-cursor-dev libxcb-xinerama0-dev libxkbcommon-x11-dev libxkbcommon-dev

sudo apt-get install -y libxcb1-dev libxcb-keysyms1-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-xinerama0-dev build-essential freeglut3-dev libfreeimage-dev libgl1-mesa-dev libopenal-dev bpango1.0-dev libsdl-ttf2.0-dev libsndfile-dev libxinerama-dev libxcursor-dev libxcb-cursor-dev


2. download i3-4.8.tar.bz2

3. uncompress i3-4.8.tar.bz2

4. cd i3-4.8

5. make

6. make isntall


Congratulations. You make it. I test the way in ubuntu 14.04 and mint 16.


If you want to compile i3-4.7, you need to compile http://cgit.freedesktop.org/xcb/util-cursor . But I don't know how to compile it.


How to compile i3status

1.  Install the below packages.

sudo apt-get install libpango1.0-dev libxcursor-dev libconfuse-dev libasound2-dev  libiw-dev


3. uncompress

4. cd to folder

5. make

6. make isntall

替 cubietruck 加上 bonding 模組

    如果你是根據 http://blog.blackwhite.tw/2014/01/cubie-truck-sd.html 這篇文章建立 lubuntu 的作業系統的話,你會發現他預設並沒有編譯 bonding 模組。因此如果我們想要使用 bonding 的話,必須自己編譯 kernel。

    編譯 kernel 是一件很麻煩的事。不過有人幫我們簡化了很多步驟了。https://github.com/davidandreoletti/cubietruck 這裡已經有人提供腳本幫我們完成 cross compile。不過你需要注意的是你要使用 Ubuntu 12.04 或是 arm-linux-gnueabihf-gcc 4.6.3 版本。不然可能會編譯失敗。我在 mint 16 (with arm-linux-gnueabihf-gcc 4.8.1 版本會編譯失敗。

    編譯完後,他會在 output 的資料夾產生很多檔案。你需要把 uImage 複製到你 sd 卡裡的 bootfs,覆蓋他。然後在複製 output/lib 裏面的內容到 sd 卡裡的 rootfs 的 lib 資料夾裡。etc 資料夾也一樣。複製完後,記得去改 sd 卡裡的 /etc/network/interface。他有寫好 bonding 的設定,記得去修改相關設定。



2014年1月13日 星期一

2014年1月12日 星期日

Ethernet And Wireless Bonding(在 linux 下合併兩張網卡,變成一張)


為什麼要把兩張網卡合併成一張呢?
理由:

  1. 當一張網卡壞掉時,還有另一張,因此不會引起斷線
  2. 網路速度提昇(因為可以走兩條路)
  3. load balance

下面的例子是如何合併筆電的有線網卡和無線網卡。

先安裝所軟體

sudo apt-get install ifenslave

首先先編輯 /etc/NetworkManager/NetworkManager.conf 這個檔案。改成像下面那樣。你可以簡單的把 managed 設成 false,或是在 unmanaged-devices 設定哪些裝置不要被 NetworkManager 管。基本上要被合併的網卡不能被 NetworkManager 控制。


[main]
plugins=ifupdown,keyfile
dns=dnsmasq
[ifupdown]
managed=false
[keyfile]
unmanaged-devices=mac:your_mac



在 /etc/network/interfaces 新增下面的設定,你需要修改無線網卡怎麼連線以及 bond0 怎麼連線,bond0 就是合併後的新界面

auto bond0
iface bond0 inet dhcp
  bond_mode 0
  bond_primary eth0
  bond_miimon 100
  bond_downdelay 200
  bond_updelay 200
  wpa-ssid ssid
  wpa-ap-scan 1
  wpa-psk password
  wpa-scan-ssid 1
  wpa-iface wlan0                                                                
  dns-nameserver 8.8.8.8                                                          
  slaves eth0 wlan0 



重新啟動網路

sudo /etc/init.d/networking restart


用下面指令檢查設定是否成功

cat /proc/net/bonding/bond0


如果你的電腦變成只能用 ip 連但是不能用網址連
如 ping 8.8.8.8 可以通,但是透過網址不行

則在編輯  /etc/resolv.conf 這個檔案
加上

nameserver 8.8.8.8
nameserver 8.8.4.4


mode 0 和6的選擇:
如果你希望能夠平衡網卡的流量,或是你的網卡無法取得速度
則用 mode 0
否則 mode 6 會是較好的選擇


注意參考連結2的 mode 0 的說明。
 "如果一个连接或者会话的数据包从不同的接口发出的话,中途再经过不同的链路,在客户端很有可能会出现数据包无序到达的问题,而无序到达的数据包需要重新要求被发送,这样网络的吞吐量就会下降"

參考資料:

  1. http://techpatterns.com/forums/about1327.html
  2. http://www.huawei.com/ecommunity/bbs/10155553.html



註:之前範例有些問題,因此今天有作更新。 

2014年1月9日 星期四

在 linux 下讓 sdk 可以正確偵測 g2


  1. 將手機連線方式改成"數據連線"
  2. 開啟 debug 模式
  3. 跑下面指令
  4. sudo ./adb kill-server
    sudo ./adb start-server
    sudo ./adb devices
    這樣 sdk 就可以正確偵測到 g2 手機了

參考連結

2014年1月6日 星期一

Arduino LCD KeyPad Shield 的測試程式碼

Arduino LCD KeyPad Shield 的測試程式碼

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
 
/*******************************************************
 
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
 
********************************************************/
 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor 
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 // For V1.1 us this threshold
 if (adc_key_in < 50)   return btnRIGHT;  
 if (adc_key_in < 250)  return btnUP; 
 if (adc_key_in < 450)  return btnDOWN; 
 if (adc_key_in < 650)  return btnLEFT; 
 if (adc_key_in < 850)  return btnSELECT;  
 
 // For V1.0 comment the other threshold and use the one below:
/*
 if (adc_key_in < 50)   return btnRIGHT;  
 if (adc_key_in < 195)  return btnUP; 
 if (adc_key_in < 380)  return btnDOWN; 
 if (adc_key_in < 555)  return btnLEFT; 
 if (adc_key_in < 790)  return btnSELECT;   
*/
 
 
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("Push the buttons"); // print a simple message
}
  
void loop()
{
 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up
 
 
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP:
     {
     lcd.print("UP    ");
     break;
     }
   case btnDOWN:
     {
     lcd.print("DOWN  ");
     break;
     }
   case btnSELECT:
     {
     lcd.print("SELECT");
     break;
     }
     case btnNONE:
     {
     lcd.print("NONE  ");
     break;
     }
 }
 
}


出處:
http://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)

2014年1月5日 星期日

cross compile python for arm

這裡是編譯 Python 3.3.3 的方法

1. 建立 config.site,檔案內容如下

ac_cv_file__dev_ptmx=no
ac_cv_file__dev_ptc=no 


2.  在 python 3.3.3 的目錄下依序輸入以下指令。cross compiler 的相關變數你改成你系統的。



CONFIG_SITE=config.site CC=arm-linux-gcc CXX=arm-linux-g++ AR=arm-linux-ar RANLIB=arm-linux-ranlib ./configure --host=arm-linux --build=x86_64-linux-gnu --prefix=/python LDFLAGS="-static -static-libgcc" CPPFLAGS="-static -march=armv4t" --disable-ipv6
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-linux-gcc -static" CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux BUILDARCH=x86_64-linux-gnu
 make install HOSTPYTHON=./hostpython BLDSHARED="arm-linux-gcc -static" CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes prefix=~/mypython

參考資料:

http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
http://bugs.python.org/msg136962

2014年1月4日 星期六

x86 qemu 使用方式

讓 qemu 指執行 kenel
sudo qemu-system-x86_64 -kernel /boot/vmlinuz-3.8.0-19-generic -m 256
這段指令執行到最後會發生 kernel panic 。因為找不到 root
sudo qemu-system-x86_64 -kernel /boot/vmlinuz-3.8.0-19-generic -initrd /boot/initrd.img-3.8.0-19-generic -append "root=/ram/" -m 256
上面這個指令複雜一些,kenel 會讀取 initrd (用來讀取其他檔案系統的玩意,細節) 。他會執行這個執行檔在 initrd 裡的 /init 這個執行檔,最後會失敗。進入 terminal 模式。你可以打 cat /init 看他做了什麼。


讓 cubie truck 從 sd 卡開機


這裡只是簡單的描述,細節請看 http://docs.cubieboard.org/zh/tutorials/ct1/installation/install_lubuntu_desktop_server_to_sd_card#make_bootable_sd_card

  1. 下載 u-boot,bootfs,rootfs
  2. 清除 sd 卡
    • sudo dd if=/dev/zero of=${card} bs=1024 seek=544 count=128
  3. 把 u-boot 寫進 sd 卡。
    • sudo dd if=u-boot-sunxi-with-spl-ct-20131102.bin of=$card bs=1024 seek=8
  4. 再做磁碟分割,bootfs(第一個磁區) 要 ext2,第二個磁區要 ext4,像這樣(sdd 會隨每個電腦環境不同而有所不同)
    1. Device Boot      Start         End      Blocks   Id  System
      /dev/sdd1            2048      133119       65536   83  Linux
      /dev/sdd2          133120    15278079     7572480   83  Linux
  5. 建立檔案系統並把 bootfs 和rootfs 寫進你剛剛新建的磁區
    1. $mkdir /tmp/sdd1 /tmp/sdd2
      $sudo mount -t ext2 ${card}1 /tmp/sdd1
      $sudo mount -t ext4 ${card}2 /tmp/sdd2
      $sudo tar -C /tmp/sdd1 -xvf bootfs-part1.tar.gz
      $sudo tar -C /tmp/sdd2 -xvf rootfs-part2.tar.gz
      $sync
      $sudo umount /tmp/sdd1
      $sudo umount /tmp/sdd2

2014年1月1日 星期三

在 qemu 底下模擬 Raspberry Pi


1. 安裝 qemu-system-arm

2. 下載 http://xecdesign.com/downloads/linux-qemu/kernel-qemu

3. 執行下面程式碼

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda 2013-09-25-wheezy-raspbian.img

重點就那個 kernel image 和 qemu 的參數,詳情請看參考連結。

參考連結:
http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/