Version 1.4.3

Bugfix: in function set_ch the address of channel was incremented instead of the value of it
Bugfix: in function get_timing integers were read to byte sized fields causing memory corruption
Updated and renamed moving_debug.c & moving_debug.h
This commit is contained in:
2021-08-30 20:33:19 +02:00
parent 0833762006
commit da56a0eb10
7 changed files with 63 additions and 39 deletions

View File

@@ -4,7 +4,7 @@ project(redony_automata C)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
add_executable(redony_automata main.c timing.c timing.h add_executable(redony_automata main.c timing.c timing.h
moving.c moving.h # moving.c moving.h
shutter.h shutter.h
#mozgatas_demo.c mozgatas_demo.h moving_debug.c moving_debug.h
) )

3
main.c
View File

@@ -1,5 +1,5 @@
#include "timing.h" #include "timing.h"
#include "moving.h" #include "moving_debug.h"
#include <stdio.h> #include <stdio.h>
#define FILEPATH "menetrend.txt" #define FILEPATH "menetrend.txt"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -56,7 +56,6 @@ int main ()
set_ch (&ercsi13[i], &ch); set_ch (&ercsi13[i], &ch);
switch (check_timing (&ercsi13[i])) switch (check_timing (&ercsi13[i]))
{ {
case up:press_button (up); case up:press_button (up);
break; break;
case stop:break; case stop:break;

View File

@@ -7,19 +7,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> //project is to be compiled to openwrt #include <unistd.h> //project is to be compiled to openwrt
void set_ch (shutter *r, byte *ch) void set_ch (shutter *r, byte *channel)
{ {
while (*ch != r->ch) while (*channel != r->ch)
{ {
if (*ch > r->ch) if (*channel > r->ch)
{ {
press_button (prev); press_button (prev);
*ch--; (*channel)--;
} }
else if (*ch < r->ch) else if (*channel < r->ch)
{ {
press_button (next); press_button (next);
*ch++; (*channel)++;
} }
} }
} }
@@ -40,16 +40,16 @@ void reset ()
//doing positive logic as button GPIOs are 0 on startup //doing positive logic as button GPIOs are 0 on startup
void press_button (buttons b) void press_button (buttons b)
{ {
char *fname = calloc (29, 1); char *fname = calloc (29, sizeof (char ));
sprintf (fname, "/sys/class/gpio/gpio%d/value", b); sprintf (fname, "/sys/class/gpio/gpio%d/value", b);
FILE *gpio = fopen (fname, "w"); FILE *gpio = fopen (fname, "w");
usleep (200000);
fprintf (gpio, "0"); fprintf (gpio, "0");
fclose (gpio); fclose (gpio);
gpio = fopen (fname, "w"); gpio = fopen (fname, "w");
usleep (200000); usleep (200000);
fprintf (gpio, "1"); fprintf (gpio, "1");
fclose (gpio); fclose (gpio);
usleep (200000);
} }
void lower (shutter *r) void lower (shutter *r)

View File

@@ -2,14 +2,24 @@
// Created by lacko on 19/08/2021. // Created by lacko on 19/08/2021.
// //
#include "mozgatas_demo.h" #include "moving_debug.h"
#include <stdio.h> #include <stdio.h>
void set_ch (shutter *r) void set_ch (shutter *r, byte *channel)
{ {
reset (); while (*channel != r->ch)
for (int i = 1; i <= r->ch; ++i) {
printf ("ch. %d\n", i); if (*channel > r->ch)
{
press_button (prev);
(*channel)--;
}
else if (*channel < r->ch)
{
press_button (next);
(*channel)++;
}
}
} }
//reset láb active low, de negatív logikával van bekötve //reset láb active low, de negatív logikával van bekötve
@@ -34,4 +44,11 @@ void press_button (buttons b)
break; break;
default: printf ("hiba\n"); default: printf ("hiba\n");
} }
}
void lower (shutter *r)
{
press_button (down);
printf ("sleeping %d usecs", r->percentage * r->rolltime_down * 10000);
press_button (stop);
} }

21
moving_debug.h Normal file
View File

@@ -0,0 +1,21 @@
//
// Created by lacko on 19/08/2021.
//
#ifndef _MOVING_DEBUG_H_
#define _MOVING_DEBUG_H_
#include "shutter.h"
//set to the desired channel on the remote
void set_ch (shutter *r, byte *channel);
//activates the gpio given to it and thus "presses" the button
void press_button (buttons b);
//resets the remote so we start from ch 1
void reset ();
//lowers the shutter to the percentage level described in the shutter structure
void lower (shutter *r);
#endif //_MOVING_DEBUG_H_

View File

@@ -1,18 +0,0 @@
//
// Created by lacko on 19/08/2021.
//
#ifndef _MOZGATAS_DEMO_H_
#define _MOZGATAS_DEMO_H_
#include "shutter.h"
//beállítja a távirányítón a kívánt redőny csatornáját
void set_ch (shutter *r);
//megnyomja a kívánt gombot
void press_button (buttons b);
//reseteli a távirányítót, hogy a 0-ás csatornáról kezdjünk
void reset ();
#endif //_MOZGATAS_DEMO_H_

View File

@@ -61,7 +61,7 @@ int find_next_day (FILE *f)
void get_timing (shutter *r, FILE *schedule) void get_timing (shutter *r, FILE *schedule)
{ {
int channel = 0; int tmp_min = 0, tmp_hour = 0, channel = 0, tmp_percentage = 0;
while (channel != r->ch) while (channel != r->ch)
{ {
fscanf (schedule, "%*[^\n]s\n"); fscanf (schedule, "%*[^\n]s\n");
@@ -71,14 +71,19 @@ void get_timing (shutter *r, FILE *schedule)
} }
} }
while (fscanf (schedule, "%d:%d", &r->up.tm_hour, &r->up.tm_min) != 2) while (fscanf (schedule, "%d:%d", &tmp_hour, &tmp_min) != 2)
fscanf (schedule, "%*c"); fscanf (schedule, "%*c");
r->up.tm_hour = (char )tmp_hour;
r->up.tm_min = (char )tmp_min;
while (fscanf (schedule, "%d:%d", &r->down.tm_hour, &r->down.tm_min) != 2) while (fscanf (schedule, "%d:%d", &tmp_hour, &tmp_min) != 2)
fscanf (schedule, "%*c"); fscanf (schedule, "%*c");
r->down.tm_hour = (char )tmp_hour;
r->down.tm_min = (char )tmp_min;
while (fscanf (schedule, "%d", &r->percentage) != 1) while (fscanf (schedule, "%d", &tmp_percentage) != 1)
fscanf (schedule, "%*c"); fscanf (schedule, "%*c");
r->percentage = (char )tmp_percentage;
fscanf (schedule, "%*[^\n]s\n"); fscanf (schedule, "%*[^\n]s\n");
} }