Dec 30, 2013
Technology###Add mp4 videos
From the link http://octopress.org/docs/blogging/plugins/ we can easily see HTML5 Video has been suported by octopress by-default, we add the video following this format. The details, click the upper link .
###Add Youtube Links
Download the plugin from https://github.com/manojlds/octopress-plugins, copy it under the folder plugins.
\{\% youtube 3dNDUNYT1fY \%\}
Or specify its size via:
\{\% youtube 3dNDUNYT1fY 640 480 \%\}
###Add Youku Links
First download the plugin from https://gist.github.com/liuhui998/455504954d1c6134ca57, Copy it to plugins folder, add its executable priviledge.
Add following for adding the video in size of 480x320
\{\% youku XMzM3MDM0Mjg0 480 320 \%\}
###An example of Leonard Cohen’s song:
{% youku XNTc4MDQyODky 480 320 %}
A thousand kisses deep
You came to me this morning
清晨你来到我身边
And you handled me like meat.
像触摸一块肉一般触摸我
You′d have to be a man to know
你得是个男人才会明白
How good that feels, how sweet.
那感觉多么甜蜜,多么美妙
My mirror twin, my next of kin,
我的镜中人啊,我的至亲,
I′d know you in my sleep.
我在睡梦中也认得你的模样。
And who but you would take me in
除了你没人会将我收留
A thousand kisses deep?
你的爱如同一千个吻那么深
I loved you when you opened
我爱你,当你像朵百合
Like a lily to the heat.
向着炎热盛开的样子
You see, I′m just another snowman
但我却像个雪人
Standing in the rain and sleet,
伫立在雨雪之中
Who loved you with his frozen love
用他冰冻的爱
His second-hand physique,
和他身不由己的身体去爱你
With all he is, and all he was
用他现在和曾经的全部
A thousand kisses deep.
他的爱如同一千个吻那么深
I know you had to lie to me
我知道你不得不撒谎
I know you had to cheat
我知道你不得不撒下谎言
To pose all hot and high
透过哄骗的面纱
Behind The veils of sheer deceit
你努力装得无比性感和骄傲
Our perfect porn aristocrat
我们完美的肉欲之爱
So elegant and cheap
如此优雅而低俗
I’m old but I’m still into that
我老了,但我依然深深怀念
A thousand kisses deep.
当年一千个吻那么深的爱情
I'm good at love, I'm good at hate,
我,爱之深也恨之切,
It's in between I freeze.
爱恨交织于是我不知所措
Been working out, but it's too late,
我试着走出,但为时晚矣
It's been too late for years.
一切都太晚了。
But you look good, you really do,
不过你看上去不错,真的不错
They love you on the street,
走在街上依然有人为你神魂颠倒
If you were here, I'd kneel for you
如果你在我面前,我会为你跪倒,
A thousand kisses deep.
以一千个吻般深刻的爱。
The Autumn moved across your skin,
秋天掠过你的肌肤
Got something in my eye,
也给我的眼睛里带进了某些物事。
A light that doesn't need to live,
那是一道无需存在
And doesn't need to die.
也无需消失的光
A riddle in the book of love,
一个爱之书里的谜
Obscure and obsolete
晦涩而陈腐
Till witnessed here in time and blood
唯有用时间与鲜血方可证实
A thousand kisses deep.
如同一千个吻般深刻的爱意
And I’m still working with the wine
我还在借酒浇愁
Still dancing cheek to cheek
依然放荡不羁
The band is playing Auld Lang Syne
乐队还在唱着霏靡之音
But the heart will not retreat
而我的心依然不懂得退却
I ran with Diz, I sang with Ray,
我和迪吉及但丁一起混
I never had their sweep
我从未有威风之时
But once or twice they let me play
但偶尔他们也会让我露两手
A thousand kisses deep.
唱上这首《A thousand kissed deep》
I loved you when you opened
我爱你,当你像朵百合
Like a lily to the heat.
向着炎热盛开之时
You see, I′m just another snowman
看看我吧,我仍然像个雪人
Standing in the rain and sleet,
伫立在雨雪之中
Who loved you with his frozen love
用他冰冻的心脏深深爱着你
His second-hand physique,
用他冰冻的不由自主的身体爱着你
With all he is, and all he was
用他的过往、他的现在
A thousand kisses deep.
如同一千个吻般深深爱着你
But you don’t need to hear me now,
但现在你已无需再听
And every word I speak,
我说的每句话
It counts against me anyhow
也许都会让你厌恶
A thousand kisses deep.
然而我的爱意,依然如同一千个吻般那么深。
Dec 30, 2013
TechnologyThis is like
{% video http://s3.imathis.com/video/zero-to-fancy-buttons.mp4 640 320 http://s3.imathis.com/video/zero-to-fancy-buttons.png %}
Youtube:
{% youtube 3dNDUNYT1fY %}
Youku:
{% youku XMjIyNDg0NTcy 480 320 %}
Dec 30, 2013
Technology###Preparation
Mount the partition automatically, add following lines into the /etc/fstab:
/dev/sda3 /media/ntfs ntfs-3g permissions,locale=en_US.utf8 0 2
I decide to use samba to share the files, so I have to install samba
apt-get install samba
The samba server will start automatically, but we have to configure it to adapte to our situation.
Add the configuration to the samba config file:
/etc/samba/smb.conf
[raspshare]
comment = raspberry PI Share
path = /media/ntfs
valid users = Trusty
public = no
writable = yes
printable = no
create mask = 0765
Restart the samba server
/etc/init.d/samba restart
For using smbpasswd, you have to install samba-common-bin:
apt-get install samba-common-bin
Add some users to the samba sharing:
smbpasswd -a xxx
###Mount the shared partition in client
List all of the available samba shared items:
$ smbclient -L 10.0.0.230 -U%
Then we can mount it, I add following command into the .bashrc, so everytime I enter ‘mountraspsamba’ is ok
alias mountraspsamba='sudo mount -t cifs //10.0.0.230/raspshare/ -o user=xxxx,password=XXXX,workgroup=WORKGROUP /media/raspsamba'
Dec 29, 2013
Technology###连线
Arduino I2C 连线:
RaspberryPI I2C 连线:
连线图:
RPI Arduino (Uno/Duemillanove)
--------------------------------------------
GPIO 0 (SDA) <--> Pin 4 (SDA)
GPIO 1 (SCL) <--> Pin 5 (SCL)
Ground <--> Ground
###Arduino端代码
#include <Wire.h>
#define SLAVE_ADDRESS 0x04
int number = 0;
int state = 0;
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600); // start serial for output
// initialize i2c as slave
Wire.begin(SLAVE_ADDRESS);
// define callbacks for i2c communication
Wire.onReceive(receiveData);
Wire.onRequest(sendData);
Serial.println("Ready!");
}
void loop() {
delay(100);
}
// callback for received data
void receiveData(int byteCount){
while(Wire.available()) {
number = Wire.read();
Serial.print("data received: ");
Serial.println(number);
if (number == 1){
if (state == 0){
digitalWrite(13, HIGH); // set the LED on
state = 1;
}
else{
digitalWrite(13, LOW); // set the LED off
state = 0;
}
}
}
}
// callback for sending data
void sendData(){
Wire.write(number);
}
###RaspberryPI端准备
在/etc/modules中增加一行:
i2c-dev
注释掉黑名单:
$ cat /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
# blacklist spi-bcm2708
#blacklist i2c-bcm2708
安装i2c工具:
apt-get install i2c-tools
安装python库:
apt-get install python-smbus
探测i2c设备
i2cdetect -y 0
如果不是root用户,例如,如果是pi用户,则需要将当前用户增加到i2c组中:
$ sudo adduser pi i2c
###RaspberryPI端代码
import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(0)
# This is the address we setup in the Arduino Program
address = 0x04
def writeNumber(value):
bus.write_byte(address, value)
# bus.write_byte_data(address, 0, value)
return -1
def readNumber():
number = bus.read_byte(address)
# number = bus.read_byte_data(address, 1)
return number
while True:
var = input("Enter 1 - 9: ")
if not var:
continue
writeNumber(var)
print "RPI: Hi Arduino, I sent you ", var
# sleep one second
time.sleep(1)
number = readNumber()
print "Arduino: Hey RPI, I received a digit ", number
print
运行代码时要注意,0~255的数字输入进去,会在arduino i2c slave端收到对应的数据,并原封不动的被返回。超过255的数值将溢出。
Dec 29, 2013
Technology接着上一个日志来,玩一个小tricky,通过SPI总线自己想输入的字符。
主机端,添加下列头文件
#include <string.h>
这使得可以使用strcpy等函数。
重写transfer()函数
static void transfer_mine(int fd, char *buf)
{
int ret;
uint8_t tx[140];
int len = strlen(buf)+1;
memcpy(tx, buf, strlen(buf)+1);
tx[strlen(tx)] = '\n';
uint8_t rx[ARRAY_SIZE(tx)] = {0, };
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)tx,
.rx_buf = (unsigned long)rx,
//.len = ARRAY_SIZE(tx),
.len = len,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
pabort("can't send spi message");
}
在main()函数里,改写调用的方式:
char myinput[140]="Trustywill, Hi, this is Trusty";
transfer_mine(fd, myinput);
这样就可以将自定义的字符传输过去了,140是随便设置的值,可以设置为别的更大或者更小的值。
当然你也可以从命令行输入想传输的字符, 这里就不深入了。。