New IT forum
26 June 2022, 04:55:45 pm *
Welcome, %1$s. Please login or register.

: MiraBox now in stock.
 
Pages: [1]

Author Topic: Linux Twiddly Bits  (Read 18210 times)

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Linux Twiddly Bits
« on: 07 October 2011, 01:39:44 pm »

Convert a file of u-boot environment variables to setenv variables.

You have screendumped\cut'n'pasted your u-boot environment variables and
saved them in a file. Now you want the commands to paste back at the u-boot prompt.

Code: [Select]
[[email protected] ~]$ ./env-setenv.sh dreamplug-envars.txt
setenv bootcmd 'setenv ethact egiga0; ${x_bootcmd_ethernet}; setenv ethact egiga1; ${x_bootcmd_ethernet}; ${x_bootcmd_usb}; ${x_bootcmd_kernel}; setenv bootargs ${x_bootargs} ${x_bootargs_root}; bootm 0x6400000;';
setenv bootdelay '3';
setenv baudrate '115200';
setenv x_bootcmd_ethernet 'ping 192.168.2.1';
setenv x_bootcmd_usb 'usb start';
setenv x_bootcmd_kernel 'fatload usb 0 0x6400000 uImage';
setenv x_bootargs 'console=ttyS0,115200';
setenv x_bootargs_root 'root=/dev/sda2 rootdelay=10';
setenv ethact 'egiga0';
setenv ethaddr 'F0:AD:4E:00:7E:xx';
setenv eth1addr 'F0:AD:4E:00:7E:xx';
setenv stdin 'serial';
setenv stdout 'serial';
setenv stderr 'serial';
[[email protected] ~]$

Contents of 'env-setenv.sh'
Code: [Select]
#!/bin/bash
sed -e "s/\(^.[^=]*\)=\(.*$\)/setenv \1 '\2';/1" [email protected]

TWFM YMMV
« Last Edit: 07 October 2011, 02:11:27 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #1 on: 08 October 2011, 07:23:20 am »

Mount a dd'd disk image file

I threw up together this embarrassment whilst burning the midnight oil.
Somebody please write a better version so I can delete my shame and this post.

Code: [Select]
#!/bin/bash
# vim:ai:sw=2
N=0
if [ -n "$1" ] ; then
  if [ -f "$1" ] ; then
    fdisk -l "$1" | grep "^${1##*/}" | awk '{print $2}' | \
    while read S ; do
      N=$[$N+1]
      sudo mkdir -p /mnt/tmp$N
      sudo mount -o loop,owner,offset=$[512*$S] "$1" /mnt/tmp$N
      echo "/mnt/tmp$N"
      ls /mnt/tmp$N
    done
  else
    echo "Can't find \"$1\""
  fi
else
  for T in /mnt/tmp[0-9]* ; do
    if grep -q $T /proc/mounts >> /dev/null 2>&1 ; then
      echo "unmounting \"$T\""
      sudo umount $T
    fi
  done
fi

Quote
[[email protected] ~]$ ./img-mount.sh Dreamplug-Ubuntu.img
[sudo] password for bldrbob:
/mnt/tmp1
uImage
/mnt/tmp2
bin   dev  home  lost+found  mnt  proc  sbin     srv  tmp  var
boot  etc  lib   media       opt  root  selinux  sys  usr
[[email protected] ~]$
[[email protected] ~]$ ./img-mount.sh
unmounting "/mnt/tmp1"
unmounting "/mnt/tmp2"
[[email protected] ~]$


EDIT: As can be seen the script requires loopback support, this is commonly available by default in most distributions, but may not be included in the kernel running on your plug.
« Last Edit: 12 December 2011, 08:32:37 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #2 on: 14 October 2011, 03:13:47 pm »

'chroot' into an arm root filesystem (i.e. a mounted disk image file).

Quote
[[email protected] ~]$ ./img-mount.sh Dreamplug-Ubuntu.img
[sudo] password for bldrbob:
/mnt/tmp1
uImage
/mnt/tmp2
bin   dev  home  lost+found  mnt  proc  sbin     srv  tmp  var
boot  etc  lib   media       opt  root  selinux  sys  usr
[[email protected] ~]$

[[email protected] ~]$sudo ./chroot-arm-rootfs.sh /mnt/tmp2
[[email protected]:/# ls /root
init_setup.sh
[[email protected]:/# exit
[[email protected] ~]$

This script assumes:
that 'qemu-arm-static' has been downloaded\installed to /usr/bin.
the kernel has support for 'binfmt_misc' compiled in (most do).
that you have the gcc compiler installed.

chroot-arm-rootfs.sh
Code: [Select]
#!/bin/bash
# vim:ai:sw=2

[ $(id -u) -eq 0 ] || {
  echo "You must be root to chroot"
  exit -1
}

[ $# -ne 2 ] || {
  echo "Usage: ${0##*/} </directory/path/of/rootfs>"
  exit -1
}

ROOTFS="$1"

[ -d ${ROOTFS}/tmp ] || {
  echo "This does not appear to be a valid rootfs"
  exit -1
}

[ -x ${ROOTFS}/tmp/qemu-arm-static ] || \
  cp -a /usr/bin/qemu-arm-static ${ROOTFS}/tmp

[ -x ${ROOTFS}/tmp/qemu-wrapper ] || {
  cat >/tmp/qemu-wrapper.c << EOF
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv, char **envp) {
        char *newargv[argc + 3];

        newargv[0] = argv[0];    
        newargv[1] = "-cpu";
        newargv[2] = "arm926";
  
        memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc - 1));    
        newargv[argc + 2] = NULL;
        return execve("/tmp/qemu-arm-static", newargv, envp);
}
EOF
  gcc -static /tmp/qemu-wrapper.c -o ${ROOTFS}/tmp/qemu-wrapper
}

[ -d /proc/sys/fs/binfmt_misc ] || \
  modprobe binfmt_misc

[ -f /proc/sys/fs/binfmt_misc/register ] || \
  mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc

[ -f /proc/sys/fs/binfmt_misc/arm ] &&
  echo -1 >> /proc/sys/fs/binfmt_misc/arm

NAME="arm"
TYPE="M"
OFFSET=""
MAGIC="\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00"
MASK="\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff"
INTERPRETER="/tmp/qemu-wrapper"
FLAGS=""
echo ":${NAME}:${TYPE}:${OFFSET}:${MAGIC}:${MASK}:${INTERPRETER}:${FLAGS}" >> /proc/sys/fs/binfmt_misc/register
chroot ${ROOTFS} /bin/bash -l
« Last Edit: 16 October 2011, 09:04:29 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #3 on: 31 October 2011, 07:51:42 pm »

'dd' or 'tar', that old chestnut!

If you don't want to use 'dd' to write your SDHC Cards, then make your own gzip'ped tar file from a New IT image...

Code: [Select]
[[email protected] ~] ls
NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.img.gz
[[email protected] ~] gzip -dc NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.img.gz > NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.img
[[email protected] ~] mount-img.sh NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.img
[sudo] password for bldrbob:
/mnt/tmp1
uImage
/mnt/tmp2
bin   dev  home  lost+found  mnt  proc  sbin     srv  tmp  var
boot  etc  lib   media       opt  root  selinux  sys  usr
[[email protected] ~] cp /mnt/tmp1/uImage NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.uImage
[[email protected] ~] sudo tar -C /mnt/tmp2 -czf NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.tgz .
[[email protected] ~] mount-img.sh
unmounting "/mnt/tmp1"
unmounting "/mnt/tmp2"
[[email protected] ~] rm -f NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.img
[[email protected] ~] ls NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.*
NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.img.gz
NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.tgz
NewIT-GuiPlug-v2.7-4Gb-29oct11-Dreamplug.uImage

NB see earlier in this thread for 'mount-img.sh'
« Last Edit: 02 November 2011, 10:54:29 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #4 on: 09 November 2011, 06:28:55 pm »

Make a 4GB image file for use with 'mount-img.sh', which you can then un-tar (or whatever) onto.

Quote
[[email protected] ~]$ ./make-img.sh
Creating blank image...done
Creating partitions...done
[sudo] password for bldrbob:
Creating DOS filesystem
Creating ext4 filesystem
Tidying up..done
[[email protected] ~]$ls -l DreamPlug.img
-rw-rw-r--. 1 bldrbob bldrbob 4102029312 Nov  9 18:17 DreamPlug.img

Code: [Select]
#!/bin/bash
if [ -e DreamPlug.img ] ; then
  echo "DreamPlug.img already exists, quitting!"
  exit -1
fi
echo -en "Creating blank image..."
# Flash should be filled with 0xFF in preference to 0x00
# Dont have a source of 0xFF's, be imaginative
# 1,048,576 Bytes
dd if=/dev/zero count=2048 | tr -t '\000' '\377' | dd of=DreamPlug.img >/dev/null 2>&1
# 4,102,029,312 Bytes
dd if=DreamPlug.img of=DreamPlug.img bs=1048576 seek=1048576 conv=notrunc oflag=append count=3911 >/dev/null 2>&1
echo "done"
echo -en "Creating partitions..."
fdisk DreamPlug.img >/dev/null 2>&1 << EOF
n
p
1
2048
+16M
t
1
6
n
p
2
34816
8011775
w
EOF
echo "done"
PART1=$(sudo losetup -f)
sudo losetup -o $[2048*512] ${PART1} DreamPlug.img
PART2=$(sudo losetup -f)
sudo losetup -o $[34816*512] ${PART2} DreamPlug.img
echo "Creating DOS filesystem"
sudo mkdosfs -n DreamPlug ${PART1} 16384 >/dev/null 2>&1
echo "Creating ext4 filesystem"
sudo mke2fs -L DreamPlug -t ext4 ${PART2} >/dev/null 2>&1
echo -en "Tidying up.."
sudo losetup -d ${PART2} ${PART1}
echo -e "done"
exit 0

NB THERE ARE NO SAFETY CHECKS - if you trash your system with this, it's your fault!
« Last Edit: 10 November 2011, 12:52:43 am by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #5 on: 24 February 2012, 03:36:06 pm »

A number of the NewIT SD image files have been specifically created allowing room for flash wear'n'tear.
This little script will 'short copy' prune the surplus space off the end of the uncompressed SD image file, which will then enable the copy to be written to an undersized (already worn) SD card.

prune-img.sh
Code: [Select]
#!/bin/bash
# vim:ai:sw=2
set -e
if [ ! -r "$1" ] ; then
  echo "Cannot read \"$1\""
  echo -e "Usage:\n${0##*/} <diskfile.img>"
  exit -1
fi
T=0
while read P S E A G ; do
  if [ "$S" == "*" ] ; then
    S=$E
    E=$A
  fi
  if [ $E -gt $T ] ; then
    T=$E
  fi
done < <(fdisk -l "$1" | grep "^$1")
T=$(($T+1))
dd if=$1 of=$1-pruned bs=512 count=$T

If you are low on workspace, changing the last line to that below will truncate the original image rather than 'short copy' it.
Code: [Select]
dd if=/dev/null of=$1 bs=512 seek=$T

No Guarantees, No Safety Checks, No Responsibility Taken, Your Risk!
« Last Edit: 24 February 2012, 05:53:02 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #6 on: 24 February 2012, 03:47:30 pm »

Got fed up typing the same stuff over'n'over again when looking at an SD image file in gparted.
This script 'sets up'\'tears down' an uncompressed SD image file in a way that gparted accepts.
THIS SCRIPT NECESSARILY RUNS AS ROOT AND CREATES & DELETES, YOU HAVE BEEN WARNED!!!

gparted-img.sh
Code: [Select]
#!/bin/bash
# vim:ai:sw=2
set -e
if [ "$(id -u)" -ne 0 ] ; then
  sudo su -c "$0 [email protected]"
fi
if [ ! -r "$1" ] ; then
  echo "Cannot read \"$1\""
  echo -e "Usage:\n${0##*/} <diskfile.img>"
  exit -1
fi
L[0]="$(losetup -f)"
losetup ${L[0]} "$1"
I=1
while read P[${I}] S E A G ; do
  if [ "$S" == "*" ] ; then
    S=$E
    E=$A
  fi
  L[${I}]=$(losetup -f)
  ln -s "${L[${I}]}" "${P[${I}]}"
  losetup "${L[${I}]}" -o $(($S*512)) "$1"
  I=$(($I+1))
done < <(fdisk -l ${L[0]} | grep "^${L[0]}")
gparted ${L[0]}
while [ ${I} -gt 0 ] ; do
  I=$(($I-1))
  losetup -d "${L[${I}]}"
  [ $I -ne 0 ] && rm -f "${P[${I}]}"
done

DISCLAIMER: everything, as always.
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #7 on: 20 December 2012, 09:13:49 pm »

Identify your SoC firmware version

Run this on a serial connection to your plug during it's boot to throw the SoC into debug mode.
When successful it will print the prompt (containing the firmware version) and quit.

Change '/dev/ttyUSB0' to whatever is appropriate for your setup.

kwuartdebug.sh
Code: [Select]
#!/bin/bash
# vim:ai:sw=2
for((i=0;i<500;i++)); do
  echo -e "\xDD\x11\x22\x33\x44\x55\x66\x77" >> /dev/ttyUSB0
done
timeout 1s cat /dev/ttyUSB0
exit

This script has been useful to me in practising my timing in readiness for real work of transferring a u-boot image for flashing.
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #8 on: 17 January 2013, 11:28:43 pm »

RasPi Overclock Aid

Overclocking a Rasberry Pi is not just a simple matter of incrementing the Core frequency, as a small change can cause a large jump in the related GPU frequency.
Repeatedly (trying) to do the calculations in my head confusticated me to the point that I decided to let my workstation do the work for me.
For a given Core Frequency, the script calculates the valid GPU frequencies (to zero decimal places), or calculates what will actually be used if the values are passed in.

Quote
[[email protected] raspi]$ ./raspi-core-gpu.sh
Enter core_freq:
core_freq= 200 (pll_freq= 2400) gpu_freq[]= 600, 400, 300, 240, 200, 171
core_freq= 225 (pll_freq= 2250) gpu_freq[]= 562, 375, 281, 225, 187, 160
core_freq= 250 (pll_freq= 2000) gpu_freq[]= 500, 333, 250, 200, 166, 142
core_freq= 275 (pll_freq= 2200) gpu_freq[]= 550, 366, 275, 220, 183, 157
core_freq= 300 (pll_freq= 2400) gpu_freq[]= 600, 400, 300, 240, 200, 171
core_freq= 325 (pll_freq= 1950) gpu_freq[]= 487, 325, 243, 195, 162, 139
core_freq= 350 (pll_freq= 2100) gpu_freq[]= 525, 350, 262, 210, 175, 150
core_freq= 375 (pll_freq= 2250) gpu_freq[]= 562, 375, 281, 225, 187, 160
core_freq= 400 (pll_freq= 2400) gpu_freq[]= 600, 400, 300, 240, 200, 171
core_freq= 425 (pll_freq= 1700) gpu_freq[]= 425, 283, 212, 170, 141, 121
core_freq= 450 (pll_freq= 1800) gpu_freq[]= 450, 300, 225, 180, 150, 128
core_freq= 475 (pll_freq= 1900) gpu_freq[]= 475, 316, 237, 190, 158, 135
core_freq= 500 (pll_freq= 2000) gpu_freq[]= 500, 333, 250, 200, 166, 142
core_freq= 525 (pll_freq= 2100) gpu_freq[]= 525, 350, 262, 210, 175, 150
core_freq= 550 (pll_freq= 2200) gpu_freq[]= 550, 366, 275, 220, 183, 157
core_freq= 575 (pll_freq= 2300) gpu_freq[]= 575, 383, 287, 230, 191, 164
core_freq= 600 (pll_freq= 2400) gpu_freq[]= 600, 400, 300, 240, 200, 171
[[email protected] raspi]$

Quote
[[email protected] raspi]$ ./raspi-core-gpu.sh 700 250
core_freq= 700 (pll_freq= 1400) gpu_freq= 280
[[email protected] raspi]$

raspi-core-gpu.sh
Code: [Select]
#!/bin/bash
# vim:ai:sw=2

# From http://elinux.org/RPi_config.txt
# pll_freq = floor(2400 / (2 * core_freq)) * (2 * core_freq)
# gpu_freq = pll_freq / [even number]
# The effective gpu_freq is automatically rounded to nearest even integer,
# so asking for core_freq=500 and gpu_freq=300 will result in
# divisor of 2000/300 = 6.666 => 6 and so 333.33MHz.

# worked example with core_freq=500
# pll_freq = floor(2400 / (2 * 500)) * (2 * 500)
# pll_freq = floor(2400 / 1000) * 1000
# pll_freq = floor(2.4) * 1000
# pll_freq = 2 * 1000
# pll_freq = 2000

# Possible values for gpu_freq (even divisors)
# gpu_freq = 2000/4, 2000/6, 2000/8, 2000/10
# gpu_freq =  500,    333.3,  250,    200

# bash uses integer math, thus floor() occurs natively, an unfortunate
# side-effect is gpu_freq will loose its decimal precision resulting
# in a potential overclock error of 0.999(reoccurring) Hz.

if [ $# -eq 0 ] ; then
  echo -n "Enter core_freq: "
  read CORE_FREQ
  if [ -n "$CORE_FREQ" ] ; then
    echo -n "Enter target gpu_freq: "
    read GPU_FREQ
  fi
else
  [ $# -ge 1 ] && CORE_FREQ=$1
  [ $# -ge 2 ] && GPU_FREQ=$2
  [ $# -ge 3 ] && CORE_FREQ=
fi

if [ -z "$CORE_FREQ" ] && [ -z "$GPU_FREQ" ] ; then
  for CORE_FREQ in $(seq 200 25 600) ; do
    PLL_FREQ=$[(2400/(2*$CORE_FREQ))*(2*$CORE_FREQ)]
    echo -n "core_freq= $CORE_FREQ (pll_freq= $PLL_FREQ) gpu_freq[]="
    for DIVISOR in $(seq 4 2 14) ; do
      GPU_FREQ=$[$PLL_FREQ/$DIVISOR]
      echo -n " $GPU_FREQ,"
    done
    echo -e "\b "
  done
elif [ -n "$CORE_FREQ" ] && [ -z "$GPU_FREQ" ] ; then
  PLL_FREQ=$[(2400/(2*$CORE_FREQ))*(2*$CORE_FREQ)]
  echo -n "core_freq= $CORE_FREQ (pll_freq= $PLL_FREQ) gpu_freq[]="
  for DIVISOR in $(seq 4 2 14) ; do
    GPU_FREQ=$[$PLL_FREQ/$DIVISOR]
    echo -n " $GPU_FREQ,"
  done
  echo -e "\b "
elif [ -n "$CORE_FREQ" ] && [ -n "$GPU_FREQ" ] ; then
  PLL_FREQ=$[(2400/(2*$CORE_FREQ))*(2*$CORE_FREQ)]
  DIVISOR=$[$PLL_FREQ/$GPU_FREQ]
  GPU_FREQ=$[$PLL_FREQ/$DIVISOR]
  echo "core_freq= $CORE_FREQ (pll_freq= $PLL_FREQ) gpu_freq= $GPU_FREQ"
else
  echo -e "$0: Argument Error!\nUsage:\n\t${0##*/} [CORE_FREQ [GPU_FREQ]]"
  exit -1
fi
exit 0
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #9 on: 02 February 2013, 09:19:21 pm »

HDMI\DisplayLink and X on the RasPi

These may be useful as a starting point for anyone wishing to run either combination or both simultaneously.
The 'InputClass' Section of xorg.conf may need adjusting to the DisplayLink monitor you use (using the relevant information from /var/log/Xorg.0.log, and 'evtest' to calibrate).
 
/etc/X11/xorg.conf
Code: [Select]
Section "ServerFlags"
    Option "DontZap" "no"
EndSection

Section "ServerLayout"
    Identifier     "HDMI"
    Screen         0 "HDMIScreen" 0 0
EndSection

Section "ServerLayout"
    Identifier     "DisplayLink"
    Screen         0 "MimoScreen" 0 0
EndSection

Section "ServerLayout"
    Identifier     "HDMIDL"
    Screen         0 "HDMIScreen" 0 0
    Screen         1 "MimoScreen" Above "HDMIScreen"
EndSection

Section "ServerLayout"
    Identifier     "XINERAMA"
    Screen         0 "HDMIScreen" 0 0
    Screen         1 "MimoScreen" Above "HDMIScreen"
    Option "Xinerama"
EndSection

Section     "Screen"  
    Identifier "HDMIScreen"  
    Device     "HDMIDevice"  
    Monitor    "HDMIMonitor"  
EndSection  

Section     "Screen"  
    Identifier "MimoScreen"  
    Device     "MimoDevice"  
    Monitor    "MimoMonitor"  
EndSection  

Section     "Device"  
    Identifier   "HDMIDevice"  
    Driver     "fbdev"  
    Option     "fbdev" "/dev/fb0"  
EndSection  
 
Section     "Device"  
    Identifier   "MimoDevice"  
    Driver     "fbdev"  
    Option     "fbdev" "/dev/fb1"  
    # True: increase performance at the expense of RAM
    Option "ShadowFB" "true"
EndSection  
 
Section     "Monitor"  
    Identifier   "HDMIMonitor"  
EndSection  

Section     "Monitor"  
    Identifier   "MimoMonitor"  
    VendorName "iMo"
    ModelName "AT-7"
EndSection  

Section "InputClass"
    Identifier "iMo Pivot"
    MatchProduct "eGalax Inc. USB TouchController"
    MatchDevicePath "/dev/input/event*"
    Driver "evdev"
    Option "ReportingMode" "Raw"
    Option "Emulate3Buttons" "false"
    Option "SendCoreEvents" "On"
    Option "InvertX" "false"
    Option "InvertY" "true"
    Option "Calibration" "4014 98 3965 149"
EndSection

HDMI-Only.sh
Code: [Select]
#!/bin/bash
startx -- -layout HDMI

DisplayLink-Only.sh
Code: [Select]
#!/bin/bash
startx -- -layout DisplayLink

RasPi Desktop on HDMI display, LXDE mouse menu on DisplayLink display
HDMI-DisplayLink.sh
Code: [Select]
#!/bin/bash
startx -- -layout HDMIDL

Desktop across both displays
Xinerama.sh
Code: [Select]
#!/bin/bash
startx -- -layout XINERAMA
« Last Edit: 02 February 2013, 09:33:33 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!

Confusticated

  • New IT customer
  • Hero Member
  • *
  • Posts: 663
Re: Linux Twiddly Bits
« Reply #10 on: 25 March 2014, 09:08:31 pm »

Concept of using a web server as an automated control interface.

File: control.php
Code: [Select]
<?php
    
// Check whether we want HTML output or not
    
if(isset($_POST['html']) || isset($_GET['html'])) {
        
$html $_REQUEST['html'];
    }
    else {
        
// assume we do
       
$html 1;
    }

    if(
$html != 0) {
        echo 
'<html>';
        echo 
'<head> <title>Form</title> </head>';
        echo 
'<body>';
        echo 
'<h1>';
    }

    if(isset(
$_POST['relay']) || isset($_GET['relay'])) {
        
$relay $_REQUEST['relay'];
        switch (
$relay) {
            case 
'0' : {
                
// Insert code here to change relay state
                
echo 'Relay off';
                break;
            }
            case 
'1' : {
                
// Insert code here to change relay state
                
echo 'Relay on';
                break;
            }
            default : {
                echo 
'What "'.$relay.'" ???';
                break;
            }
        }
    }
    else {
        
// Relay state should be interrogated here and reported
        
echo '<h1>Relay state unknown</h1>';
    }

    if(
$html != 0) {
        echo 
'</h1>';
        echo 
'<h2>Enter required relay state</h2>';
        echo 
'<form method="post" action="control.php">';
        echo 
'<input type="text" name="relay">';
        echo 
'<input type="submit">';
        echo 
'</form>';
        echo 
'</body>';
        echo 
'</html>';
    }
?>


File: get.sh
Code: [Select]
#!/bin/bash
if [ $# -eq 0 ] ; then
    # Open a connection and hold it for the duration
    ( $0 $$ 1>&3  cat 0<&3) 3<> /dev/tcp/127.0.0.1/6666
else
    # stdin/stdout now go to the network connection
    echo "Sending request to turn relay on" >> /dev/tty
    echo "GET /control.php?&html=0&relay=1 HTTP/1.1"
    echo ""
    until ! read -t 1 ANS ; do
        echo "\"$ANS\"" | grep Relay >> /dev/tty
    done
fi

File: post.sh
Code: [Select]
#!/bin/bash
if [ $# -eq 0 ] ; then
    # Open a connection and hold it for the duration
    ( $0 $$ 1>&3  cat 0<&3) 3<> /dev/tcp/127.0.0.1/6666
else
    # stdin/stdout now go to the network connection
    echo "Sending request to turn relay on" >> /dev/tty
    echo "POST /control.php HTTP/1.1"
    echo "Content-Type: application/x-www-form-urlencoded"
    echo "Content-Length: 14"
    echo ""
    echo "html=0&relay=1"
    until ! read -t 1 ANS ; do
        echo "\"$ANS\"" >> /dev/tty
    done
fi

File: start-server.sh
Code: [Select]
#!/bin/bash
php -S 127.0.0.1:6666 -t $(pwd)

Running start-server.sh fires up PHP's test web server, leave it running and switch to another terminal.
Now run either get.sh (GET Method) or post.sh (POST Method), or point your browser to http://localhost:6666/control.php
The get.sh and post.sh scripts simply send a HTML page to the webserver, which should be performed whichever way is most suitable for automating.
I used bash script here as networking examples in bash are not that common.

NB. This code is purely for the purposes of demonstration.
« Last Edit: 25 March 2014, 09:32:51 pm by Confusticated »
Logged
Advocatus Diaboli - My agenda is not to give you the answer, but to guide your thoughts so you derive it for yourself!
Pages: [1]
 
 

Powered by MySQL Powered by PHP SMF 2.0.10 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!