2014年7月28日 星期一

Eclipse 在 Windows 下可能會出現的問題

Q1:location of the android SDK has not been setup in the preferences?
http://stackoverflow.com/questions/16731126/location-of-the-android-sdk-has-not-been-set-up-in-the-preferences-in-64-bit-win


How to Update your ADT to Latest Version?

1. In Eclipse go to Help

2. Install New Software ---> Add
 

3. inside Add Repository write the Name: ADT (as you want)
 

4. and Location: https://dl-ssl.google.com/android/eclipse/
 

5. after loading some time you will get Developer Tools and NDK Plugins
 

6. check both if you want to use NDK in the future or check Developer Tool only
 click Next
 

7. Finish

Now My Problem Solved :-)
==================================================================
Q2:android SDK manager 不見?

A2:此現象可以通過在eclipse中的-window-customize perspective-command groups availability 裏勾選Android SDK and AVD Manager出來
==================================================================
Q3.no cpu/abi system image available?

A3:download Android SDK manager
restart eclipse

==================================================================
Q4:The project cannot be built until build path errors are resolved

A4:我簡單的在project裏選擇clean一下就解决了,不知算不算lucky。
 

ps.後果很嚴重,這样每個project 都要clean下才行。

之後我又在project->Properties->Android下勾選了Is Library.
看到其他人的解决方案,歸納有以下幾步:

1,看看project -- Build Automatically有沒有勾上?如果沒有,勾上以後,clean一下,重启eclipse

2,看看你的lib裏面有沒有不用的jar包,看你的.classpath文件中有沒有錯誤的路徑.

3,這是最重要的一點,有problems視圖中查看有沒有關於本項目的錯誤信息,一般都會有這样的話: The project cannot be built until build path errors are resolved 然後下面提示unbound classpath, 一般在.classpath中刪除這些path就可以了

4. 安裝Tomcat後,確保{tomcat_home}/common/lib文件夾下有jasper-runtime.jar、jsp-api.jar、servlet-api.jar、jndi.jar幾個文件。启動Eclipse,第一次启動會有一個配置過程,選擇菜單上的window/preferences,選java/classpath variables,New添加一個名为JDK_TOOLS並指向你的{jdk_home}/lib/tools.jar的環境變量。

如此以來,Eclipse運行正常了。
==================================================================
Q5:actionBarActivity cannot be resolved to a type

A5:

Android 小遊戲「終極密碼」

Download: gamble.apk

遊戲說明:
這是一個 Android App 數字小遊戲,開始從正整數 1~100間,會隨機產生未知亂數,玩家要從範圍裡面猜出該數數值,猜對數字時,會跳出一個提示視窗,說明該亂數數值及所猜的次數,並有兩個 Button 可以選擇「Restart」或「Close」遊戲。

在過程中發現的幾個重點要注意:
1. 產生亂數的方法。
2. 控制IO (包含顯示出來的訊息及玩家所輸入的資料),還要避免輸入空字串或錯的內容而出現 bug。
3. 資料型態轉換(text -> string > int)。
4. 跳出視窗的方法。


##ReadMore##

Step 1. 先編輯 activity_main.xml ,擺好進入 App 時的介面。

activity_main.xml Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/keyin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.gamble.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="110dp"
        android:text="===== Gamble Start =====\nGuess the number ( 1~100 )" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="34dp"
        android:ems="10"
        android:inputType="number" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="79dp"
        android:onClick="buttonClick1"
        android:text="確定" />

</RelativeLayout>


Step 2. 編輯 strings.xml ,設定 Step1 之介面顯示出來的文字。
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">gamble</string>
    <string name="hello_world"></string>
    <string name="action_settings">Settings</string>

</resources>



tep3. 編輯 MainActivity.java 主程式,開始撰寫遊戲運作內容。
package com.example.gamble;

import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.Random;



public class MainActivity extends ActionBarActivity {
 // Parameter
 boolean gameWin = true;
 int max, min, Ran, gameCount, guessNum;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }

 // Create a random number in range min ~ max
 public int randomCreate(int max, int min){
  Random Ran = new Random();
  return (Ran.nextInt(max)+min);
 }

 // Button_Click event
 public void buttonClick1(View view) throws InterruptedException{
  // Initialize setting
  if (gameWin == true) {
   max = 100;  // Random range (Max)
   min = 1;  // Random range (Min)
   Ran = randomCreate(max, min); // Get random number
   gameCount = 0;  // Guess count
   gameWin = false; // Game win flag
  }

  // IO setting
  TextView txtOutput = (TextView) findViewById(R.id.textView1);
  EditText txtInput = (EditText) findViewById(R.id.editText1);
  Button txtButton = (Button) findViewById(R.id.button1);

  // Alert dialog setting
  AlertDialog.Builder endGame = new AlertDialog.Builder(this);
  endGame.setTitle("You've guessed right!\n");
  endGame.setMessage("Random Num. is \""+ Ran  + "\"\nGuess count: " + gameCount);
  endGame.setPositiveButton("Restart", new DialogInterface.OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int i) {
    // Reload App
    finish();
    startActivity(getIntent());
   }
  });
  endGame.setNegativeButton("Close", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int i) {
       // Close App
       finish();
      }
     });

  if ("".equals(txtInput.getText().toString().trim())) // if not any keyin
   txtOutput.setText("Error Keyin, \nPlease keyin number " + min + " ~ " + max);
  else {
   String keyinStr = txtInput.getText().toString(); // keyinStr = Get editText1's text to string
   int keyinInt = Integer.parseInt(keyinStr);   // keyinInt = keyinStr to integer
   if((keyinInt >= min) && (keyinInt <= max)){
    gameCount += 1;  // count guess number
    // Determine whether the input is equal random or not.
    if (keyinInt == Ran){
     txtOutput.setText("");
     gameWin = true;
     endGame.show();  // Show "Restart" & "Close" button
    }
    else if (keyinInt < Ran) {
     min = keyinInt;
     txtOutput.setText("Guess wrong!\nThe number is " + min + " ~ " + max + " , guess again.");
    }
    else if (keyinInt > Ran) {
     max = keyinInt;
     txtOutput.setText("Guess wrong!\nThe number is " + min + " ~ " + max + " , guess again.");
    }
    else {
     txtOutput.setText("Error");  // Other error
    }
   }
   else
     txtOutput.setText("Keyin Error, \nPlease keyin number " + min + " ~ " + max);
  }
  txtInput.setText(null);  // clear EditText "txtInput"
 }
}

遊戲執行結果:

Raspberry Pi GPIO (二) 控制按鍵、LED

附圖為我們 控制按鍵、LED的電路圖

圖中用Pin 11(GPIO 0)控制LED / Pin 7(GPIO 7)控制按鍵開關

把電路圖接好後,就可以準備把程式寫成一個檔案,這邊我是命名為switch_led_double.py

     
  
   #switch_led_double.py
 
   import RPi.GPIO as GPIO
   import time
   GPIO.setmode(GPIO.BOARD)
  
   switch=7
   led=11
   i=0
 
   print "Setup Switch Pin 7 is a input"
   GPIO.setup(switch,GPIO.IN)
   print "Setup Switch Pin 11 is a output"
   GPIO.setup(led,GPIO.OUT)
  
   while True:
           input=GPIO.input(switch)
           if (input):
                   i+=1
                   print ("Button is on("+str(i)+")")
                   GPIO.output(led,GPIO.HIGH)
                   time.sleep(0.1)
                   GPIO.output(led,GPIO.LOW)
           time.sleep(0.05)
   GPIO.cleanup()
結果影片:
當我們按一下,或是連續按,LED都會呈現亮滅的的動作

2014年7月26日 星期六

Raspberry Pi GPIO (三) 控制伺服馬達


首先我們來了解一下伺服馬達的控制方式,伺服馬達與步進馬達雖然功能相似,但控制原理卻大大不同。

標準的伺服馬達上會有三條控制線,分別為:VCC,GND,還有訊號線。VCC 與 GND 用於提供內部直流馬達及控制線路所需的能源,電壓通常介於 4 ~ 6 V 之間,電壓大小差別在於扭力的大小,和轉動速度的快慢。

而訊號線則是用來控制馬達的轉動.,輸入的訊號為 PWM ,也就是脈衝寬度調變,伺服馬達的角度就是由 PWM 的 Duty Cycle 去控制,以我用的 S03T 2BBMG 作為範例:



下面為這顆馬達的控制規格:



這顆馬達在規格上是寫可以控制到180度,但是實際上它只能轉動170度,還有千萬不要送超過馬達控制角度的訊號給伺服馬達,這樣會使馬達受損,齒輪組損壞。

基本上我們送出的PWM必須要在 1 秒內產生 50 個波以上才能夠讓伺服馬達運作,而我使用的 Python 中可以透過以下程式去設定:
pwm_motor = GPIO.PWM(p,50)
pwm_motor.start(0)
在這當中 p 為輸出的腳位號碼,50 則是頻率(Hz),而 start(0) 則是設定一開始的Duty Cycle為 0,由於 Python 控制的是 Duty Cycle 的百分比,所以我們必須把上面表格中的頻寬轉為百分比才能使用。

由於我們是使用 50Hz 的 PWM,所以 1 個波的時間為:

1 / 50 =  0.02 = 20 ms

再來就可以計算頻寬的百分比了

+90度:( 0.8 ms / 20 ms ) * 100 = 4
+60度:( 0.9 ms / 20 ms ) * 100 = 4.5
    0度:( 1.5 ms / 20 ms ) * 100 = 7.5
-60度:( 2.1 ms / 20 ms ) * 100 = 10.5
-90度:( 2.2 ms / 20 ms ) * 100 = 11

接下來就是硬體電路的部分:

伺服馬達的 VCC 使用外接電池盒( 6 V ) 然後 GND 與 電池盒的 GND 還有 RPI 的 GND 必須接在一起達到共地,然後訊號腳的部分,我們使用可以送出PWM的第12腳作為 GPIO,如下圖所示:



實際電路:


再來是我測試用的程式,我讓伺服馬達由 +90度 => 0度 => -90度 去做循環,下面為我的程式碼:

#!/usr/bin/python
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
MotorPin=12
GPIO.setup(MotorPin,GPIO.OUT)
pwm_motor = GPIO.PWM(MotorPin, 50)
pwm_motor.start(7.5)

while True:
        for a in range(100):
                pwm_motor.ChangeDutyCycle(4)
                time.sleep(0.01)
                print a
#       pwm_motor.stop()
        for b in range(100):
                pwm_motor.ChangeDutyCycle(7.5)
                time.sleep(0.01)
                print b
#       pwm_motor.stop()
        for c in range(100):
                pwm_motor.ChangeDutyCycle(11)
                time.sleep(0.01)
                print c
#       pwm_motor.stop()
        for d in range(100):
                pwm_motor.ChangeDutyCycle(7.5)
                time.sleep(0.01)
                print d

實際影片:


2014年7月24日 星期四

Linux Icewm 隨機自動換桌布

筆者使用 Debian Linux 的 GUI 為 icewm,下面為 shell script。

此 Shell Script 要修改幾個簡單變數,就可以使用了:
1. IMG_POSTION ,在06行,為你自己的桌圖目錄位置。
2. IMG_TYPE*.jpg 要修改, 在 12 行,該部份為你自己所擁的圖片副檔名,若只有 JPG 改 *.jpg,若有多種副檔名 (例如 JPG、PNG) 就改為 *.{jpg, png}。


  • 自動更換桌面,首先先安裝有 hsetroot,桌面布圖指令
sudo apt-get update && apt-get install hsetroot

  • 接下來,寫一個可以自動換圖的 Shell Script 
vi WallpaperChange.sh


  • My code
#!/bin/bash
# 2014/04/19    Author:Kai-Lin Liao
# Auto Change Wallpaper

# Parameter
IMG_POSITION=/home/lin/images/Wallpaper

# Change Director 
cd $IMG_POSITION

# Parameter
IMG_TYPE=`find *.jpg`
#IMG_TYPE=`find *.{jpg,png}`
IMG_AMOUNT=`find $IMG_TYPE -type f | wc -l`

# Test World
#echo "Image Type: $IMG_TYPE"
#echo "Wallpaper Postion: $IMG_POSITION, File Amount: $IMG_AMOUNT"

# Build Picture List
for N in $(seq 1 $IMG_AMOUNT)
do
        GET_IMG=`find $IMG_TYPE | sort | sed -n ${N}p`
        DeskPicture[${N}]=$GET_IMG
done

# Create RANDOM
LOW=1
HIGH=$IMG_AMOUNT
COUNT=$(($LOW + $RANDOM % $HIGH))
#echo $COUNT 

# Seting Wallpaper
echo "Wallpaper Change: ${DeskPicture[$COUNT]}"
hsetroot -fill $IMG_POSITION/${DeskPicture[$COUNT]}&


  • 測試、記得加入 x 權限
chmod +x WallpaperChange.sh
./WallpaperChange.sh 2> /dev/null

Conky 系統監測工具

Conky 是 Linux 上的免費 X-Window 監測工具,可以顯示各硬體監測數據。
------

1. 安裝conky
apt-get install conky conky-all


2. 安裝系統感測軟體
apt-get install curl lm-sensors hddtemp


3. conky 執行指令
conky -dq → turn on conky
pkill conky → turn off conky


4. conky設定檔
cp /etc/conky/conky.conf ~/.conkyrc
vi ~/.conkyrc


5. 開機啟動 conky:
vim ~/.xinitrc
sleep 2 && conky -qd


ps.指令位置要下在環境啟動之前,例如我的 Linux GUI 是使用 icewm,而我的 conky 啟動指令要放在 .xinitrc 文件中 exec icewm 這個指令之前。

我的conky 設定內容如下:

#Aligned position on screen(設定conky位置) 
alignment bottom_right

background no
border_width 1
#border_margin 4

cpu_avg_samples 2

default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
double_buffer yes

use_xft yes

#字型及大小
xftfont DejaVu Sans Mono:size=12
#xftfont Bitstream Vera Sans Mono:size=16
#font Sans:size=11

#視窗座標
gap_x 20
gap_y 150

minimum_size 5 5
maximum_width 300

net_avg_samples 2
no_buffers yes

out_to_console no
out_to_stderr no

extra_newline no

own_window no
own_window_transparent no
own_window_class Conky
own_window_type desktop

stippled_borders 0

#更新頻率(秒)
update_interval 1.0
uppercase no
use_spacer no

show_graph_scale no
show_graph_range no
#stippled_borders 10

total_run_time 0
###########################################
TEXT
# Kernel
#${color lightgrey}$sysname $kernel ${color}on ${color lightgrey}$machine
# Time
${color lightgrey}Time:${color 00ff00}${time %Y/%m/%d - %R:%S}
# separator
${color grey}$stippled_hr
# File system
${color lightgrey}File systems:
${color lightgrey}root: $color${fs_used /}${color lightgrey}/$color${fs_size /}
${color lightgrey}(free: $color${fs_free /}${color lightgrey} - $color${fs_free_perc /}%${color lightgrey})
#home: $color${fs_used /home/lin}/${fs_size /home/lin}
${color 7f8ed3}${fs_bar 12 /}
# Networking-eth0
${color lightgrey}Eth0:
${color lightgrey}Down:${color} ${downspeed eth0} ${offset 40}Up:${color} ${upspeed eth0}
${color black}${downspeedgraph eth0 35,140 ff0000 0000ff} ${color black}${upspeedgraph eth0 35,140 0000ff ff0000}
#${color 888888}${downspeedgraph eth0 35,130 ff0000 0000ff}       ${color 888888}${upspeedgraph eth0 35,130 0000ff ff0000}
#${color 888888}TOTAL: ${color CCCCCC}${totaldown eth0}  ${color 888888}TOTAL: ${color CCCCCC}${totalup eth0}
# separator
${color grey}$stippled_hr
# CPU
${color lightgrey}Total CPU:${color ddaa00} ${cpu}%
${color 7f8ed3}${cpubar 12}
${color lightgrey}CPU0:         CPU1:
${color 000000}${cpugraph cpu0 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu1 35,140 000000 7f8ed3}
${color lightgrey}CPU2:         CPU3:
${color 000000}${cpugraph cpu2 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu3 35,140 000000 7f8ed3}
# RAM
${color lightgrey}RAM: ${color}$mem/$memmax - ${color ddaa00}$memperc%
${color 7f8ed3}${membar 12}
# Swap
${color lightgrey}Swap: ${color}$swap/$swapmax - ${color ddaa00}$swapperc%
${color 7f8ed3}${swapbar 12}
# separator
${color grey}$stippled_hr
# process CPU usage
${color ffccaa}CPU usage         PID   CPU%
${color ddaa00} ${top name 1}${top pid 1}${top cpu 1}
${color lightgrey} ${top name 2}${top pid 2}${top cpu 2}
${color lightgrey} ${top name 3}${top pid 3}${top cpu 3}
${color lightgrey} ${top name 4}${top pid 4}${top cpu 4}

# process RAM usage
${color ffccaa}Mem usage         PID   RAM%
${color ddaa00} ${top_mem name 1}${top_mem pid 1}${top mem 1}
${color lightgrey} ${top_mem name 2}${top_mem pid 2}${top mem 2}
${color lightgrey} ${top_mem name 3}${top_mem pid 3}${top mem 3}
${color lightgrey} ${top_mem name 4}${top_mem pid 4}${top mem 4}


第二版,新增CPU、GPU 溫度(排版修改)

但要偵測顯卡溫度前,要先安裝 Nvidia 顯卡驅動

一般 command 查看溫度的方法:
看CPU 溫度: sensors
看GPU 溫度: nvidia-settings -q gpucoretemp

善用 command 擷取,再加到 .conkyrc 內:
加入後的 conky 如下圖:

.conkyrc 設定如下:
# Conky, a system monitor, based on torsmo
#
# Any original torsmo code is licensed under the BSD license
#
# All code written since the fork of torsmo is licensed under the GPL
#
# Please see COPYING for details
#
# Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
# Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
# Possible variables to be used:
#
#      Variable         Arguments                  Description                
#  acpiacadapter                     ACPI ac adapter state.                   
#  acpifan                           ACPI fan state                           
#  acpitemp                          ACPI temperature.                        
#  adt746xcpu                        CPU temperature from therm_adt746x       
#  adt746xfan                        Fan speed from therm_adt746x             
#  battery           (num)           Remaining capasity in ACPI or APM        
#                                    battery. ACPI battery number can be      
#                                    given as argument (default is BAT0).     
#  buffers                           Amount of memory buffered                
#  cached                            Amount of memory cached                  
#  color             (color)         Change drawing color to color            
#  cpu                               CPU usage in percents                    
#  cpubar            (height)        Bar that shows CPU usage, height is      
#                                    bar's height in pixels                   
#  downspeed         net             Download speed in kilobytes              
#  downspeedf        net             Download speed in kilobytes with one     
#                                    decimal                                  
#  exec              shell command   Executes a shell command and displays    
#                                    the output in torsmo. warning: this      
#                                    takes a lot more resources than other    
#                                    variables. I'd recommend coding wanted   
#                                    behaviour in C and posting a patch :-).  
#  execi             interval, shell Same as exec but with specific interval. 
#                    command         Interval can't be less than              
#                                    update_interval in configuration.        
#  fs_bar            (height), (fs)  Bar that shows how much space is used on 
#                                    a file system. height is the height in   
#                                    pixels. fs is any file on that file      
#                                    system.                                  
#  fs_free           (fs)            Free space on a file system available    
#                                    for users.                               
#  fs_free_perc      (fs)            Free percentage of space on a file       
#                                    system available for users.              
#  fs_size           (fs)            File system size                         
#  fs_used           (fs)            File system used space                   
#  hr                (height)        Horizontal line, height is the height in 
#                                    pixels                                   
#  i2c               (dev), type, n  I2C sensor from sysfs (Linux 2.6). dev   
#                                    may be omitted if you have only one I2C  
#                                    device. type is either in (or vol)       
#                                    meaning voltage, fan meaning fan or temp 
#                                    meaning temperature. n is number of the  
#                                    sensor. See /sys/bus/i2c/devices/ on     
#                                    your local computer.                     
#  kernel                            Kernel version                           
#  loadavg           (1), (2), (3)   System load average, 1 is for past 1     
#                                    minute, 2 for past 5 minutes and 3 for   
#                                    past 15 minutes.                         
#  machine                           Machine, i686 for example                
#  mails                             Mail count in mail spool. You can use    
#                                    program like fetchmail to get mails from 
#                                    some server using your favourite         
#                                    protocol. See also new_mails.            
#  mem                               Amount of memory in use                  
#  membar            (height)        Bar that shows amount of memory in use   
#  memmax                            Total amount of memory                   
#  memperc                           Percentage of memory in use              
#  new_mails                         Unread mail count in mail spool.         
#  nodename                          Hostname                                 
#  outlinecolor      (color)         Change outline color                     
#  pre_exec          shell command   Executes a shell command one time before 
#                                    torsmo displays anything and puts output 
#                                    as text.                                 
#  processes                         Total processes (sleeping and running)   
#  running_processes                 Running processes (not sleeping),        
#                                    requires Linux 2.6                       
#  shadecolor        (color)         Change shading color                     
#  stippled_hr       (space),        Stippled (dashed) horizontal line        
#                    (height)        
#  swapbar           (height)        Bar that shows amount of swap in use     
#  swap                              Amount of swap in use                    
#  swapmax                           Total amount of swap                     
#  swapperc                          Percentage of swap in use                
#  sysname                           System name, Linux for example           
#  time              (format)        Local time, see man strftime to get more 
#                                    information about format                 
#  totaldown         net             Total download, overflows at 4 GB on     
#                                    Linux with 32-bit arch and there doesn't 
#                                    seem to be a way to know how many times  
#                                    it has already done that before torsmo   
#                                    has started.                             
#  totalup           net             Total upload, this one too, may overflow 
#  updates                           Number of updates (for debugging)        
#  upspeed           net             Upload speed in kilobytes                
#  upspeedf          net             Upload speed in kilobytes with one       
#                                    decimal                                  
#  uptime                            Uptime                                   
#  uptime_short                      Uptime in a shorter format               
#
#  seti_prog                         Seti@home current progress
#  seti_progbar      (height)        Seti@home current progress bar
#  seti_credit                       Seti@hoome total user credit
#

#Aligned position on screen(設定conky位置) 
#alignment top_right
alignment bottom_right
background no
border_width 1
#border_margin 4

cpu_avg_samples 2

default_color white
default_outline_color white
default_shade_color white
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
double_buffer yes

use_xft yes

#字型及大小
xftfont DejaVu Sans Mono:size=12
#xftfont Bitstream Vera Sans Mono:size=16
#font Sans:size=11

#視窗座標
gap_x 20
gap_y 150

minimum_size 5 5
maximum_width 300

net_avg_samples 2
no_buffers yes

out_to_console no
out_to_stderr no

extra_newline no

# 視窗背景 yes:黑底 ; no:透明
own_window yes
own_window_transparent no
own_window_class Conky
own_window_type desktop

stippled_borders 0

#更新頻率(秒)
update_interval 1.0
uppercase no
use_spacer no

show_graph_scale no
show_graph_range no
#stippled_borders 10

total_run_time 0
###########################################
TEXT
#
# Kernel
#${color lightgrey}$sysname $kernel ${color}on ${color lightgrey}$machine
#
# Time
${color lightgrey}Time:${color 00ff00}${time %Y/%m/%d - %R:%S}
#
# separator
${color grey}$stippled_hr
#
# Networking-eth0
${color lightgrey}Eth0:
${color lightgrey}Down:${color} ${downspeed eth0} ${offset 40}Up:${color} ${upspeed eth0}
${color black}${downspeedgraph eth0 35,140 ff0000 0000ff} ${color black}${upspeedgraph eth0 35,140 0000ff ff0000}
#${color 888888}${downspeedgraph eth0 35,130 ff0000 0000ff}       ${color 888888}${upspeedgraph eth0 35,130 0000ff ff0000}
#${color 888888}TOTAL: ${color CCCCCC}${totaldown eth0}  ${color 888888}TOTAL: ${color CCCCCC}${totalup eth0}
#
# separator
${color grey}$stippled_hr
#
# Total  CPU %
${color lightgrey}Total CPU:${color ddaa00} ${cpu}%
${color 7f8ed3}${cpubar 12}
#
# Tempratures 
${alignc}Temperatures
${color lightgrey}CPU: ${color ddaa00}${exec sensors atk0110-acpi-0|grep "CPU Temp"|cut -d '+' -f 2|cut -d ' ' -f 1}
${color lightgrey}GPU: ${color ddaa00}${exec nvidia-settings -q gpucoretemp -t | tail -n 1} °C
#
# separator
${color grey}$stippled_hr
#
# Per CPU %
#
# CPU 0 & CPU 1
${color lightgrey}CPU0 (${exec sensors coretemp-isa-0000|grep 0:|cut -d '+' -f 2|cut -d ' ' -f 1})              ${color lightgrey}CPU1 (${exec sensors coretemp-isa-0000|grep 1:|cut -d '+' -f 2|cut -d ' ' -f 1})
${color 000000}${cpugraph cpu0 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu1 35,140 000000 7f8ed3}
#
# CPU 2 & CPU 3
${color lightgrey}CPU2 (${exec sensors coretemp-isa-0000|grep 2:|cut -d '+' -f 2|cut -d ' ' -f 1})              ${color lightgrey}CPU3 (${exec sensors coretemp-isa-0000|grep 3:|cut -d '+' -f 2|cut -d ' ' -f 1})
${color 000000}${cpugraph cpu2 35,140 000000 7f8ed3}    ${color 000000}${cpugraph cpu3 35,140 000000 7f8ed3}
##
## CPU 4 & CPU 5
#${color lightgrey}CPU4 (${exec sensors coretemp-isa-0000|grep 4:|cut -d '+' -f 2|cut -d ' ' -f 1})             ${color lightgrey}CPU5 (${exec sensors coretemp-isa-0000|grep 5:|cut -d '+' -f 2|cut -d ' ' -f 1})
#${color 000000}${cpugraph cpu4 35,140 000000 7f8ed3}   ${color 000000}${cpugraph cpu5 35,140 000000 7f8ed3}
##
## CPU 6 & CPU 7
#${color lightgrey}CPU6 (${exec sensors coretemp-isa-0000|grep 6:|cut -d '+' -f 2|cut -d ' ' -f 1})             ${color lightgrey}CPU7 (${exec sensors coretemp-isa-0000|grep 7:|cut -d '+' -f 2|cut -d ' ' -f 1})
#${color 000000}${cpugraph cpu6 35,140 000000 7f8ed3}   ${color 000000}${cpugraph cpu7 35,140 000000 7f8ed3}
#
# File system
${color lightgrey}File systems:
${color lightgrey}root: $color${fs_used /}${color lightgrey}/$color${fs_size /}
${color lightgrey}(free: $color${fs_free /}${color lightgrey} - $color${fs_free_perc /}%${color lightgrey})
#home: $color${fs_used /home/lin}/${fs_size /home/lin}
${color 7f8ed3}${fs_bar 12 /}
#
# RAM
${color lightgrey}RAM: ${color}$mem/$memmax - ${color ddaa00}$memperc%
${color 7f8ed3}${membar 12}
#
# Swap
${color lightgrey}Swap: ${color}$swap/$swapmax - ${color ddaa00}$swapperc%
${color 7f8ed3}${swapbar 12}
#
# separator
${color grey}$stippled_hr
#
# process CPU usage
${color ffccaa}CPU usage         PID   CPU%
${color ddaa00} ${top name 1}${top pid 1}${top cpu 1}
${color lightgrey} ${top name 2}${top pid 2}${top cpu 2}
${color lightgrey} ${top name 3}${top pid 3}${top cpu 3}
${color lightgrey} ${top name 4}${top pid 4}${top cpu 4}

#
# process RAM usage
${color ffccaa}Mem usage         PID   RAM%
${color ddaa00} ${top_mem name 1}${top_mem pid 1}${top mem 1}
${color lightgrey} ${top_mem name 2}${top_mem pid 2}${top mem 2}
${color lightgrey} ${top_mem name 3}${top_mem pid 3}${top mem 3}
${color lightgrey} ${top_mem name 4}${top_mem pid 4}${top mem 4}


補充:字型顏色可以參考十六進制色碼表
http://www.wibibi.com/info.php?tid=372






Blender 畫一個高腳杯 Goblet

# Step 1:上網找或拍一張高腳杯的正視圖,例如下:

# Step 2:開啟 Blender,按"N"開啟右側選單,如下圖步驟1-3選取打開圖片。

# Step 3:按"Shift+A"新增一個 Plane。

# Step 4:編輯 Plane,按"Ctrl+Tab"選Vertex,並選取兩個點刪除掉,只留下另兩個點。


# Step 5:將線段擺放到杯口上,按"A"取消所選,再按左鍵選一個點,接下來使用"按住Ctrl+左鍵",來描繪整個杯子半個輪廓




# Step 6:取消勾選 "Background Image" 後,在最右側選單找到 Modifier (板手的圖示),並選"Add Modifier"加入"Screw"及"Subdivision Surface",參數設定如下面:

"Screw" 為螺旋工具,可以選擇 Axis 依需要的軸向來旋轉,其中Steps與Render是設定線條段數(越多段越精細,同時越吃顯卡),Steps是編輯下看到的物件段數,而Render是按 "F12" 計算出來的實際段數;一般而言,建模的原則是越少的段數來達到需求越好,比較不吃電腦資源。

"Subdivision Surface" 為細分表面,讓表面更精細、圓滑,與上面同理 View 是編輯模式下看到的,Render 是實際運算的段數量。

Step 7:同上步位置最右側選單找到 Materal 工具,新增一個材質,並調整 Transparency 參數。

最後,加入 Lamp 及 Camera 調整視角,就可以按 "F12" 來算圖了!


2014年7月22日 星期二

Setup Eclipse on Debian

本教學所使用之作業系統為 x64 Debian Linux,安裝 Eclipse 來建立 Android App 程式撰寫環境。


##ReadMore##

# Step1: Install Eclipse
sudo apt-get update && apt-get install eclipse*
# Step2: Check Java version
java -version
search "OpenJDK... (6b31-1.13.3-1~deb7u1)", This's ok!

如果沒裝 Java 請至:
Oracle 首頁 > Download > Java For Developer > Java Platform (JDK) > 選取 AcceptLicense Agreement > 下載並安裝所需版本。

# Step3: Open Eclipse to make Hello world,測試 *.Java
(1) eclipse
(2) File > New > Project > Java Project > Next
         > Project name: HelloWorld > Finish
(4) File > New > Class > Package: HelloWorld > Finish
(5) Coding:
public class HelloWorld {

        public static void main (String[] args){

                System.out.printf("Hello,World!!\n");

        }

}
(6) Click "Ctrl + F11" to Run.

# Step4: Install Android Repository
(1) Help > Install New Software > Add
(2) Name: Android
    Location: https://dl-ssl.google.com/android/eclipse/ > OK

(3) Select All > Next > Next > I accept... > Finish

(4) Restart Eclipse
(5) Android SDK install 官方載點,抓下來後,至 Window > Preferences > Android > 選對 SDK 的路徑。


(6) Check JREs location:
      Eclipse > Window > Preferences > Java > Installed JREs
要確定 JREs 有抓到對的 Java lib 路徑(Step 2 所安裝之Java JDK 的路徑)。

# Step5: Eclipse > Window > Android SDK Manager > 安裝所需版本 (下圖是以 Android 4.0 為例)

# Step6: Create Android Virtual Device
(1) Eclipse > Window > Android Virtual Device Manager
(2) Setting: "ADV Name" "Device" "Target" "Skin"... > OK
(下圖例為新增一個 Android 4.0 版)

# Stop7: Start Android Virtual Device
(1) Eclipse > Window > Android Virtual Device Manager
(2) 選要開啟的 ADV > Start > Launch > 出現手機介面
 

# Step7: 簡易測試ADV:建立一個 Android_HelloWorld 專案,打開會顯示 "null"  字串,且有一個 "Button"  按鈕,按下案鈕會將 "null" 改變為 "Hello World" 字串。

(1) File > New > Project > Android > Android Application Project         > Application Name: Android_HelloWorld > 選擇要建立的Android 版本 > 依需求設定 (本例是直接按 Next 到 Finish)
(2) 編輯: src/*.java、res/layout/main.xml、res/values/strings.xml
(3) edit main.xml
按左下角切換到Graphical Layout > 拉一個 Button >
編輯 Button 的 Properties > On Click 加入:  button_Click1  >
編輯 TextView 的 Properties > ID 加入: @+id/txtView1 > 會出Rename Resource 按下 ok。
(4) edit strings.xml
選擇 hello_world(String) > 編輯 Valus* : null
(5) coding .java
// Button Click Event
 public void button_Click (View view){
  TextView txtOutput = (TextView) findViewById(R.id.txtView1);
  txtOutput.setText("Hello, World!\n");
 }
若 View 或 TextView 出現錯誤訊息,就使用自動除錯功能,選擇 import 。
若找不到 txtView1 物件,一樣使用自動除錯功能,加入 *R.java 檔案內:
public static int txtView1;
(6) Click "Ctrl+F11" key to Run.

# Step8: Setting Editor Fonts.
eclipse > Window > Preference > General > Appearance > Colorsand and Fonts > Java > Java Editor Text Font > Edit
推薦 Fonts: DejaVu Sans Mono
其優點:中英等距、英文o與數字0有點做區分…等。

Raspberry Pi 設定國內鏡像站


RPI成功開啟後,預設的鏡像站在國外,連線速度會受到影響,
所以我們必須加入國內的鏡像站,連結網址如下:

http://forum.cse.yzu.edu.tw/Linux/raspberrypi/

這個網站架設了RPI各種系統版本的鏡像站,而我們使用的是debian的版本(raspbian)

首先編輯鏡像站的設定檔,指令如下:

sudo vim /etc/apt/sources.list

然後加入以下內容:

deb http://ftp.cse.yzu.edu.tw/Linux/raspbian/raspbian/ jessie main contrib non-free rpi

最後更新套件清單即可,指令如下:

sudo apt-get update

如果沒有出 error,那我們就可以使用國內的鏡像站去下載安裝套件了

2014年7月21日 星期一

在 Google Blogger 中嵌入程式碼

Google Code Prettify 建置說明

1. 開啟 Google Blogger -> 範本 -> 編輯 HTML -> 按 Ctrl+F 搜尋 <head>  -> 在下方加入:
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

2. 同樣位置:範本 -> 編輯 HTML -> 按 Ctrl+F 搜尋 /* Posts  -> 在/* Posts ----------------------------------------------- */ 的下方加入:
.post .codeblock {
display: block; /* fixes a strange ie margin bug */
font-family: Courier New;
font-size: 10pt;
overflow:auto;
background: #f0f0f0 url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAASwCAYAAAAt7rCDAAAABHNCSVQICAgIfAhkiAAAAQJJREFUeJzt0kEKhDAMBdA4zFmbM+W0upqFOhXrDILwsimFR5pfMrXW5jhZr7PwRlxVX8//jNHrGhExjXzdu9c5IiIz+7iqVmB7Hwp4OMa2nhhwN/PRGEMBh3Zjt6KfpzPztxW9MSAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzAMwzB8HS+J9kUTvzEDMwAAAABJRU5ErkJggg==) left top repeat-y;
border: 1px solid #ccc;
padding: 10px 10px 10px 21px;
max-height:1000px;
line-height: 1.2em;
}
3. 發文章的使用方法與上述類似:新文章 -> HTML 編輯模式加入標籤,共有三種類型:

類型一:
<pre class="codeblock">
        程式內容
</pre>
類型二:
<pre class="prettyprint">
        程式內容
</pre>
類型三:
<pre class="codeblock prettyprint">
        程式內容
</pre>

注意,當要顯示 HTML 語法時,顯示內容有標籤符號,必須要使用 HTML EncoderCoder's Toolbox 先進行轉換。

提醒,在範本中加入 script 會佔用到網路,可能會影響到 blogger 的載入速度,可以將不常用的 code 類型之 .js 檔註解掉,減少不必要的 onload 。

在 Google Blogger 中貼上表格

說明如何在 Google Blog 中,嵌入一個表格在裡頭,操作步驟如下:

  1. 打開 Google Drive 建立一個「文件」或「試算表」,編輯表格內容。
  2. 編輯完成後,選擇: 檔案 > 發佈到網路 > 開始發佈 > 複製「嵌入式程式碼



  3. 登入 Google Blog > 發表文章 > HTML 編輯模式 > 貼上嵌入式程式碼

    並在嵌入式程式碼中加入 height、width 來調整 Size,以本 Blog 為例:height="1500" width="500",可以切換「撰寫模式」調整適合自己 Blog 的 Size.
  4. 
    


Reference: Google > 文件編輯器 > 說明 > 發佈您的文件、試算表、簡報和繪圖