- 將手機連線方式改成"數據連線"
- 開啟 debug 模式
- 跑下面指令 sudo ./adb kill-server
sudo ./adb start-server
sudo ./adb devices
- 這樣 sdk 就可以正確偵測到 g2 手機了
參考連結
//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;
}
}
}
ac_cv_file__dev_ptmx=no
ac_cv_file__dev_ptc=no
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
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 看他做了什麼。
Device Boot Start End Blocks Id System /dev/sdd1 2048 133119 65536 83 Linux /dev/sdd2 133120 15278079 7572480 83 Linux
$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
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
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig編譯完後的檔案會放在 _install。把他做成 img
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
$ cd _install
$ find . | cpio -o --format=newc > ../rootfs.img
qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img -append "root=/dev/ram rdinit=/bin/sh"
$ cd _install
$ mkdir proc sys dev etc etc/init.d
$ cd ..
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
chmod +x _install/etc/init.d/rcS最後的驗收
qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append "root=/dev/ram rdinit=/sbin/init"參考資料
find . | cpio -H newc -o | gzip -9 > /boot/initrd.img
find . | cpio -H newc -o > rootfs
gunzip -c /boot/initrd.img-2.6.24-19-generic | cpio -i
mount -t ext2 -o loop initrd.img temp/
make ARCH=arm versatile_defconfigmake ARCH=arm menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- all
#include <stdio.h>
intmain() {printf("Hello World!\n");while(1);}
arm-linux-gnueabi-gcc -static test.c -o test製作 rootfs
echo test | cpio -o --format=newc > rootfs執行第一支程式
qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs -append "root=/dev/ram rdinit=/test" -no-reboot啟動核心後,核心會執行你的程式。
qemu-arm -L /usr/arm-linux-gnueabi/ a.out
class MyStr1(str):
def __init__(self, a='', b=''):
super(MyStr1, self).__init__()
self.a = a
self.b = b
a = MyStr1("1")
a = MyStr1("1", "2")
Traceback (most recent call last): File "", line 1, in TypeError: str() takes at most 1 argument (2 given)
def __call__(cls, *args, **kwargs):
obj = cls.__new__(cls, *args, **kwargs)
obj.__init__(*args, **kwargs)
return obj
class ClsA(object):
def __init__(self, *args, **kwargs):
print 'init: ', args, kwargs
def __new__(cls, *args, **kwargs):
print 'new: ', args, kwargs
return super(ClsA, cls).__new__(cls, *args, **kwargs)
a = ClsA('a', 'b', 2)
class CustomMetaCls(type):
def __call__(cls, *args, **kwargs):
if len(args):
content = args[0]
else:
content = ''
obj = cls.__new__(cls, content)
obj.__init__(*args, **kwargs)
return obj
class MyStr(str):
__metaclass__ = CustomMetaCls
def __init__(self, a='', b=''):
super(MyStr, self).__init__(a)
self.a = a
self.b = b
b = MyStr('a', 'b')
class MyStr1(str):
def __init__(self, a='', b=''):
super(MyStr1, self).__init__()
self.a = a
self.b = b
def __new__(cls, *args, **kwargs):
print args, kwargs
if len(args):
content = args[0]
else:
content = ''
return str.__new__(cls, content)
![]() |
| 虛線表示那兩個是同一個。箭頭表示程序間的父子關係。有箭頭的表示子程序。 |
