Hallo zusammen.
zu meinem Abschied von hier möchte ich noch nen kleinen Beitrag leisten:
Es bezieht sich auf : Hardwareproblem/Ventile o.Ä
... hab's hinbekommen.
... mag wer dahintersteigen, oder auch nicht... egal
... hidden routine:
#i've used the pigpio Daemon... using: gpioWrite_Bits_0_31_Set... gpioWrite_Bits_0_31_Clr...
... added the procedures ...shift_down_and_show(), and EOW_func().
... it run's
... you'l never seen it... try to find out it.
... bye @all
@ manul : visual effect ist ab morgen in youtupe verfügbar ...
... mit echtem Wasser gibt'ts ne Sauerei am Schreibtisch ... das Ablaufsystem bedarf noch einer Überarbeitung...
... meint zumindest mein mir einzigst angetrautes Eheweib.
...hab eben dbv geantwortet und bin auf nen .... Knopf geclickt.... weiß der Geyer ... pls... ignore
// , June 2017
// © by
//
// compile with: gcc water.c -o water -l pigpio -l rt
//
//
// needed libraries:
//
#include <stdio.h>
#include <stdlib.h>
#include <pigpio.h> // this's not part of the os, must be imported
#include <string.h>
#include <time.h>
//
// self-designed macros for general purpose
//
#define ESC 27 // esc CHAR
#define cursor(y,x) printf("%c[%d;%dH",ESC,y,x) // positioning cursor
#define cls() printf("%c[2J",ESC) // clear the screen
#define CHK_BIT(var,pos) ((var) & (1<<(pos))) // test a bit in var x at pos y, return's T if true, else F // return 1 if true else 0
// fetch char's array
//
char source[8];
//
// simulator array
//
char dest1[8]; char dest2[8]; char dest3[8]; char dest4[8]; char dest5[8]; char dest6[8]; char dest7[8]; char dest8[8];
char dest9[8]; char dest10[8]; char dest11[8];
//
// that's a fictifious ASCII table without 'holes' as the origin have.
// each char got, have an appropriate row in that 2-dimensional array.
// the index of an char in that array depends on the ASCII char-table by an algorythm ... have to find ...
// ... i've found it ... :)
//
int array[39][8] = { {0x7e, 0x83, 0x85, 0x89, 0x91, 0xa1, 0xc1, 0x7e}, // 0 // numeric
{0xc0, 0xc0, 0xc0, 0xc0, 0xc3, 0xcc, 0xf0, 0xe0}, // 1
{0xff, 0x07, 0x03, 0x03, 0x7e, 0x80, 0x80, 0x7f}, // 2
{0x7e, 0xff, 0xc0, 0x7c, 0x7c, 0xc0, 0xff, 0x7e}, // 3
{0x18, 0x18, 0x18, 0x7f, 0x19, 0x01, 0x02, 0x0c}, // 4
{0x7e, 0x80, 0x80, 0x80, 0x7f, 0x03, 0x03, 0x7f}, // 5
{0x7e, 0x81, 0x81, 0x7f, 0x01, 0x81, 0x80, 0x7e}, // 6
{0x02, 0x04, 0x08, 0xfc, 0x20, 0xc0, 0x80, 0xff}, // 7
{0x7e, 0x81, 0x81, 0x7e, 0x81, 0x81, 0x81, 0x7e}, // 8
{0x7e, 0xc0, 0xc0, 0xc0, 0xfe, 0xc3, 0xc3, 0x7e}, // 9
{0xc3, 0xc3, 0xff, 0xff, 0xc3, 0x66, 0x3c, 0x18}, // a // alphabetic's
{0x7f, 0x83, 0x83, 0x7f, 0x83, 0x83, 0x83, 0x7f}, // b
{0x7e, 0xff, 0x83, 0x03, 0x03, 0x03, 0xff, 0x7c}, // c
{0x7f, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x7f}, // d
{0xff, 0x03, 0x03, 0x7f, 0x7f, 0x03, 0x03, 0xff}, // e
{0x03, 0x03, 0x03, 0x3f, 0x3f, 0x03, 0x03, 0xff}, // f
{0x7f, 0xff, 0xc3, 0xf3, 0x03, 0x03, 0xff, 0x7f}, // g
{0xc3, 0xc3, 0xc3, 0xff, 0xff, 0xc3, 0xc3, 0xc3}, // h
{0x3c, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c}, // i
{0x3c, 0x7e, 0x66, 0x60, 0x60, 0x60, 0x7f, 0x7f}, // j
{0x63, 0x33, 0x1f, 0x07, 0x07, 0x1f, 0x33, 0x63}, // k
{0x7e, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06}, // l
{0x88, 0x88, 0x88, 0x88, 0xd9, 0x7e, 0x3e, 0x3c}, // m
{0xc3, 0xc3, 0xe3, 0xd3, 0xcb, 0xc7, 0xc3, 0xc3}, // n
{0x7e, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0x7e}, // o
{0x03, 0x03, 0x7f, 0xff, 0xc3, 0xc3, 0xff, 0x7f}, // p
{0x7e, 0xff, 0xcf, 0xcb, 0xc3, 0xc3, 0xff, 0x7e}, // q
{0x7c, 0x3f, 0x0f, 0x3f, 0x7f, 0xc3, 0xff, 0x7f}, // r
{0x3e, 0x7e, 0xc0, 0x70, 0x0e, 0x30, 0xfe, 0x7c}, // s
{0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0xff}, // t
{0x7c, 0x7e, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, // u
{0x18, 0x3c, 0x3c, 0x66, 0xc6, 0xc3, 0xc3, 0xc3}, // v
{0xc3, 0xe3, 0xe7, 0x9d, 0xdb, 0xdd, 0xc3, 0xc3}, // w
{0xc3, 0xe6, 0x3c, 0x38, 0x3c, 0x6c, 0xe3, 0xc3}, // x
{0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x66, 0xc3}, // y
{0x7f, 0xfe, 0x80, 0x18, 0x30, 0x21, 0x7f, 0xff}, // z
};
//
// global's
//
int GPIO_Number[8] = {18, 15, 4, 17, 27, 22, 7, 8}; // full access to mag_valves ...
int GPIO_Pwr[2] = {5, 10}; // ...and pump pwr
//
// function call's for general purpose
//
int set_GPIO_ports(); // set solenoid port's
int set_on(); // set pump on/off
int set_midon(); // and appropriate speed
int set_midoff();
int set_fullon();
int set_fulloff();
int set_clr_mag(); // clr\set mag. valve
int shift_down_and_show(); // timing falling matrix like realtime
int EOW_func(); // all drop's are out
int split_2_chars(); // image enhancement
int mag_self_test(); // accoustic selftest
// int shw_matrix_for_correction;
//
/////////////////////////////////////////////////////////////////////
// main
/////////////////////////////////////////////////////////////////////
//
// !!! WARNING !!! array move, copy, memcpy ... etc.
// most of these functions do not work properly if the source and destination arrays overlap.
// for example,if the beginning of the destination array overlaps the end of the source array,
// in ever wor's,the original contents of that part of the source array may get overwritten before it is copied.
// in this case of the string functions, the null byte marking the end of the string may be lost,
// and the copy function might get stuck in a loop trashing all the memory allocated to your program.
//
int main () {
int row, cntr, col, len, index, sft, str, i, j, k, matrix = 0, xbits; // def some variables
int bit_time_delay; bit_time_delay = 11000; // fine tuning....
int row_time_delay; row_time_delay = 4000; // ...for falling parameter's
int char_time_delay; char_time_delay = 60000;
int fall_out_row_delay; fall_out_row_delay = 9000;
char valbytes[30], hexout, c;
if (gpioInitialise() < 0 ) { // try to initialising gpio's
printf("cant init gpios\n");
return 1; // by fail, ret to OS
}
set_GPIO_ports(); // Sub's ...
cls();
set_on();
set_on();
set_midon();
set_fullon();
cursor(5, 10);
printf("init Hardware pls be patient\n");
mag_self_test();
set_fulloff();
set_midoff();
while (1) { // loop programm 'til break
cursor(5,10);
printf(" \n");
cursor(5,10);
printf("Get your string or leave with (Strg c) :");
scanf("%30s", valbytes);
len = strlen(valbytes); // how many char's got i ?
set_midon();
for (str = 0; str < len; str ++) { // now loop the len of string
hexout = valbytes[str]; // point to 1st char in string
cursor(21, 10);
printf (" \n");
cursor (21, 10);
printf ("... working\n");
cursor(8,10);
printf(" ");
cursor(8,10);
printf("working byte: %c\n", hexout);
if (hexout > 64) { // calc the index in the fictifious ASCII table
index = 10 + (hexout - 65); // ...explaint as above
}
else {
index = (hexout - 48);
}
cursor(8,33); // show index
printf (" \n");
cursor(8,33);
printf ("index : %i\n", index);
for (matrix = 0; matrix < 8; matrix++) { // loop the 1st byte found in matrix
hexout = (array[index][matrix]); // fetch 1st array byte
switch (matrix) { // select col
case 0 ... 8: // begin with col 0
for (xbits = 0; xbits < 8; xbits ++) { // select each bit
cursor(18,10); // set cursor ...
printf ("row : %x, act xbyte : %X, bitPattern : \n", xbits, hexout); // show found hexvalue
cursor(18,(50 + ((xbits + 1)* 2))); // ... set again
printf("%c\n\033[32m", (CHK_BIT(hexout, xbits)) ? '#' : ' '); // show org. bit to scrn
source[xbits] = CHK_BIT(hexout, xbits) ? 0x23 : 0x20; // write bit to cache
set_clr_mag(source[xbits], GPIO_Number[xbits]); // set\clr apropp. mag.valve
gpioSleep(PI_TIME_RELATIVE, 0, bit_time_delay);
} // eigth times ...
shift_down_and_show(); // 8 drop's are out, disp that and move
gpioSleep(PI_TIME_RELATIVE, 0, row_time_delay);
break; // done... do next col of that byte
gpioSleep(PI_TIME_RELATIVE, 0, char_time_delay);
}
}
split_2_chars(); // disp a blank line between 2 char's
for (cntr = 0; cntr < 8; cntr ++) // clear all Pin's of solenoid's
gpioWrite(GPIO_Number[cntr], 0);
}
set_midoff(); // switch middle pump off
for (cntr = 0; cntr < 8; cntr ++) // clr input puffer
source[cntr] = 0x20;
cursor(21,10);
printf ("rest is falling... \n");
EOW_func(fall_out_row_delay); // let rest fall out
cursor (21,10);
printf ("\033[0mall is done... \n");
} // wait for user action, string is out
gpioTerminate(); // Strg_c was pressed
return EXIT_SUCCESS; // ret to OS
}
//
//
// that's the most complicated function in that programm.
// this algorythm is part of 2 functions, which are linked by themself. (shift_down_and_show() and EOW_func())
// it show's a simulated falling matrix of waterdrop's ....
// ... even the falling-acceleration (y=1/2at²) is included ...
// ... like the real. ....try to find out, what i've done to solve that problem ....
// ... my secret ):-)
//
int shift_down_and_show() {
int col, row;
int length = 8;
strncpy( dest1, source, length); // cpy sourcebyte to destination_byte_1
for (col = 0; col < 11; col ++){ // ... now let drop's fall
switch (col) { // set 8 row's
case 1: // next is 2nd row in next col ...
memcpy( dest10, dest9, length); // ...same algorythm as above
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest9[row]);
}
break;
case 2:
memcpy( dest9, dest8, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest8[row]);
}
break;
case 3:
memcpy( dest8, dest7, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest7[row]);
}
break;
case 4:
memcpy( dest7, dest6, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest6[row]);
}
break;
case 5:
memcpy( dest6, dest5, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest5[row]);
}
break;
case 6:
memcpy( dest5, dest4, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest4[row]);
}
break;
case 7:
memcpy( dest4, dest3, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest3[row]);
}
break;
case 8:
memcpy( dest3, dest2, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest2[row]);
}
break;
case 9:
memcpy( dest2, dest1, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest1[row]);
}
}
}
return 0;
}
//
// last char is out... let'him fall down 'til absolutely down
// 've no control to the drop's, 'cause they leaved the land
//
int EOW_func(int fall) {
int col, row;
int length = 8;
int rest = 10;
strncpy( dest1, source, length); // last char of string is out
fall = (fall - 150)
do { // 8 col's x 8 row's x 8 roll's
for (col = 0; col < 11; col ++){ // rest of matrix will be shown
switch (col) {
case 0:
memcpy( dest11, dest10, length);
for (row = 0; row < 8; row ++) { // now let's fall...
cursor((20 - col),(70 + ((row + 1)* 2))); // calc cursorposition
printf("%c\n\033[32m", dest11[row]); // and show bits(8 per col)
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 1:
memcpy( dest10, dest9, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest10[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 2:
memcpy( dest9, dest8, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest9[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 3:
memcpy( dest8, dest7, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest8[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 4:
memcpy( dest7, dest6, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest7[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 5:
memcpy( dest6, dest5, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest6[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 6:
memcpy( dest5, dest4, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest5[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 7:
memcpy( dest4, dest3, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest4[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 8:
memcpy( dest3, dest2, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest3[row]);
}
gpioSleep(PI_TIME_RELATIVE, 0, fall);
break;
case 9:
memcpy( dest2, dest1, length);
for (row = 0; row < 8; row ++) {
cursor((20 - col),(70 + ((row + 1)* 2)));
printf("%c\n\033[32m", dest2[row]);
}
}
}
rest --;
} while (rest > 0);
return 0;
}
//
// writes a blank line after each char if valbyte is a string
// it's only for better visualisation
//
int split_2_chars() {
int col, row, cntr;
int length = 8;
for (cntr = 0; cntr < 10; cntr ++) {
source[cntr] = 0x20;
}
memcpy( dest1, source, length);
for (col = 0; col < 11; col ++){
switch (col) {
case 0:
memcpy( dest11, dest10, length);
for (row = 0; row < 8; row ++) {
cursor((18 - col),(70 + ((row + 1)* 2)));
printf("%\n", dest11[row]);
}
break;
case 1:
memcpy( dest10, dest9, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest10[row]);
}
break;
case 2:
memcpy( dest9, dest8, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest9[row]);
}
break;
case 3:
memcpy( dest8, dest7, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest8[row]);
}
break;
case 4:
memcpy( dest7, dest6, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest7[row]);
}
break;
case 5:
memcpy( dest6, dest5, length);
for (row = 0; row < 8; row ++) {
cursor((18 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest6[row]);
}
break;
case 6:
memcpy( dest5, dest4, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest5[row]);
}
break;
case 7:
memcpy( dest4, dest3, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest4[row]);
}
break;
case 8:
memcpy( dest3, dest2, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest3[row]);
}
break;
case 9:
memcpy( dest2, dest1, length);
for (row = 0; row < 8; row ++) {
cursor((21 - col),(70 + ((row + 1)* 2)));
printf("%c\n", dest2[row]);
}
}
}
return 0;
}
//
// define gpio's as output and put out's to an appropriate internal pull_down resistor,
// reason: 'cause of magnetic/inductive sens in the cable's
//
int set_GPIO_ports() {
for (int cntr = 0; cntr < 8; cntr ++) { // mag.vent port's
switch (cntr) {
case 0 ... 1: // pwr port's
gpioSetMode (GPIO_Pwr[cntr], PI_OUTPUT);
gpioSetPullUpDown (GPIO_Pwr[cntr], PI_PUD_DOWN);
gpioSetMode (GPIO_Pwr[cntr], PI_OUTPUT);
gpioSetPullUpDown (GPIO_Pwr[cntr], PI_PUD_DOWN);
}
gpioSetMode (GPIO_Number[cntr], PI_OUTPUT);
gpioSetPullUpDown (GPIO_Number[cntr], PI_PUD_DOWN);
}
return 0;
}
//
// mag valves solenoid's self test
//
int mag_self_test() {
int i, j, k;
for (k = 1; k < 3; k++) {
for (i = 0; i < 8; i++) { // accoustic start
gpioWrite(GPIO_Number[i], 1);
gpioSleep(PI_TIME_RELATIVE, 0, 50000); // sleep for 0.1 seconds
}
gpioSleep(PI_TIME_RELATIVE, 0, 190000);
for (i = 0; i < 8; i++) {
gpioWrite(GPIO_Number[i], 0);
gpioSleep(PI_TIME_RELATIVE, 0, 50000); // sleep for 0.1 seconds
}
gpioSleep(PI_TIME_RELATIVE, 0, 190000); // sleep for 0.1 seconds
}
for (k = 1; k < 4; k++) { // quick on 1st then 2nd
for (j = 0; j < 8; j++) {
gpioWrite(GPIO_Number[j], 1);
}
gpioSleep(PI_TIME_RELATIVE, 0, 90000); // sleep for 0.08 seconds
for (j = 0; j < 8; j++) {
gpioWrite(GPIO_Number[j], 0);
}
gpioSleep(PI_TIME_RELATIVE, 0, 90000);
gpioSleep(PI_TIME_RELATIVE, 0, 90000); // sequenz ready
}
return 0;
}
//
// support's pump activity's and disp it on scrn
//
int set_on() {
cursor (1,25);
printf ("pmp \033[32m☻\033[0m\n");
cursor (2,24);
printf ("midp \033[31m◙\033[0m\n");
gpioWrite(GPIO_Pwr[1], 0);
cursor (3,23);
printf ("fullp \033[31m◙\033[0m\n");
gpioWrite(GPIO_Pwr[2], 0);
return 0;
}
//
int set_midon() {
cursor (2,29);
printf ("\033[32m☻\033[0m\n");
gpioWrite(GPIO_Pwr[1], 1);
return 0;
}
//
int set_midoff() {
cursor (2,29);
printf ("\033[31m◙\033[0m\n");
gpioWrite(GPIO_Pwr[1], 0);
return 0;
}
int set_fullon() {
cursor (3,29);
printf ("\033[32m☻\033[0m\n");
gpioWrite(GPIO_Pwr[2], 1);
return 0;
}
//
int set_fulloff() {
cursor (3,29);
printf ("\033[31m◙\033[0m\n");
gpioWrite(GPIO_Pwr[2], 0);
return 0;
}
//
// set\clr mag valve solenoid, port is given by caller
//
int set_clr_mag(int val, int port) { // get val and port from caller...
if (val == ' ')
gpioWrite (port, 0); // ... clr
else
gpioWrite (port, 1); // ... or set
return 0; // go back to caller...
}
//
Alles anzeigen