This commit is contained in:
Willy-JL
2023-11-12 02:20:45 +00:00
498 changed files with 4821 additions and 2206 deletions

View File

@@ -1,7 +1,6 @@
#include "dolphin/dolphin.h"
#include "dolphin/helpers/dolphin_state.h"
#include "dolphin_i.h"
#include "portmacro.h"
#include "projdefs.h"
#include <furi_hal.h>
#include <stdint.h>
@@ -10,7 +9,7 @@
#define DOLPHIN_LOCK_EVENT_FLAG (0x1)
#define TAG "Dolphin"
#define HOURS_IN_TICKS(x) ((x)*60 * 60 * 1000)
#define HOURS_IN_TICKS(x) ((x) * 60 * 60 * 1000)
static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin);
@@ -46,8 +45,8 @@ void dolphin_flush(Dolphin* dolphin) {
dolphin_event_send_wait(dolphin, &event);
}
void dolphin_butthurt_timer_callback(TimerHandle_t xTimer) {
Dolphin* dolphin = pvTimerGetTimerID(xTimer);
void dolphin_butthurt_timer_callback(void* context) {
Dolphin* dolphin = context;
furi_assert(dolphin);
DolphinEvent event;
@@ -55,8 +54,8 @@ void dolphin_butthurt_timer_callback(TimerHandle_t xTimer) {
dolphin_event_send_async(dolphin, &event);
}
void dolphin_flush_timer_callback(TimerHandle_t xTimer) {
Dolphin* dolphin = pvTimerGetTimerID(xTimer);
void dolphin_flush_timer_callback(void* context) {
Dolphin* dolphin = context;
furi_assert(dolphin);
DolphinEvent event;
@@ -64,11 +63,11 @@ void dolphin_flush_timer_callback(TimerHandle_t xTimer) {
dolphin_event_send_async(dolphin, &event);
}
void dolphin_clear_limits_timer_callback(TimerHandle_t xTimer) {
Dolphin* dolphin = pvTimerGetTimerID(xTimer);
void dolphin_clear_limits_timer_callback(void* context) {
Dolphin* dolphin = context;
furi_assert(dolphin);
xTimerChangePeriod(dolphin->clear_limits_timer, HOURS_IN_TICKS(24), portMAX_DELAY);
furi_timer_start(dolphin->clear_limits_timer, HOURS_IN_TICKS(24));
DolphinEvent event;
event.type = DolphinEventTypeClearLimits;
@@ -81,17 +80,12 @@ Dolphin* dolphin_alloc() {
dolphin->state = dolphin_state_alloc();
dolphin->event_queue = furi_message_queue_alloc(8, sizeof(DolphinEvent));
dolphin->pubsub = furi_pubsub_alloc();
uint32_t butthurt_timer = xtreme_settings.butthurt_timer;
dolphin->butthurt_timer = xTimerCreate(
NULL,
butthurt_timer ? ((int32_t)butthurt_timer * 1000) : -1,
pdTRUE,
dolphin,
dolphin_butthurt_timer_callback);
dolphin->butthurt_timer =
furi_timer_alloc(dolphin_butthurt_timer_callback, FuriTimerTypePeriodic, dolphin);
dolphin->flush_timer =
xTimerCreate(NULL, 30 * 1000, pdFALSE, dolphin, dolphin_flush_timer_callback);
dolphin->clear_limits_timer = xTimerCreate(
NULL, HOURS_IN_TICKS(24), pdTRUE, dolphin, dolphin_clear_limits_timer_callback);
furi_timer_alloc(dolphin_flush_timer_callback, FuriTimerTypeOnce, dolphin);
dolphin->clear_limits_timer =
furi_timer_alloc(dolphin_clear_limits_timer_callback, FuriTimerTypePeriodic, dolphin);
return dolphin;
}
@@ -131,14 +125,14 @@ FuriPubSub* dolphin_get_pubsub(Dolphin* dolphin) {
static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin) {
furi_assert(dolphin);
TickType_t now_ticks = xTaskGetTickCount();
TickType_t timer_expires_at = xTimerGetExpiryTime(dolphin->clear_limits_timer);
uint32_t now_ticks = furi_get_tick();
uint32_t timer_expires_at = furi_timer_get_expire_time(dolphin->clear_limits_timer);
if((timer_expires_at - now_ticks) > HOURS_IN_TICKS(0.1)) {
FuriHalRtcDateTime date;
furi_hal_rtc_get_datetime(&date);
TickType_t now_time_in_ms = ((date.hour * 60 + date.minute) * 60 + date.second) * 1000;
TickType_t time_to_clear_limits = 0;
uint32_t now_time_in_ms = ((date.hour * 60 + date.minute) * 60 + date.second) * 1000;
uint32_t time_to_clear_limits = 0;
if(date.hour < 5) {
time_to_clear_limits = HOURS_IN_TICKS(5) - now_time_in_ms;
@@ -146,7 +140,7 @@ static void dolphin_update_clear_limits_timer_period(Dolphin* dolphin) {
time_to_clear_limits = HOURS_IN_TICKS(24 + 5) - now_time_in_ms;
}
xTimerChangePeriod(dolphin->clear_limits_timer, time_to_clear_limits, portMAX_DELAY);
furi_timer_start(dolphin->clear_limits_timer, time_to_clear_limits);
}
}
@@ -162,9 +156,10 @@ int32_t dolphin_srv(void* p) {
furi_record_create(RECORD_DOLPHIN, dolphin);
dolphin_state_load(dolphin->state);
xTimerReset(dolphin->butthurt_timer, portMAX_DELAY);
uint32_t butthurt_interval = xtreme_settings.butthurt_timer * 1000;
if(butthurt_interval) furi_timer_restart(dolphin->butthurt_timer, butthurt_interval);
dolphin_update_clear_limits_timer_period(dolphin);
xTimerReset(dolphin->clear_limits_timer, portMAX_DELAY);
furi_timer_restart(dolphin->clear_limits_timer, HOURS_IN_TICKS(24));
DolphinEvent event;
while(1) {
@@ -174,8 +169,9 @@ int32_t dolphin_srv(void* p) {
dolphin_state_on_deed(dolphin->state, event.deed);
DolphinPubsubEvent event = DolphinPubsubEventUpdate;
furi_pubsub_publish(dolphin->pubsub, &event);
xTimerReset(dolphin->butthurt_timer, portMAX_DELAY);
xTimerReset(dolphin->flush_timer, portMAX_DELAY);
if(butthurt_interval)
furi_timer_restart(dolphin->butthurt_timer, butthurt_interval);
furi_timer_restart(dolphin->flush_timer, 30 * 1000);
} else if(event.type == DolphinEventTypeStats) {
event.stats->icounter = dolphin->state->data.icounter;
event.stats->butthurt = dolphin->state->data.butthurt;

View File

@@ -30,9 +30,9 @@ struct Dolphin {
// Queue
FuriMessageQueue* event_queue;
FuriPubSub* pubsub;
TimerHandle_t butthurt_timer;
TimerHandle_t flush_timer;
TimerHandle_t clear_limits_timer;
FuriTimer* butthurt_timer;
FuriTimer* flush_timer;
FuriTimer* clear_limits_timer;
};
Dolphin* dolphin_alloc();