Termux – Custom Prompt

Termux is a terminal emulator and Linux environment for Android. I wanted to customise my prompt in the same way that I have done on my desktop/laptop machines. Ordinarily I would have a .bashrc in my home directory where I would make the changes to the prompt (PS1). However Termux doesn't recognise this.

I found a reference to configuring this: http://blog.ataboydesign.com/2015/12/01/termux-is-the-one-for-android/

Following this method the changes to PS1 are made in "/data/data/com.termux/files/usr/etc/bash.bashrc". I had been successfully using this method for a while with no ill effects. That was until today when I realised an update to Termux had overwritten the changes. Not what I wanted.

So after some searching I have found a solution that should survive future updates. In your Termux home directory save the following as ".profile". This will be run when Termux is started and make Termux look for a ".bashrc" file in the home directory.

# .profile
if [ -n "BASH_VERSION" ]; then
  # Echo msg to indicate file is run - can be removed later
  echo "Profile load.bashrc"
  # include .bashrc if it exists
  if [ -f "$HOME/.bashrc" ]; then
  . "$HOME/.bashrc"
  fi
fi

Create and edit ".bashrc" with any custom options. Exit and restart Termux and your custom configuration should be loaded.

ARM Research

ARM Logo

This month I have been spending some time putting together a simple development set-up for 32bit ARM devices. Whilst not yet fully complete I am making steady progress and have begun to document the process. This is easier said than done. I set out to do the simple task of making an LED blink to test my set-up. There is a lot more to learn than what I had originally expected. The 8bit Atmega 328P was simple by comparison.

What I have discovered is a lack of resources based around my set-up & understanding. Hence why I feel the need to document it where I can. My documentation is taking shape HERE. It is likely to evolve over time but it is better to make it available as I write it in the hope it proves useful to others.

Who Broke My Toolchain?

It has been a few weeks since I felt like sitting down and working on a few of my projects. Tonight I decided to put in a little more work on trying to get text displayed on an OLED screen (DN2015-001). Imagine my frustration when I attempted to compile my code only to be presented with errors. Now my code will generate a few errors at the best of times due to the odd typo, but even after correcting these I was still having no luck. Time to Google the error message.

This time it seems I am not at fault. The search revealed that during my upgrade to Fedora 23 I gained a new version of avr-gcc (5.1.0). This version however appears to be broken and has been for a few months. So if I want to continue I have to downgrade to version 4.x. Not something I can be bothered to do when the clock is approaching midnight. I guess that's all I'm going to get done tonight.

New Projects

This month I have started a couple of new projects. It began as one but soon split. The primary project was to make use of a 128x64 I2C OLED display. It has been sitting on the side for a few months after an impulse purchase. It soon became apparent that I needed a way to generate static images for the screen. Although there were programs out there that would convert a bitmap image into the hex code I needed, many were for Windows. So I decided to have a go at converting it myself.

So new to my GitHub repo are:
DN2015-001 – An interface for the SSD1306 OLED Display Driver
DN2015-002 – A bitmap to hex converter for use wwith DN2015-001

Both projects are under development at the moment. How much they develop will depend on how my experimentation with the OLED display goes.

Damn You ISR!

I am sat here on a Sunday evening trying to debug embedded C/C++. For the most part all has been going well and the code has been behaving as expected. I have however run into one of my least favourite problems, the interrupt service routine (ISR). I have a couple of ISR's and they are presenting an unexpected start-up condition. The flow of the main body of the code is fine. I just can't understand why I am getting the current output.

All these problems take me back to a traffic light program I wrote at University. That worked fine for most of the sequence only to be tripped up by an ISR along the way and ending up in a stuck state. Not what you want from a set of traffic lights, especially if you find yourself stuck in the queue behind the red light.
Luckily there wasn't a green light & green man situation with the pedestrians finding themselves in the role of Frogger.

Only one solution for this situation; single malt.

Make List

I have been making use of the Arduino Makefile from ed.am for some time but recently I needed more functionality from the Makefile.

I ran across a case when needed to check the number of instructions/clock cycles that my C/C++ code was generating. To do this I needed to have a look at the assembly listing that was created. Reading just the assembly is tricky so adding in the C/C++ that creates it makes following it a little easier.

The instructions contained here detail the commands required to generate the debugging information and the flags for avr-objdump which allow the C++/ASM listing to be generated. Typing in all these commands takes time, hence why I am using a Makefile in the first place. What I needed was to add them to the existing ed.am Makefile.

It turns out that the easiest way to do this is not to modify the original Makefile. Instead I created a blank Makefile for my project and include the ed.am Makefile. Having done this I can overload and add to its contents.

This is what I came up with, using “make list” will generate a program listing interspersed with the source code.

# Include Arduino Makefile
# ========================
include ~/bin/arduino.mk
# Arduino Makefile downloaded from:
# http://ed.am/dev/make/arduino-mk

# Override some of the included Makefile settings
# ===============================================

# Add '-g' to compiler flag to embed debug info (doesn't end up in .hex)
CPPFLAGS += -g

# Locate avr-objdump on system
OBJDUMP := $(call findsoftware,avr-objdump)

# Create a listing of asm and C source code
list: $(TARGET).elf
	@echo "Generating Listing"
	$(OBJDUMP) -h -S $(TARGET).elf > $(TARGET).lst

# Override clean target to remove additonal files
clean:
	rm -f $(OBJECTS)
	rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
	rm -rf .lib .dep
	rm -f $(TARGET).map $(TARGET).lst

Kivy

This week whilst thinking about how to represent an idea as a GUI application I ran into the limits of GTK3. I had a look around at matplotlib and pygame as possible work arounds but neither suited what I had in mind. It was then that I discovered Kivy.

Kivy - Open source Python library for rapid development of applications
that make use of innovative user interfaces, such as multi-touch apps.

Having had a look at some of the demo interfaces that have been created it looks like a really powerful tool. The only limitation appears to be your imagination. In addition the multi-touch aspect is appealing in the longer term as touch interfaces become more prevalent. Once I can get it fully installed/working on Fedora I will be experimenting with it a little.

Tmux – Solving The Problem Of Window Names

I was lucky enough to get a book on using tmux for Christmas. Following through the examples I noticed that I was not getting the expected behaviour when attempting to set window names.

Commandline

1
$ tmux new-window -n console

What this should do is create a new tmux window and within it a window called "console". What I was getting was a tmux window containing a window named after my command prompt e.g. 'bob@computer ~'. This was bothering me so I set about researching the problem, unluckily for me its not one that is that common. By chance I located a post linking to a RedHat bug report https://bugzilla.redhat.com/show_bug.cgi?id=969429. The report outlines a problem regarding a change in terminal escape codes and highlighted an identical problem with screen as I am having with tmux. I checked the escape codes in my .bashrc file, nothing wrong there. Next stop was /etc/bashrc.

/etc/bashrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "\033k%s@%s:%s\033\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
      ;;
    esac
  fi

/etc/bashrc contained the above code section. It comprises two different sections for different terminals, each has its own prompt with different escape codes. The but report highlighted that the problem lay with the 033k escape code where as 033]0 worked. I should only be using the problematic escape code if I am using a screen terminal. So which am I using?

Commandprompt

1
$ echo $TERM

The result from running the above command in my gnome-terminal was "xterm-256color". This was expected and what I assumed I was using. Running it from inside a tmux session I got "screen-256color". Tmux using a screen terminal is pointing back to the problematic escape code. Time to go back to the .tmux.conf and check my settings.

.tmux.conf

1
2
# Use 256 term colours
set -g default-terminal "screen-256color"

There is my problem line, I have set it to use the screen terminal, oops.

.tmux.conf - Correct

1
2
# Use 256 term colours
set -g default-terminal "xterm-256color"

By using the xterm-256color terminal I correct the problem with the escape code. Rerunning my initial tmux command tmux opens with a window named 'console'. Problem solved.

Aims for 2014

Time for a look back at what I intended to do last year.

  • Read an ebook on my Kindle Paper-white. - I have managed to read several and it's in regular use.
  • Contribute to some open source projects. - Failed
  • Continue to develop my wireless sensor system. - Mostly failed, a little progress made but not much.
  • Buy a new soldering iron/station. - I have an ERSA Icon Nano
  • Decorate and carpet my lounge. - Success - It now looks lived in.Still needs curtains.
  • Document more of my projects on this website. - Mostly failed, a few notes were uploaded but not much else.
  • Use my Raspberry Pi for something interesting. - Barely looked at it.
  • Clear clutter out of my garage. - Cleared once then got full again.
  • Finish networking between lounge and bedroom. - Completed as part of decorating.
  • Write an android application for my tablet or phone. - I wrote a calculator script for use at work but it's in html rather than an app.

So 2013 was mixed, some things achieved some not.
Time to see if I can complete some of last years goals in 2014.

  • Contribute to some open source projects.
  • Put more time into electronics projects (Raspberry Pi/Wireless Sensor System).
  • Get curtains for lounge.
  • Clear out Garage (again).
  • Write an android application for my tablet/phone
  • Pay off student loan.
  • Carpet master bedroom.
  • Build a Gaming PC and/or Steam Box
  • Repave Back Yard
  • Use a Linux desktop environment other than Gnome 3 for at least a month

Another to do list, but as before it will be a good year if I can cross a few of them off.

Git Hub – Codecolorer

I have been using Git for version control on my own machine for a little while now. I've barely scratched the surface of what it can do but it is still useful to me. I have had an account on Git Hub for a while and have been meaning to either start or contribute to a project. I noticed that one of the syntax highlighting projects I use had not been updated in a while. So I forked the Codecolorer code and applied some updates. My intent is that these changes get pulled back into the main project. In the mean time my version of the codecolorer wordpress plugin is available here or by clicking on the link in the Git Hub widget (under Octocat).