SayoriOS 0.3.3

trigger.c
См. документацию.
1
12 #include <io/ports.h>
13 #include <io/status_loggers.h>
14 #include <lib/stdio.h>
15 #include <sys/trigger.h>
16 #include <drv/input/keymap.h>
17 #include "sys/scheduler.h"
18 #include "sys/timer.h"
19
20 trigger_t Triggers[1024] = {0};
21 size_t TriggersCount = 0;
22
23 int _FoundFreeIndexTrigger(){
24 for(int i = 0; i < 1024; i++){
25 if (Triggers[i].is_not_delete == 0) return i;
26 }
27 return -1;
28 }
29
35 int RegTrigger(int type,trigger_cmd_t handler){
37 qemu_log("[Trigger] An attempt to register trigger '%x' was detected.",type);
38 int idx = _FoundFreeIndexTrigger();
39 if (idx == -1) {
40 qemu_err("[Trigger] ERROR NO FREE TRIGGERS SPACE!!");
41 return -1;
42 }
43 Triggers[idx].index = TriggersCount;
44 Triggers[idx].type = type;
45 Triggers[idx].ready = 1;
46 Triggers[idx].is_not_delete = 1;
47 Triggers[idx].cmd = handler;
48 qemu_ok("[Trigger] Format %x trigger has successfully registered and has index number %d.",type,idx);
49 TriggersCount++;
50 return idx;
51 }
52
56 void DeleteTrigger(int index){
57 if (index > 1024 || Triggers[index].is_not_delete == 0){
58 qemu_err("[Trigger] Unknown #%d trigger",index);
59 return;
60 }
61 qemu_log("[Trigger] Trigger #%d has been deleted",index);
62 Triggers[index].is_not_delete = 0;
63 Triggers[index].ready = 0;
64 }
65
69 void OnTrigger(int index){
70 if (index > 1024 || Triggers[index].is_not_delete == 0){
71 qemu_err("[Trigger] Unknown #%d trigger",index);
72 return;
73 }
74
75 Triggers[index].ready = 1;
76 }
77
81 void OffTrigger(int index){
82 if (index > 1024 || Triggers[index].is_not_delete == 0){
83 qemu_err("[Trigger] Unknown #%d trigger",index);
84 return;
85 }
86 qemu_log("[Trigger] Trigger #%d has been disabled",index);
87 Triggers[index].ready = 0;
88 }
89
93 void CallTrigger(int type, void* data1, void* data2, void* data3, void* data4, void* data5){
94 for (size_t inx = 0; inx < TriggersCount; inx++){
95 //if (log) qemu_log("[Trigger] Scan: %d | Type: %x | Ready: %d",inx,Triggers[inx]->type,Triggers[inx]->ready);
96 if (type == Triggers[inx].type && Triggers[inx].ready){
98 Triggers[inx].cmd(data1, data2, data3, data4, data5);
99 }
100 }
101 }
102
106 void triggersConfig(){
107 qemu_log("[Trigger] Configurate...");
108
109 //Triggers = kmalloc(sizeof(trigger_t)*1024); ///< Выделяем память на триггеры
110 }
111
trigger
Definition: trigger.h:24
trigger::cmd
trigger_cmd_t cmd
Команда с 5ю аргументами
Definition: trigger.h:29
trigger::index
size_t index
Индекс триггера
Definition: trigger.h:25
trigger::ready
bool ready
Триггер готов к работе
Definition: trigger.h:27
trigger::type
int type
Тип триггера
Definition: trigger.h:26
trigger::is_not_delete
bool is_not_delete
Триггер НЕ удален и НЕ свободен
Definition: trigger.h:28
DeleteTrigger
void DeleteTrigger(int index)
Удаление триггера
Definition: trigger.c:56
CallTrigger
void CallTrigger(int type, void *data1, void *data2, void *data3, void *data4, void *data5)
Функция для вызовов триггеров (Если самостоятельно надо вызвать триггер)
Definition: trigger.c:93
OffTrigger
void OffTrigger(int index)
Выключить триггер
Definition: trigger.c:81
TriggersCount
size_t TriggersCount
Колво активных триггеров
Definition: trigger.c:21
OnTrigger
void OnTrigger(int index)
Включить триггер
Definition: trigger.c:69
Triggers
trigger_t Triggers[1024]
Сетка смонтированных триггеров
Definition: trigger.c:20
triggersConfig
void triggersConfig()
Инициализация триггеров
Definition: trigger.c:106
RegTrigger
int RegTrigger(int type, trigger_cmd_t handler)
Регистрация триггера
Definition: trigger.c:35