diff --git a/CMakeLists.txt b/CMakeLists.txt index b5668b6..2173630 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(redony_automata C) set(CMAKE_C_STANDARD 99) add_executable(redony_automata main.c timing.c timing.h - moving.c moving.h +# moving.c moving.h shutter.h - #mozgatas_demo.c mozgatas_demo.h + moving_debug.c moving_debug.h ) \ No newline at end of file diff --git a/main.c b/main.c index df61485..29807e8 100755 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ #include "timing.h" -#include "moving.h" +#include "moving_debug.h" #include #define FILEPATH "menetrend.txt" /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -56,7 +56,6 @@ int main () set_ch (&ercsi13[i], &ch); switch (check_timing (&ercsi13[i])) { - case up:press_button (up); break; case stop:break; diff --git a/moving.c b/moving.c index 913dc5e..8753ea3 100644 --- a/moving.c +++ b/moving.c @@ -7,19 +7,19 @@ #include #include //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); - *ch--; + (*channel)--; } - else if (*ch < r->ch) + else if (*channel < r->ch) { press_button (next); - *ch++; + (*channel)++; } } } @@ -40,16 +40,16 @@ void reset () //doing positive logic as button GPIOs are 0 on startup 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); FILE *gpio = fopen (fname, "w"); - usleep (200000); fprintf (gpio, "0"); fclose (gpio); gpio = fopen (fname, "w"); usleep (200000); fprintf (gpio, "1"); fclose (gpio); + usleep (200000); } void lower (shutter *r) diff --git a/mozgatas_demo.c b/moving_debug.c similarity index 52% rename from mozgatas_demo.c rename to moving_debug.c index 0e4d27b..699fac9 100644 --- a/mozgatas_demo.c +++ b/moving_debug.c @@ -2,14 +2,24 @@ // Created by lacko on 19/08/2021. // -#include "mozgatas_demo.h" +#include "moving_debug.h" #include -void set_ch (shutter *r) +void set_ch (shutter *r, byte *channel) { - reset (); - for (int i = 1; i <= r->ch; ++i) - printf ("ch. %d\n", i); + while (*channel != r->ch) + { + 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 @@ -34,4 +44,11 @@ void press_button (buttons b) break; default: printf ("hiba\n"); } +} + +void lower (shutter *r) +{ + press_button (down); + printf ("sleeping %d usecs", r->percentage * r->rolltime_down * 10000); + press_button (stop); } \ No newline at end of file diff --git a/moving_debug.h b/moving_debug.h new file mode 100644 index 0000000..889ec22 --- /dev/null +++ b/moving_debug.h @@ -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_ diff --git a/mozgatas_demo.h b/mozgatas_demo.h deleted file mode 100644 index ed34ee1..0000000 --- a/mozgatas_demo.h +++ /dev/null @@ -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_ diff --git a/timing.c b/timing.c index c1c347a..06e2925 100644 --- a/timing.c +++ b/timing.c @@ -61,7 +61,7 @@ int find_next_day (FILE *f) 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) { 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"); + 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"); + 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"); + r->percentage = (char )tmp_percentage; fscanf (schedule, "%*[^\n]s\n"); }