Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mongoose-os-libs/ds3231
https://github.com/mongoose-os-libs/ds3231
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mongoose-os-libs/ds3231
- Owner: mongoose-os-libs
- License: other
- Created: 2018-06-14T12:29:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T00:17:13.000Z (almost 3 years ago)
- Last Synced: 2024-07-31T21:52:49.577Z (4 months ago)
- Language: C
- Size: 17.6 KB
- Stars: 3
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mongoose-os - ds3231
README
# A native Mongoose OS DS3231 RTC library
## Implementation
The library implements 2 structures: `struct mgos_ds3231` and a helper `struct mgos_ds3231_date_time`.
Both structures are available for mJS too. The mJS support is available if the user includes the mjs library:
```
- origin: https://github.com/mongoose-os-libs/mjs
```### struct mgos_ds3231
This is used to communicate with the DS3231.
The RTC data is read into and written from using the helper `struct mgos_ds3231_date_time`#### Example in C
```c
struct mgos_ds3231* ds=mgos_ds3231_create(addr);
time_t unixtime=time(NULL);
mgos_ds3231_write_unixtime(ds, unixtime);
mgos_ds3231_free(ds);
```#### Example in mJS
```javascript
let ds=DS3231.create(addr);
let unixtime=Timer.now();
ds.writeUnixtime(unixtime);
ds.free();
```### struct mgos_ds3231_date_time
Encapsulates the DS3231 date/time information plus the unix timestamp.
Several functions are provided to create and free the structure and to get/set different fields.#### Example in C
```c
struct mgos_ds3231_date_time* dt=mgos_ds3231_date_time_create();
mgos_ds3231_date_time_set_date(dt, 2016, 2, 3);
// mgos_ds3231_date_time_set_time will calculate the unixtime.
// It is VERY important to call mgos_ds3231_date_time_set_date first
mgos_ds3231_date_time_set_time(dt, 12, 34, 56);struct mgos_ds3231* ds=mgos_ds3231_create(addr);
mgos_ds3231_write(ds, dt);
mgos_ds3231_settimeofday(ds);mgos_ds3231_free(ds);
mgos_ds3231_date_time_free(dt);
```#### Example in mJS
```javascript
let dt=DS3231DateTime.create();
dt.setDate(2016, 2, 3);
dt.setTime(12, 34, 56);let ds=DS3231.create(addr);
ds.write(dt);
ds.setTimeOfDay();ds.free();
dt.free();
```