mirror of
https://github.com/Derisis13/Shutter.git
synced 2025-12-06 19:32:48 +01:00
Version 1.5.1
Added dynamic memory management for shutters (functions in shutter.c). Code is now much easier to tailor to specific needs and works better in the limited RAM of routers. Memory leaks were not found by Valgrind Memcheck.
This commit is contained in:
@@ -7,4 +7,4 @@ add_executable(redony main.c timing.c timing.h
|
|||||||
# moving.c moving.h
|
# moving.c moving.h
|
||||||
shutter.h
|
shutter.h
|
||||||
moving_debug.c moving_debug.h
|
moving_debug.c moving_debug.h
|
||||||
)
|
shutter.c)
|
||||||
48
main.c
48
main.c
@@ -2,6 +2,8 @@
|
|||||||
#include "moving.h"
|
#include "moving.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define FILEPATH "menetrend.txt"
|
#define FILEPATH "menetrend.txt"
|
||||||
|
#define N_of_Shutters 7
|
||||||
|
#define rolltimelist {23, 23, 23, 23, 16, 23, 33}
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
* SHUTTER AUTOMATA
|
* SHUTTER AUTOMATA
|
||||||
* -----------------
|
* -----------------
|
||||||
@@ -14,39 +16,26 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
shutter ercsi13[] = {
|
//set up linked list of shutters
|
||||||
{
|
shutter *ercsi13 = NULL;
|
||||||
1, 0, 0, 0, 0, 23, 0 //fiúszoba
|
byte rolltimes[] = rolltimelist;
|
||||||
},
|
for (int i = 0; i < N_of_Shutters; ++i)
|
||||||
{
|
{
|
||||||
2, 0, 0, 0, 0, 23, 0 //lányszoba
|
shutter *tmpshutter = create_shutter ((byte)(i + 1), rolltimes[i]);
|
||||||
},
|
append_shutter (&ercsi13, tmpshutter);
|
||||||
{
|
}
|
||||||
3, 0, 0, 0, 0, 23, 0 //nappali bal
|
|
||||||
},
|
|
||||||
{
|
|
||||||
4, 0, 0, 0, 0, 23, 0 //nappali jobb
|
|
||||||
},
|
|
||||||
{
|
|
||||||
5, 0, 0, 0, 0, 16, 0 //konyha
|
|
||||||
},
|
|
||||||
{
|
|
||||||
6, 0, 0, 0, 0, 23, 0 //szülői szoba
|
|
||||||
},
|
|
||||||
{
|
|
||||||
7, 0, 0, 0, 0, 33, 0 //előtető (lehúzás = kieresztés, felhúzás = behúzás)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//get the time of launch
|
//get the time of launch
|
||||||
time_t t = time (NULL);
|
time_t t = time (NULL);
|
||||||
struct tm *now = localtime (&t);
|
struct tm *now = localtime (&t);
|
||||||
|
|
||||||
//scan the schedule
|
//scan the schedule
|
||||||
for (int i = 0; i < 7; ++i)
|
|
||||||
|
for (shutter *tmp = ercsi13; tmp != NULL; tmp = tmp->next)
|
||||||
{
|
{
|
||||||
FILE *schedule = fopen (FILEPATH, "r");
|
FILE *schedule = fopen (FILEPATH, "r");
|
||||||
find_today (schedule);
|
find_today (schedule);
|
||||||
get_timing (&ercsi13[i], schedule);
|
get_timing (tmp, schedule);
|
||||||
fclose (schedule);
|
fclose (schedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,19 +43,20 @@ int main ()
|
|||||||
byte ch = 1; //remote defaults to ch 1
|
byte ch = 1; //remote defaults to ch 1
|
||||||
|
|
||||||
//check timings and act accordingly
|
//check timings and act accordingly
|
||||||
for (int i = 0; i < 7; ++i)
|
for (shutter *tmp = ercsi13; tmp != NULL; tmp = tmp->next)
|
||||||
{
|
{
|
||||||
set_ch (&ercsi13[i], &ch);
|
set_ch (tmp, &ch);
|
||||||
switch (check_timing (&ercsi13[i], now))
|
switch (check_timing (tmp, now))
|
||||||
{
|
{
|
||||||
case up:press_button (up);
|
case up:press_button (up);
|
||||||
break;
|
break;
|
||||||
case stop:break;
|
case stop:break;
|
||||||
case down:lower (&ercsi13[i]);
|
case down:lower (tmp);
|
||||||
break;
|
break;
|
||||||
case prev:
|
case prev:
|
||||||
case next:break;
|
case next:break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
free_shutters (ercsi13);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
35
shutter.c
Normal file
35
shutter.c
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// Created by lacko on 18/09/2021.
|
||||||
|
//
|
||||||
|
#include "shutter.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
shutter *create_shutter (byte ch, byte rolltime_down)
|
||||||
|
{
|
||||||
|
shutter *new_shutter = calloc (1, sizeof (shutter));
|
||||||
|
new_shutter->ch = ch;
|
||||||
|
new_shutter->rolltime_down = rolltime_down;
|
||||||
|
return new_shutter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void append_shutter (shutter **head, shutter *new_shutter)
|
||||||
|
{
|
||||||
|
if (*head == NULL)
|
||||||
|
{
|
||||||
|
*head = new_shutter;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
shutter *tmp = *head;
|
||||||
|
while (tmp->next != NULL)
|
||||||
|
tmp = tmp->next;
|
||||||
|
tmp->next = new_shutter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_shutters (shutter *head)
|
||||||
|
{
|
||||||
|
for (shutter *tmp = head; head != NULL; tmp = head)
|
||||||
|
{
|
||||||
|
head = head->next;
|
||||||
|
free (tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ typedef struct shutter {
|
|||||||
minitime down; //time of lowering
|
minitime down; //time of lowering
|
||||||
byte rolltime_down; //measured in seconds, measured when the shutter is rolling down (usually faster than rolling up)
|
byte rolltime_down; //measured in seconds, measured when the shutter is rolling down (usually faster than rolling up)
|
||||||
byte percentage; //the percentage to which the shutter is to be lowered
|
byte percentage; //the percentage to which the shutter is to be lowered
|
||||||
|
struct shutter *next;
|
||||||
} shutter;
|
} shutter;
|
||||||
|
|
||||||
typedef enum buttons {
|
typedef enum buttons {
|
||||||
@@ -27,4 +28,8 @@ typedef enum buttons {
|
|||||||
prev,
|
prev,
|
||||||
next
|
next
|
||||||
} buttons;
|
} buttons;
|
||||||
|
|
||||||
|
shutter * create_shutter (byte ch, byte rolltime_down);
|
||||||
|
void append_shutter (shutter **head, shutter *new_shutter);
|
||||||
|
void free_shutters (shutter * head);
|
||||||
#endif //_SHUTTER_H_
|
#endif //_SHUTTER_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user