-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
770 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ | |
"vf-cid": 0, | ||
|
||
// Vereinsflieger article id to use for purchases | ||
"vf-article-id": 0 | ||
"vf-article-id": "1234" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use chrono::{DateTime, TimeDelta, Utc}; | ||
use core::cell::RefCell; | ||
use embassy_sync::blocking_mutex::CriticalSectionMutex; | ||
use log::debug; | ||
|
||
/// Calculated time of system start | ||
static SYSTEM_START_TIME: CriticalSectionMutex<RefCell<Option<DateTime<Utc>>>> = | ||
CriticalSectionMutex::new(RefCell::new(None)); | ||
|
||
/// Time of system start | ||
fn start_time() -> Option<DateTime<Utc>> { | ||
SYSTEM_START_TIME.lock(|sst| *sst.borrow()) | ||
} | ||
|
||
/// Set time of system start | ||
fn set_start_time(time: DateTime<Utc>) { | ||
SYSTEM_START_TIME.lock(|sst| { | ||
*sst.borrow_mut() = Some(time); | ||
}); | ||
} | ||
|
||
/// Duration of system run time | ||
pub fn uptime() -> Option<TimeDelta> { | ||
let millis = esp_hal::time::now().duration_since_epoch().to_millis(); | ||
TimeDelta::try_milliseconds(i64::try_from(millis).ok()?) | ||
} | ||
|
||
/// Current time | ||
pub fn now() -> Option<DateTime<Utc>> { | ||
if let (Some(start_time), Some(uptime)) = (start_time(), uptime()) { | ||
Some(start_time + uptime) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Set current time by using the given current time to calculate the time of system start | ||
pub fn set(now: DateTime<Utc>) { | ||
if let Some(uptime) = uptime() { | ||
set_start_time(now - uptime); | ||
debug!("Time: Current time set to {}", now); | ||
} | ||
} |
Oops, something went wrong.