This repository has been archived by the owner on Nov 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from leinardi/ds3231
Added DS3231 driver
- Loading branch information
Showing
38 changed files
with
2,220 additions
and
5 deletions.
There are no files selected for viewing
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 @@ | ||
/build |
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,5 @@ | ||
# Change Log | ||
|
||
## [0.1] - 2018-01-09 | ||
- initial version | ||
|
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,58 @@ | ||
# DS3231 automatic system wall clock time backup and restore for Android Things | ||
|
||
[![Maven metadata URI](https://img.shields.io/maven-metadata/v/http/jcenter.bintray.com/com/leinardi/android/things/driver-ds3231-receiver/maven-metadata.xml.svg?style=plastic)](https://jcenter.bintray.com/com/leinardi/android/things/driver-ds3231-receiver/maven-metadata.xml) | ||
[![Build Status](https://img.shields.io/travis/leinardi/androidthings-drivers/master.svg?style=plastic)](https://travis-ci.org/leinardi/androidthings-drivers) | ||
[![GitHub license](https://img.shields.io/github/license/leinardi/androidthings-drivers.svg?style=plastic)](https://github.com/leinardi/androidthings-drivers/blob/master/LICENSE) | ||
|
||
This library automatically persist on reboot/poweroff the system wall clock time, | ||
using the DS3231 driver, without the need of any code change. | ||
|
||
NOTE: these drivers are not production-ready. They are offered as sample | ||
implementations of Android Things user space drivers for common peripherals | ||
as part of the Developer Preview release. There is no guarantee | ||
of correctness, completeness or robustness. | ||
|
||
This driver is based on the [jpuderer-things-drivers driver from jpuderer](https://github.com/jpuderer/jpuderer-things-drivers) | ||
|
||
## How to use the driver | ||
|
||
### Gradle dependency | ||
If you are just interested in persisting the system wall clock time when you reboot or | ||
power off your device, simply add the line below to your project's `build.gradle`, | ||
where `<version>` matches the last version of the driver available on [jcenter][jcenter]. | ||
No additional code changes are required. | ||
``` | ||
dependencies { | ||
implementation 'com.leinardi.android.things:driver-ds3231-receiver:<version>' | ||
} | ||
``` | ||
|
||
### Specify the I2C port name | ||
The I2C port name is automatically detected for any officially supported Android Things board. | ||
You can manually specify the port name by adding the following meta-data tag in your | ||
application manifest, where the value corresponds to the I2C bus the RTC module is attached to: | ||
|
||
```xml | ||
<meta-data android:name="ds3231_i2c_port" android:value="I2C1" /> | ||
``` | ||
|
||
## License | ||
|
||
Copyright 2018 Roberto Leinardi | ||
|
||
Licensed to the Apache Software Foundation (ASF) under one or more contributor | ||
license agreements. See the NOTICE file distributed with this work for | ||
additional information regarding copyright ownership. The ASF licenses this | ||
file to you under the Apache License, Version 2.0 (the "License"); you may not | ||
use this file except in compliance with the License. You may obtain a copy of | ||
the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
License for the specific language governing permissions and limitations under | ||
the License. | ||
|
||
[jcenter]: https://bintray.com/leinardi/androidthings/driver-ds3231-receiver/_latestVersion |
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,52 @@ | ||
/* | ||
* Copyright 2018 Roberto Leinardi. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
apply plugin: 'com.android.library' | ||
apply from: rootProject.file('checkstyle.gradle') | ||
|
||
android { | ||
compileSdkVersion build_versions.target_sdk | ||
buildToolsVersion build_versions.build_tools | ||
|
||
apply from: 'mavenConfig.gradle' | ||
|
||
defaultConfig { | ||
minSdkVersion build_versions.min_sdk | ||
targetSdkVersion build_versions.target_sdk | ||
versionCode build_versions.version_code | ||
versionName mvn_config.version as String | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility build_versions.java_version | ||
targetCompatibility build_versions.java_version | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
compileOnly deps.androidthings | ||
implementation deps.support.annotations | ||
implementation 'com.leinardi.android.things:driver-ds3231:0.1' | ||
} |
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,36 @@ | ||
/* | ||
* Copyright 2018 Roberto Leinardi. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
def mvn_config = [:] | ||
mvn_config.repository = 'androidthings' | ||
mvn_config.group_id = 'com.leinardi.android.things' | ||
mvn_config.artifact_id = 'driver-ds3231-receiver' | ||
mvn_config.version = '0.1' | ||
mvn_config.licenses = 'Apache-2.0' // Comma separated | ||
mvn_config.website = 'https://github.com/leinardi/androidthings-drivers' | ||
mvn_config.issue_tracker_url = 'https://github.com/leinardi/androidthings-drivers/issues' | ||
mvn_config.vcs_url = 'https://github.com/leinardi/androidthings-drivers.git' | ||
mvn_config.description = 'DS3231 boot completed and time set receiver for Android Things' | ||
mvn_config.tags = 'ds3231,android-things,android,raspberry-pi' // Comma separated | ||
mvn_config.inception_year = '2018' | ||
mvn_config.dryRun = false | ||
mvn_config.publish = false | ||
mvn_config.override = true | ||
|
||
ext.mvn_config = mvn_config | ||
|
||
apply from: rootProject.file('maven.gradle') | ||
apply from: rootProject.file('bintray.gradle') |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,38 @@ | ||
<!-- | ||
~ Copyright 2018 Roberto Leinardi. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<manifest package="com.leinardi.android.things.driver.ds3231.receiver" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | ||
<uses-permission android:name="com.google.android.things.permission.CHANGE_TIME" /> | ||
|
||
<application> | ||
<uses-library | ||
android:name="com.google.android.things" | ||
android:required="false" /> | ||
<receiver | ||
android:name=".Ds3231Receiver"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.BOOT_COMPLETED" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
</intent-filter> | ||
<intent-filter> | ||
<action android:name="android.intent.action.TIME_SET" /> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
</manifest> |
48 changes: 48 additions & 0 deletions
48
...eiver/src/main/java/com/leinardi/android/things/driver/ds3231/receiver/BoardDefaults.java
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,48 @@ | ||
/* | ||
* Copyright 2018 Roberto Leinardi. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.leinardi.android.things.driver.ds3231.receiver; | ||
|
||
import android.os.Build; | ||
import android.util.Log; | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public class BoardDefaults { | ||
private static final String TAG = BoardDefaults.class.getSimpleName(); | ||
private static final String DEVICE_RPI3 = "rpi3"; | ||
private static final String DEVICE_IMX6UL_PICO = "imx6ul_pico"; | ||
private static final String DEVICE_IMX7D_PICO = "imx7d_pico"; | ||
|
||
private BoardDefaults() { | ||
} | ||
|
||
/** | ||
* Return the preferred I2C port for each board. | ||
*/ | ||
public static String getI2CPort() { | ||
switch (Build.DEVICE) { | ||
case DEVICE_RPI3: | ||
return "I2C1"; | ||
case DEVICE_IMX6UL_PICO: | ||
return "I2C2"; | ||
case DEVICE_IMX7D_PICO: | ||
return "I2C1"; | ||
default: | ||
Log.w(TAG, "Unknown Build.DEVICE " + Build.DEVICE); | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.