Conky Customization

Add existing user to specified group

The problem is : why I can’t use hddtemp? This is because hddtemp need priviledge for accessing the disk related equipment.

	[Trusty@XXXyyy ~]$ whoami
	Trusty
	[Trusty@XXXyyy ~]$ groups
	root log kvm users vboxusers
	[Trusty@XXXyyy ~]$ su root
	Password: 
	[root@XXXyyy Trusty]# groups
	root bin daemon sys adm disk wheel log

But this didn’t solve the problem, I have to add prividge in /etc/sudoes,

	# visudo
	Trusty ALL = NOPASSWD: /usr/bin/hddtemp

Therefore in the configuration file of conky I need to replace the hddtemp with “sudo hddtemp”, everything will be displayed.

Now testing the Conky

After you have installed conky, the first thing for you to do is to edit its configuration file, to decide what to display on your own widget, my configuration file is listed as following:

alignment top_right
background yes
border_width 1
cpu_avg_samples 2
default_color black
default_outline_color blue
default_shade_color blue
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
use_xft yes
xftfont AR PL KaitiM GB:size=12
gap_x 5
gap_y 30
minimum_size 280 5
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no
own_window yes
own_window_class Conky
own_window_type override
##设置conky的默认背景色
##own_window_colour 573049
##很重要,只有启用argb才能透明,但是如果窗口属性如果设置为override,可能无法生效
#own_window_argb_visual yes
##设置透明的alpha值0-255,0为透明,255不透明
#own_window_argb_value 0
##own_window_argb_visual true
##own_window_argb_value 120
own_window_transparent yes
double_buffer yes
stippled_borders 0
update_interval 1
uppercase no
use_spacer none
show_graph_scale no
show_graph_range no

TEXT
#${color red}${font AR PL KaitiM GB:style=Blod:size=17}    ${time %Y.%m.%d %H:%M:%S}
#${font AR PL KaitiM GB:style=Blod:size=12}
#${font AR PL KaitiM GB:style=Blod:size=12}${scroll 16 $nodename - $sysname $kernel on $machine}
#$hr
#${font AR PL KaitiM GB:style=Blod:size=14}${color green}${exec cal}
#$hr
${font AR PL KaitiM GB:style=Blod:size=12}${color purple}Uptime:$color $uptime
${color purple}Frequency (in MHz):$color $freq
#${color purple}Frequency (in GHz):$color $freq_g
${color purple}RAM: $color$mem/$memmax - $memperc% ${membar 4}
${color purple}Swap: $color$swap/$swapmax - $swapperc% ${swapbar 4}
${color purple}CPU1: $color${cpu cpu1}% ${cpubar 4}
${color purple}CPU2: $color${cpu cpu2}% ${cpubar 4}
${color purple}CPU3: $color${cpu cpu3}% ${cpubar 4}
${color purple}CPU4: $color${cpu cpu4}% ${cpubar 4}
${color purple}Processes: $color $processes  ${color red}Running:$color $running_processes
$hr
#${color red}Temp:
${color purple}CPU1 Temp: ${color red}${exec sensors | grep 'Core 0' | awk {'print $3'}}
${color purple}CPU2 Temp: ${color red}${exec sensors | grep 'Core 1' | awk {'print $3'}}
${color purple}System Temp: ${color red}${exec sensors | grep 'temp1' | tail -1 | awk {'print $2'}}
${color purple}Hard Temp: ${color red}${exec sudo hddtemp /dev/sda -n -u=C}°C
$hr
#${color red}File systems:
${color black}${exec df -h | grep /dev/sda3 | awk {'print $3'}} / $color${fs_used /}/${fs_size /} ${fs_bar 6 /}
${exec df -h | grep /dev/sda2 | awk {'print $3'}} x $color${exec df -h | grep /dev/sda2 | awk {'print $3'}}/138GB ${fs_bar 6 /media/ubuntu}
#${exec df -h | grep /dev/sda8 | cut -c40-43} /boot $color${fs_used /boot}/${fs_size /boot} ${fs_bar 6 /boot}
$hr
#${color red}Networking:
#${color red}eth0:
#Up:$color ${upspeed eth0} ${color red} - Down:$color ${downspeed eth0}
${color red}br0:
Up:$color ${upspeed br0} ${color red} - Down:$color ${downspeed eth0}
#${color red}ppp0:
#${color red}Up:$color ${upspeed ppp0} ${color red} - Down:$color ${downspeed ppp0}
$hr
${color red}Name              PID   CPU%   MEM%
${color black} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1}
${color black} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2}
${color black} ${top name 3} ${top pid 3} ${top cpu 3} ${top mem 3}
${color purple} ${top name 4} ${top pid 4} ${top cpu 4} ${top mem 4}
${color purple} ${top name 5} ${top pid 5} ${top cpu 5} ${top mem 5}


In fact I didn’t finished the Translucent, so I use the Transparent, a little bit ugly, but it’s OK.

Add it into awesome

Simply add one line in your ~/.config/awesome/rc.lua could solve the problem:

	awful.util.spawn("conky")

Now you can enjoy your Conky.

conky.jpg

openOCD Configuration

###OpenOCD Device Scan Install and view the OpenOCD:

	$ pacman -S openocd
	[Trusty@XXXyyy debian_octopress]$ openocd -v
	Open On-Chip Debugger 0.7.0 (2013-11-02-01:53)
	Licensed under GNU GPL v2
	For bug reports, read
		http://openocd.sourceforge.net/doc/doxygen/bugs.html

Insert your openJTAG debug board, and view its connection:

	[Trusty@XXXyyy debian_octopress]$ lsusb
	Bus 001 Device 016: ID 1457:5118 First International Computer, Inc. OpenMoko Neo1973 Debug board (V2+)

From the dmesg information:

	[15767.673553] usb 1-1: new full-speed USB device number 11 using xhci_hcd
	[15767.695990] usb 1-1: Device not responding to set address.
	[15767.938262] usb 1-1: Device not responding to set address.
	[15768.140725] usb 1-1: device not accepting address 11, error -71
	[15768.421057] usb 1-1: new full-speed USB device number 13 using xhci_hcd
	[15769.015800] usbcore: registered new interface driver usbserial
	[15769.016012] usbcore: registered new interface driver usbserial_generic
	[15769.016075] usbserial: USB Serial support registered for generic
	[15769.020028] usbcore: registered new interface driver ftdi_sio
	[15769.020050] usbserial: USB Serial support registered for FTDI USB Serial Device
	[15769.020458] usb 1-1: Ignoring serial port reserved for JTAG
	[15769.020499] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected
	[15769.020544] usb 1-1: Detected FT2232C
	[15769.020548] usb 1-1: Number of endpoints 2
	[15769.020550] usb 1-1: Endpoint 1 MaxPacketSize 64
	[15769.020553] usb 1-1: Endpoint 2 MaxPacketSize 64
	[15769.020555] usb 1-1: Setting MaxPacketSize 64
	[15769.026647] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
	[15975.012193] usb 1-1: USB disconnect, device number 13
	[15975.012449] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
	[15975.012465] ftdi_sio 1-1:1.1: device disconnected
	[15975.270658] usb 1-1: new full-speed USB device number 14 using xhci_hcd
	[15975.355869] usb 1-1: Ignoring serial port reserved for JTAG
	[15975.366867] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected
	[15975.366902] usb 1-1: Detected FT2232C
	[15975.366904] usb 1-1: Number of endpoints 2
	[15975.366906] usb 1-1: Endpoint 1 MaxPacketSize 64
	[15975.366908] usb 1-1: Endpoint 2 MaxPacketSize 64
	[15975.366909] usb 1-1: Setting MaxPacketSize 64
	[15975.371933] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0
	[16608.914153] usb 1-1: USB disconnect, device number 14
	[16608.914371] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
	[16608.914402] ftdi_sio 1-1:1.1: device disconnected
	[16609.394763] usb 1-1: new full-speed USB device number 15 using xhci_hcd
	[16609.395097] usb 1-1: Device not responding to set address.
	[16609.598734] usb 1-1: Device not responding to set address.
	[16609.801899] usb 1-1: device not accepting address 15, error -71
	[16609.962045] usb 1-1: new full-speed USB device number 16 using xhci_hcd
	[16609.962371] usb 1-1: Device not responding to set address.
	[16610.250376] usb 1-1: Ignoring serial port reserved for JTAG
	[16610.261380] ftdi_sio 1-1:1.1: FTDI USB Serial Device converter detected
	[16610.261428] usb 1-1: Detected FT2232C
	[16610.261431] usb 1-1: Number of endpoints 2
	[16610.261433] usb 1-1: Endpoint 1 MaxPacketSize 64
	[16610.261435] usb 1-1: Endpoint 2 MaxPacketSize 64
	[16610.261437] usb 1-1: Setting MaxPacketSize 64
	[16610.266397] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

From the above information we could know, Now we have a new Serial port named ttyUSB0, and also a FT2232C debug port. Currently we don’t use Serial Port, FT2232 is all we want to configure. ###OpenOCD Configuration We have to make a cfg file for OpenOCD to use. There are some pre-defined configuration files for us to refer under the directory of “/usr/share/openocd/scripts/", since we know the debug board information and we know exactly the development board info, we can easily write our own OpenOCD startup scripts.
Get the interface definition via:

	[Trusty@XXXyyy interface]$ pwd
	/usr/share/openocd/scripts/interface
	[Trusty@XXXyyy interface]$ grep "1457" ./ -r
	./neodb.cfg:ft2232_vid_pid 0x1457 0x5118
	./ftdi/neodb.cfg:ftdi_vid_pid 0x1457 0x5118

So we directly copy the neodb.cfg to our openocd.cfg under our home directory. But the usb name of our OpenOCD is changed,

	ft2232_device_desc "USB<=>JTAG&RS232

The definition is taken from the output of “lsusb -v -d 1457:5118”

We also want to define the port for telnet and gdb connection

	#########daemon configuration####
	telnet_port 4444
	gdb_port 3333


The Target configuration is taken from the /usr/share/openocd/scripts/target/stm32f1x.cfg, which is the definition of the stm32f1x. Copy them directly to your own config file.

Finally your configuration file should be listed as:


#########daemon configuration####
telnet_port 4444
gdb_port 3333

########Interface Info###########
################################################
# Since our board takes the same vid_pid
# We directly use openmoko's definition.
################################################
#
# Openmoko USB JTAG/RS232 adapter
#
# http://wiki.openmoko.org/wiki/Debug_Board_v3
#
interface ft2232
ft2232_device_desc "USB<=>JTAG&RS232"
ft2232_layout jtagkey
ft2232_vid_pid 0x1457 0x5118

########Board Info###########
# Adjust Work-area size (RAM size) according to MCU in use:
#STM32F103VC --> 48KB
#STM32F103RB --> 20KB
#set WORKAREASIZE 0x5000
# STM32F103RE --> 64KB
# set WORKAREASIZE 0x10000

# reset_config parameter (see OpenOCD manual):
# none --> srst and trst of MCU not connected to JTAG device
# srst_only --> only srst of MCU connected to JTAG device
# trst_only --> only trst of MCU connected to JTAG device
# srst_and_trst --> srst and trst of MCU connected to JTAG device
# default setting: "reset_config none" will produce a single reset via SYSRESETREQ (JTAG commands) at reset pin of MCU
#reset_config none


#script for stm32f1x family

if { [info exists CHIPNAME] } {
   set _CHIPNAME $CHIPNAME
} else {
   set _CHIPNAME stm32f1x
}

if { [info exists ENDIAN] } {
   set _ENDIAN $ENDIAN
} else {
   set _ENDIAN little
}

# Work-area is a space in RAM used for flash programming
# By default use 16kB
if { [info exists WORKAREASIZE] } {
   set _WORKAREASIZE $WORKAREASIZE
} else {
   set _WORKAREASIZE 0x4000
}

# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
adapter_khz 1000

adapter_nsrst_delay 100
jtag_ntrst_delay 100

#jtag scan chain
if { [info exists CPUTAPID] } {
   set _CPUTAPID $CPUTAPID
} else {
  # See STM Document RM0008
  # Section 26.6.3
   set _CPUTAPID 0x3ba00477
}
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

if { [info exists BSTAPID] } {
   # FIXME this never gets used to override defaults...
   set _BSTAPID $BSTAPID
} else {
  # See STM Document RM0008
  # Section 29.6.2
  # Low density devices, Rev A
  set _BSTAPID1 0x06412041
  # Medium density devices, Rev A
  set _BSTAPID2 0x06410041
  # Medium density devices, Rev B and Rev Z
  set _BSTAPID3 0x16410041
  set _BSTAPID4 0x06420041
  # High density devices, Rev A
  set _BSTAPID5 0x06414041
  # Connectivity line devices, Rev A and Rev Z
  set _BSTAPID6 0x06418041
  # XL line devices, Rev A
  set _BSTAPID7 0x06430041
  # VL line devices, Rev A and Z In medium-density and high-density value line devices
  set _BSTAPID8 0x06420041
  # VL line devices, Rev A
  set _BSTAPID9 0x06428041

}
jtag newtap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 \
	-expected-id $_BSTAPID2 -expected-id $_BSTAPID3 \
	-expected-id $_BSTAPID4 -expected-id $_BSTAPID5 \
	-expected-id $_BSTAPID6 -expected-id $_BSTAPID7 \
	-expected-id $_BSTAPID8 -expected-id $_BSTAPID9

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME

$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

# flash size will be probed
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME

# if srst is not fitted use SYSRESETREQ to
# perform a soft reset
cortex_m reset_config sysresetreq


[root@XXXyyy target]# openocd -f /media/y/embedded/stm32/dev/openocd.cfg -f ./stm32f1x.cfg 

Setup an embedded development enviroment for STM32

###Download the toolchain We should download the toolchain from the ARM employee maintained website, the download address is located at: https://launchpad.net/gcc-arm-embedded, use following command:

	$ wget https://launchpad.net/gcc-arm-embedded/4.7/4.7-2013-q3-update/+download/gcc-arm-none-eabi-4_7-2013q3-20130916-linux.tar.bz2

untar the downloaded package and then add it to your system path, my solution is directly add some alias into ~/.bashrc:

	### Add Cross_Compiler for eclipse based stm32
	#export PATH="/media/y/embedded/cortex/gcc-arm-none-eabi-4_7-2013q3/bin:$PATH"
	alias setstm='export PATH="/media/y/embedded/cortex/gcc-arm-none-eabi-4_7-2013q3/bin:$PATH"'

###Eclipse Configuration We have to install zylin for flashing the stm32 board. After installation, eclipse will be rebooted.

images/eclipseinstall.jpg

###OpenOCD OpenOCD is a open-source hardware debugger.

	community/openocd 0.7.0-2
	    Debugging, in-system programming and boundary-scan testing for embedded target devices
	[root@XXXyyy capscr]# pacman -S openocd

###Template prepration Download the template from :

	$ git clone https://github.com/JorgeAparicio/bareCortexM.git

Two Tips for setting

###Disable the vim wraping There is a line in ~/.vimrc:

	autocmd FileType text setlocal textwidth=78

comment this line then everything goes OK. ###Change Awesome theme and change the titlebar width Download the 3rd party themes from https://github.com/Morley93/awesome-themes-3.5, then copy them to your own theme location, normally under the “/usr/share/awesome/themes/", Choose whatever you want, and edit the ~/.config/awesome/default.rc.lua:

beautiful.init("/usr/share/awesome/themes/wabbit/theme.lua")

Save and exit then you got the new theme.
How to change the title bar?
In /usr/share/awesome/themes/wabbit/theme.lua, edit the following lines:

--theme.font          = "MonteCarlo medium 11"
theme.font          = "MonteCarlo medium 9"

I think 9 is good for me, but change this to 11 or bigger will make old men happy.
You can change this number into a very big or very small number, then some funny things will happen :)

Using IR-remote for controlling XBMC

###Wiring The Wiring is listed as following Picture, You got your IR receiver’s pins to corresponding pins on raspberry PI. Positive to Pin1(3.3v), negative to Pin6(GND), the signal pins to Pin12(GPIO 18).

rasp1.jpg ###Check the Kernel information Log on to the raspberry PI, then input dmesg to view the startup information, we can see the lirc has been added to kernel.

	$ dmesg
	[    4.976752] systemd-udevd[822]: starting version 208
	[    7.121052] lirc_dev: IR Remote Control driver registered, major 248 
	[    7.187858] lirc_rpi: module is from the staging directory, the quality is unknown, you have been warned.
	[    7.234864] lirc_rpi lirc_rpi.0: lirc_dev: driver lirc_rpi registered at minor = 0
	[    7.234894] lirc_rpi: driver registered!
	[    8.191460] lirc_rpi: auto-detected active low receiver on GPIO pin 18
	[    8.981462] input: lircd as /devices/virtual/input/input3

Now Let’s check the GPIO status:

	OpenELEC:~ # cat /sys/kernel/debug/gpio 
	GPIOs 0-53, bcm2708_gpio:
	 gpio-16  (led0                ) out hi
	 gpio-17  (lirc_rpi ir/out     ) in  lo
	 gpio-18  (lirc_rpi ir/in      ) in  hi

If it didn’t appear, using:

	modprobe lirc_rpi gpio_in_pin=18 gpio_out_pin=1

###Getting your own remote controller’s codes Now let’s kill all of the lircd related process, then use mode2 to detect the infra-red remote input.

	OpenELEC:~ # ps -ef | grep lirc
	1016 root       0:00 eventlircd --evmap=/etc/eventlircd.d --socket=/var/run/lirc/lircd --release=_UP
	1035 root       0:00 /usr/sbin/lircd --driver=default --device=/dev/lirc0 --uinput --output=/var/run/lirc/lircd-lirc0 --pidfile=/var/run/lirc/lircd-lirc0.pid /etc/lirc/lircd.conf.rpi
	1070 root      16:02 /usr/lib/xbmc/xbmc.bin --standalone -fs --lircdev /var/run/lirc/lircd
	1146 root       0:00 grep lirc
	OpenELEC:~ # killall lirc
What is mode2?  
	Trusty@SomethingMissing:~$ apt-cache search mode2
	lirc-x - infra-red remote control support - X utilities

Then Let’s listen the infra_remote’s input.The input is quite strange:

	space 4501241
	pulse 8917
	space 4415
	pulse 577

###Catching the code using irrecord The next step is turns these message into some code.

	OpenELEC:~/.config # pwd
	/storage/.config
	OpenELEC:~/.config # ls
	aacs                 samba.conf.sample    vpn-config
	hosts.conf           sysctl.conf.sample
	remote.conf          udev.rules.d.sample

Use irrecord for recording some signals and transform them into code:

	NAME
	       irrecord - application for recording IR-codes for usage with LIRC
	
	OpenELEC:~/.config # irrecord -d /dev/lirc0 lircd.conf

The method is, first long-press some keys, the result on screen will be several dots, then the program will change to another line, this time when you press some key, it only has one dot. Keep pressing keys until the irrecord tells you successful. Then you should input make some keys meaningful to the following images, when you feel satisfied, press enter to endup the program.

LIRCMAP.png

Now your lircd.conf file is generated, let see what’s in it.

	$ cat lircd.conf
	begin remote
	
	  name  lircd.conf
	  flags RAW_CODES|CONST_LENGTH
	  eps            30
	  aeps          100
	
	  gap          106707
	
	      begin raw_codes
	
	          name KEY_UP
	             8953    4401     581     527     595     503
	              613     506     588     539     581     510

If you want to use the pre-defined files, simply go to the lirc.sourceforge.net/remotes you can find almost all of the remote control information. ###Using the infra-remote for controlling Now call irw, but irw stunned with doing nothing. This command will show you all of the input signal

	OpenELEC:~ # irw
	6a 0 KEY_RIGHT devinput
	6a 0 KEY_RIGHT_UP devinput
	69 0 KEY_LEFT devinput
	69 0 KEY_LEFT_UP devinput
	6c 0 KEY_DOWN devinput
	6c 0 KEY_DOWN_UP devinput

Now in your XBMC window, you will see you can navigate and select something using your remote control.