Browse Source

import

master
Vladimir Smagin 1 year ago
commit
f02b4d1421

+ 7
- 0
draw_lcd/60-disk_c View File

@@ -0,0 +1,7 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/disk_c.map"

LINES=`echo -e "\x08\x02\x05\x06 Disk health\n\x01\x03\x04\x07 good"`

$LCDPROG "$LINES"

+ 16
- 0
draw_lcd/circle.sh View File

@@ -0,0 +1,16 @@
#!/bin/bash

SSPATH="/opt/draw_lcd/"

while true
do

frames=`ls -w1 $SSPATH/frames/*.ss`

for frame in $frames
do
$frame
sleep 5
done

done

+ 9
- 0
draw_lcd/cpu_term View File

@@ -0,0 +1,9 @@
#!/bin/bash

cputemp=$(</sys/class/thermal/thermal_zone0/temp)

temp1=$(( cputemp/1000 ))
temp2=$(( cputemp%1000 ))
temp2=$(( temp2/100 ))

echo -e "$temp1.$temp2"

+ 8
- 0
draw_lcd/frames/00-time.ss View File

@@ -0,0 +1,8 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/set1.map"

DATE=`date "+%H:%M:%S"`
LINES=`echo -e "\x04\x05\x06 Raspi NAS\n \x07 \x01 $DATE"`

$LCDPROG "$LINES"

+ 10
- 0
draw_lcd/frames/10-show_cpu_and_sda_temp.ss View File

@@ -0,0 +1,10 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/set1.map"

CPU_TEMP=`/opt/cpu_term`
HDD_TEMP=`cat /var/run/temp-sda`

LINES=`echo -e "CPU temp: $CPU_TEMP\xdf\nHDD temp: $HDD_TEMP\xdf"`

$LCDPROG "$LINES"

+ 10
- 0
draw_lcd/frames/20-smart.ss View File

@@ -0,0 +1,10 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/set1.map"

ATWORK=`cat /run/smart_sda.txt|grep "Power_On_Hours" | awk '{ print $10 }'`
BAD=`cat /run/smart_sda.txt|grep "Reallocated_Sector_Ct" | awk '{ print $10 }'`

LINES=`echo -e "\x08 HDD health\nPOH $ATWORK BAD $BAD"`

$LCDPROG "$LINES"

+ 11
- 0
draw_lcd/frames/30-space.ss View File

@@ -0,0 +1,11 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/hdd.map"

#\x08\x04\x01 \x03\x05\x02
USED=`df -h /dev/sda1|grep sda1|awk '{ print $3 }'`
FREE=`df -h /dev/sda1|grep sda1|awk '{ print $4 }'`

LINES=`echo -e "\x08\x04\x01\x06 Used $USED\n\x03\x05\x02\x07 Free $FREE"`

$LCDPROG "$LINES"

+ 10
- 0
draw_lcd/frames/40-mem.ss View File

@@ -0,0 +1,10 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/set1.map"

USED=`free -mh|grep Mem|awk '{ print $3 }'`
FREE=`free -mh|grep Mem|awk '{ print $4 }'`

LINES=`echo -e "\x02 Memory\nU $USED, F $FREE"`

$LCDPROG "$LINES"

+ 41
- 0
draw_lcd/frames/50-network.ss View File

@@ -0,0 +1,41 @@
#!/bin/bash

LCDPROG="/opt/lcd/lcd595out /opt/lcd/set2.map"

#detect GW IP address
GATEWAY=`ip r|grep default|awk '{ print $3 }'`

GWPING=`/usr/bin/fping $GATEWAY|grep alive`
online_gw="+GW"
if [ "$GWPING" = "" ]
then
online_gw="-GW"
fi

#check city network
GWPING=`/usr/bin/fping blindage.org|grep alive`
online_tsk="+TSK"
if [ "$GWPING" = "" ]
then
online_tsk="-TSK"
fi

#check internet access
GWPING=`/usr/bin/fping ya.ru|grep alive`
online_int="+INT"
if [ "$GWPING" = "" ]
then
online_int="-INT"
fi

#check openvpn tunnel
GWPING=`/usr/bin/fping 10.0.0.10|grep alive`
online_t="+T"
if [ "$GWPING" = "" ]
then
online_t="-T"
fi

LINES=`echo -e "\x08 Network status\n$online_gw $online_tsk $online_int $online_t"`

$LCDPROG "$LINES"

+ 122
- 0
init.d/lcd View File

@@ -0,0 +1,122 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: lcd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO

# Author: Foo Bar <foobar@baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="LCD Circle"
NAME=lcd
DAEMON=/opt/draw_lcd/circle.sh
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
$DAEMON &
}

#
# Function that stops the daemon/service
#
do_stop()
{
killall $DAEMON
return 0
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}

case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

:

+ 9
- 0
install.txt View File

@@ -0,0 +1,9 @@
wiring:
http://blindage.org/?p=4835

install files:
put "lcd" and "draw_lcd" to /opt/

run at startup:
put init.d/lcd to /etc/init.d/
run "update-rc.d lcd defaults" and reboot

+ 3
- 0
lcd/build View File

@@ -0,0 +1,3 @@
rm ./lcd595out
cc -o lcd595out lcd_out.c -lwiringPi -std=c99 -Wimplicit-function-declaration
./lcd595out "`date`"

BIN
lcd/disk_c.map View File


BIN
lcd/hdd.map View File


BIN
lcd/lcd595out View File


+ 225
- 0
lcd/lcd_out.c View File

@@ -0,0 +1,225 @@
#include <time.h>
#include <wiringPi.h>
#include <wiringShift.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int latchPin=2;
int clockPin=3;
int dataPin=0;

#define BIT_RS 4
#define BIT_E 5

#define BIT_ENABLE(x,n) ((x) |= (1<<(n)))
#define BIT_DISABLE(x,n) ((x) &=~ (1<<(n)))

unsigned char pos_addr[5];
uint8_t pos_last=1;

uint8_t reverse_bits(uint8_t to_reverse) {
uint8_t reversed=0;
for( uint8_t i=0; i<8; ++i)
{
reversed = reversed << 1;
reversed |= (to_reverse & 0x1);
to_reverse = to_reverse >> 1;
}
return reversed;
}

void reg_send(uint8_t value)
{
uint8_t i;

for(i = 8; i; --i)
{
if(value & 0x80)
digitalWrite(dataPin,HIGH);
else
digitalWrite(dataPin,LOW);
delayMicroseconds(15);
digitalWrite(clockPin,HIGH);
delayMicroseconds(15);
digitalWrite(clockPin,LOW);
delayMicroseconds(15);
value <<= 1;
}
digitalWrite(dataPin,LOW);
delayMicroseconds(15);
digitalWrite(latchPin,HIGH);
delayMicroseconds(15);
digitalWrite(latchPin,LOW);
}

void low_send(unsigned char data, uint8_t type) {
data = reverse_bits(data);
data = data >> 4;
if (type>0) BIT_ENABLE(data,BIT_RS); else BIT_DISABLE(data, BIT_RS);
BIT_ENABLE(data,BIT_E);
reg_send(data);
BIT_DISABLE(data,BIT_E);
reg_send(data);
//reg_send((1<<BIT_E)|(type<<BIT_RS)|data);
//reg_send((0<<BIT_E)|(type<<BIT_RS)|data);

}

void lcd_send(unsigned char data, uint8_t _RS) {
uint8_t H_BITS, L_BITS;
H_BITS=0|(data >> 4);
L_BITS=(data & 0x0F);
low_send(H_BITS,_RS);
low_send(L_BITS,_RS);
digitalWrite (latchPin, HIGH) ;
delayMicroseconds(15);
digitalWrite (latchPin, LOW) ;
}


void lcd_init() {
lcd_send(0x20,0);
lcd_send(0,0);
lcd_send(0x14,0);
lcd_send(0x06,0);
lcd_send(0x0f,0);
lcd_send(0x28,0);

pos_addr[1]=0x00;
pos_addr[2]=0x40;
pos_addr[3]=0x14;
pos_addr[4]=0x54;
pos_last=1;
}

void lcd_char(unsigned char data) {
lcd_send(data,1);
}

void lcd_text (const char *s)
{
register char c;
while (c = *s++)
{
if (c == '\n')
{
//next line
pos_last=pos_last+1;
lcd_send((1 << 7)|pos_addr[pos_last],0);
if (pos_last>=5) pos_last=1;
}
else
//just send
lcd_char(c);
}
}

void lcd_clear() {
lcd_send(0x01,0);
delay(5);
pos_last=1;
}

void setup(){
pinMode(clockPin,OUTPUT);
pinMode(latchPin,OUTPUT);
pinMode(dataPin,OUTPUT);

digitalWrite(clockPin,HIGH);
digitalWrite(latchPin,HIGH);
delayMicroseconds(100);

reg_send(0xff);
reg_send(0xff);

digitalWrite(latchPin,LOW);
digitalWrite(clockPin,LOW);
digitalWrite(dataPin,LOW);
}

void load_ext_map(char *fname_own)
{

FILE *file;

char *fname;

fname = fname_own;

file = fopen(fname,"r");


if(file == 0)
{
printf("cant open '%s'",fname);
} else {
//printf("Map '%s' opened\n",fname);
//get file size and load to LCD memory
fseek(file, 0L, SEEK_END);
int fsz = ftell(file);
fseek(file, 0L, SEEK_SET);
unsigned char chbyte;
int charnum = 1, charcnt = 0;
for(int p=0;p<fsz;p++) {
chbyte = getc(file);
//printf("Sending addr and char\n");
lcd_send(0x40+p,0);
//delay(1);
lcd_send(chbyte,1); //write byte to mem
//delay(1);

//uncomment for debug
charcnt++;
if (charcnt > 8) { charcnt = 1; charnum++; }
//printf("CHAR %d ADDR %02X BYTE %02X\n",charnum, 0x40+p, chbyte);
}
lcd_send(0x02,0);
fclose(file);
delay(50);
}
}

int main( int argc, char *argv[] ){
if (wiringPiSetup()==-1) { exit(1); }
setup();
lcd_init();
if ( argc < 3 ) /* argc should be 3 for correct execution */
{
printf("You forgot something\n");
lcd_send(0x0C,0); //turn on display
delay(1);
while(1) {
lcd_clear();
lcd_text("Vladimir Smagin\n");
lcd_text("vk.com/int21h\n");
delay(3000);
lcd_clear();
lcd_text("Visit my site:\n");
lcd_text("blindage.org\n");
delay(3000);
}
} else {
if (argc>2) {
//printf("Loading %s \n", argv[1]);
lcd_send(0x08,0); //turn off display
delay(1);
load_ext_map(argv[1]);
lcd_clear();
lcd_text(argv[2]);
lcd_send(0x0C,0); //turn on display
delay(1);
} else {
printf("./lcd595out ./charmap \"text\"");
}
}
return 0;
}


BIN
lcd/set1.map View File


+ 1
- 0
lcd/set2.map View File

@@ -0,0 +1 @@


Loading…
Cancel
Save