Skip to content

Commit

Permalink
Cleanup for initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch452 committed Jun 5, 2018
1 parent a29546d commit 23dd11a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.0] - 2018-06-04

Initial Release of the MMM-LocalTemperature module.

## [0.2.0] - 2018-05-27

Pre-Release of the MMM-LocalTemperature module for testing purposes.
Expand Down
17 changes: 14 additions & 3 deletions MMM-LocalTemperature.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
/**
* MMM-LocalTemperature
*
/**
* Magic Mirror
* Module Style Sheet: MMM-LocalTemperature
*
* By David Dearden
* MIT Licensed.
*/

/**
* Font configurations
*/
.MMM-LocalTemperature .x-small { font-size: 15px; line-height: 20px; }
.MMM-LocalTemperature .small { font-size: 20px; line-height: 25px; }
.MMM-LocalTemperature .medium { font-size: 30px; line-height: 35px; }
.MMM-LocalTemperature .large { font-size: 65px; line-height: 65px; }
.MMM-LocalTemperature .x-large { font-size: 75px; line-height: 75px; letter-spacing: -3px; }

/**
* Loading text
Expand Down
67 changes: 35 additions & 32 deletions MMM-LocalTemperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ Module.register("MMM-LocalTemperature", {
*/
defaults: {
sensorPin: null,
pinScheme: "BCM",
pinScheme: "BCMv2",
units: config.units,
sendTemperature: true,
sendHumidity: true,
showTemperature: false,
showHumidity: false,
temperatureText: null, // Set in self.start() becuase access to self.translate is needed
humidityText: null, // Set in self.start() becuase access to self.translate is needed
fontSize: "medium",
decimalSymbol: null, // Set in self.start() becuase access to self.translate is needed
roundTemperature: false,
roundHumidity: false,
Expand All @@ -34,7 +35,7 @@ Module.register("MMM-LocalTemperature", {
animationSpeed: 0, // Milliseconds, minimum 0
retryDelay: 10, // Seconds, minimum 10
updateInterval: 5, // Minutes, minimum 0.5
developerMode: false,
developerMode: false
},

/**
Expand All @@ -58,36 +59,37 @@ Module.register("MMM-LocalTemperature", {
self.maxDataAttempts = 3;
self.validUnits = [ "metric", "imperial", "default" ];
var unitMap = { "metric": "celcius", "imperial": "fahrenheit", "default": "kelvin" };
self.validPinSchemes = [ "BOARD", "BCM", "WPI" ];
self.validPinSchemes = [ "BOARD", "BCMv1", "BCMv2", "WPI" ];
self.validFontSizes = [ "x-small", "small", "medium", "large", "x-large" ];
self.currentweatherLoaded = false;

var pinMapping = [
{ "BOARD": 3, "BCM": 2, "WPI": 8 },
{ "BOARD": 5, "BCM": 3, "WPI": 9 },
{ "BOARD": 7, "BCM": 4, "WPI": 7 },
{ "BOARD": 8, "BCM": 14, "WPI": 15 },
{ "BOARD": 10, "BCM": 15, "WPI": 16 },
{ "BOARD": 11, "BCM": 17, "WPI": 0 },
{ "BOARD": 12, "BCM": 18, "WPI": 1 },
{ "BOARD": 13, "BCM": 27, "WPI": 2 },
{ "BOARD": 15, "BCM": 22, "WPI": 3 },
{ "BOARD": 16, "BCM": 23, "WPI": 4 },
{ "BOARD": 18, "BCM": 24, "WPI": 5 },
{ "BOARD": 19, "BCM": 10, "WPI": 12 },
{ "BOARD": 21, "BCM": 9, "WPI": 13 },
{ "BOARD": 22, "BCM": 25, "WPI": 6 },
{ "BOARD": 23, "BCM": 11, "WPI": 14 },
{ "BOARD": 24, "BCM": 8, "WPI": 10 },
{ "BOARD": 26, "BCM": 7, "WPI": 11 },
{ "BOARD": 29, "BCM": 5, "WPI": 21 },
{ "BOARD": 31, "BCM": 6, "WPI": 22 },
{ "BOARD": 32, "BCM": 12, "WPI": 26 },
{ "BOARD": 33, "BCM": 13, "WPI": 23 },
{ "BOARD": 35, "BCM": 19, "WPI": 24 },
{ "BOARD": 36, "BCM": 16, "WPI": 27 },
{ "BOARD": 37, "BCM": 26, "WPI": 25 },
{ "BOARD": 38, "BCM": 20, "WPI": 28 },
{ "BOARD": 40, "BCM": 21, "WPI": 29 },
{ "BOARD": 10, "BCMv1": 15, "BCMv2": 15, "WPI": 16 },
{ "BOARD": 11, "BCMv1": 17, "BCMv2": 17, "WPI": 0 },
{ "BOARD": 12, "BCMv1": 18, "BCMv2": 18, "WPI": 1 },
{ "BOARD": 13, "BCMv1": 21, "BCMv2": 27, "WPI": 2 },
{ "BOARD": 15, "BCMv1": 22, "BCMv2": 22, "WPI": 3 },
{ "BOARD": 16, "BCMv1": 23, "BCMv2": 23, "WPI": 4 },
{ "BOARD": 18, "BCMv1": 24, "BCMv2": 24, "WPI": 5 },
{ "BOARD": 19, "BCMv1": 10, "BCMv2": 10, "WPI": 12 },
{ "BOARD": 21, "BCMv1": 9, "BCMv2": 9, "WPI": 13 },
{ "BOARD": 22, "BCMv1": 25, "BCMv2": 25, "WPI": 6 },
{ "BOARD": 23, "BCMv1": 11, "BCMv2": 11, "WPI": 14 },
{ "BOARD": 24, "BCMv1": 8, "BCMv2": 8, "WPI": 10 },
{ "BOARD": 26, "BCMv1": 7, "BCMv2": 7, "WPI": 11 },
{ "BOARD": 29, "BCMv1": null, "BCMv2": 5, "WPI": 21 },
{ "BOARD": 3, "BCMv1": 0, "BCMv2": 2, "WPI": 8 },
{ "BOARD": 31, "BCMv1": null, "BCMv2": 6, "WPI": 22 },
{ "BOARD": 32, "BCMv1": null, "BCMv2": 12, "WPI": 26 },
{ "BOARD": 33, "BCMv1": null, "BCMv2": 13, "WPI": 23 },
{ "BOARD": 35, "BCMv1": null, "BCMv2": 19, "WPI": 24 },
{ "BOARD": 36, "BCMv1": null, "BCMv2": 16, "WPI": 27 },
{ "BOARD": 37, "BCMv1": null, "BCMv2": 26, "WPI": 25 },
{ "BOARD": 38, "BCMv1": null, "BCMv2": 20, "WPI": 28 },
{ "BOARD": 40, "BCMv1": null, "BCMv2": 21, "WPI": 29 },
{ "BOARD": 5, "BCMv1": 1, "BCMv2": 3, "WPI": 9 },
{ "BOARD": 7, "BCMv1": 4, "BCMv2": 4, "WPI": 7 },
{ "BOARD": 8, "BCMv1": 14, "BCMv2": 14, "WPI": 15 }
];

// Process and validate configuration options
Expand Down Expand Up @@ -118,6 +120,7 @@ Module.register("MMM-LocalTemperature", {
if (!axis.isBoolean(self.config.roundTemperature)) { self.config.roundTemperature = self.defaults.roundTemperature; }
if (!axis.isBoolean(self.config.roundHumidity)) { self.config.roundHumidity = self.defaults.roundHumidity; }
if (!axis.isString(self.config.decimalSymbol)) { self.config.decimalSymbol = self.defaults.decimalSymbol; }
if (!self.validFontSizes.includes(self.config.fontSize)) { self.config.fontSize = self.defaults.fontSize; }

// Validate the provided sensorPin
var pinObj = pinMapping.find(function(val) { return val[this.scheme] === this.pin; }, { scheme: self.config.pinScheme, pin: self.config.sensorPin });
Expand Down Expand Up @@ -292,7 +295,6 @@ Module.register("MMM-LocalTemperature", {
var self = this;
var dataContainer;
var wrapper = document.createElement("div");
wrapper.classList.add("small");

if (self.config.showTemperature || self.config.showHumidity) {

Expand All @@ -303,6 +305,7 @@ Module.register("MMM-LocalTemperature", {
return wrapper;
}

wrapper.classList.add(self.config.fontSize);
var temperatureDecimals = self.config.roundTemperature ? 0 : 1;
var temperatureValue = self.roundNumber(self.sensorData[self.tempUnit], temperatureDecimals).toFixed(temperatureDecimals);
temperatureValue = self.replaceAll(temperatureValue.toString(), ".", self.config.decimalSymbol);
Expand Down Expand Up @@ -386,7 +389,7 @@ Module.register("MMM-LocalTemperature", {
getStyles: function () {
return [
"MMM-LocalTemperature.css",
"font-awesome.css",
"font-awesome.css"
];
},

Expand All @@ -396,7 +399,7 @@ Module.register("MMM-LocalTemperature", {
*/
getTranslations: function() {
return {
en: "translations/en.json",
en: "translations/en.json"
};
},

Expand Down
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ This module reads and displays temperature and humidity information from a senso

| Status | Version | Date | Maintained? | Minimum MagicMirror² Version |
|:------- |:------- |:---------- |:----------- |:---------------------------- |
| Beta Testing | `0.2.0` | 2018-05-27 | Yes |`2.2.1` |
| Working | `1.0.0` | 2018-06-04 | Yes |`2.2.1` |

### Example
![Example of MMM-LocalTemperature](images/sample.png?raw=true "Example screenshot")

### Notable Features
1. Get data from a DHT11, DHT22, or AM2302 sensor (The DHT11 sensor is untested as I don't have one to test with)
1. Get data from a DHT11, DHT22, or AM2302 sensor
2. Display the temperature and/or humidity from this module and/or,
3. Send the temperature and/or humidity to the built in 'currentweather' module via notifications
3. Send the temperature and/or humidity to the built in 'currentweather' module via module notifications

### Dependencies
1. A local 'c' program to read the data from the sensor (included)
Expand Down Expand Up @@ -55,15 +55,16 @@ var config = {

| Option | Details
|:----------------------- |:-------------
| `sensorPin` | **REQUIRED** - The GPIO Pin number that is connected to the data pin on the sensor. The default pin scheme is the standard Raspberry Pi (BCM) GPIO numbering system. See the `pinScheme` option for other numbering systems.<br />**Type:** `number`<br />**Default:** `N/A`<br />
| `pinScheme` | *Optional* - The pin numbering system to use for the `sensorPin` option. See this [interactive pinout diagram](https://pinout.xyz) for more details on pin usage for the Raspberry Pi. <br />Note: Ultimately the `sensorPin` value will be converted to the WiringPi system, becuase that is the library used by the `DHT` program to interact with the pin. However, any of these numbering systems can be used, since this module will convert the `sensorPin` value automatically based on the selected scheme. <br />**Type:** `string`<br />**Default:** `"BCM"`<br />**Options:**<br />- `"BCM"` The standard Raspberry Pi GPIO numbering system<br />- `"BOARD"` The physical pin numbering on the GPIO header<br />- `"WPI"` The WiringPi numbering system
| `sensorPin` | **REQUIRED** - The GPIO Pin number that is connected to the data pin on the sensor. The default pin scheme is the standard Raspberry Pi (BCM) GPIO numbering system for Rev 2 Pi's. See the `pinScheme` option for other numbering systems.<br />**Type:** `number`<br />
| `pinScheme` | *Optional* - The pin numbering system to use for the `sensorPin` option. See this [interactive pinout diagram](https://pinout.xyz) for more details on pin usage for the Raspberry Pi. <br />Note: Ultimately the `sensorPin` value will be converted to the WiringPi system, becuase that is the library used by the `DHT` program to interact with the pin. However, any of these numbering systems can be used, since this module will convert the `sensorPin` value automatically based on the selected scheme. <br />**Type:** `string`<br />**Default:** `"BCMv2"`<br />**Options:**<br />- `"BCMv2"` The standard Raspberry Pi GPIO numbering system on current (Rev 2) boards<br />- `"BCMv1"` The standard Raspberry Pi GPIO numbering system on older (Rev 1) boards<br />- `"BOARD"` The physical pin numbering on the GPIO header<br />- `"WPI"` The WiringPi numbering system
| `units` | *Optional* - The unit system to use for the temperature value. (`"metric"` = Celcius, `"imperial"` = Fahrenheit, `"default"` = Kelvin)<br />**Type:** `string`<br />**Default:** `config.units`<br />**Options:** `"metric"`, `"imperial"`, `"default"`
| `sendTemperature` | *Optional* - When `true`, an "INDOOR_TEMPERATURE" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor temperature within the built-in 'currentweather' module.<br />**Type:** `boolean`<br />**Default:** `true`
| `sendHumidity` | *Optional* - When `true`, an "INDOOR_HUMIDITY" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor humidity within the built-in 'currentweather' module.<br />**Type:** `boolean`<br />**Default:** `true`
| `sendTemperature` | *Optional* - When `true`, an "INDOOR_TEMPERATURE" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor temperature within the built-in 'currentweather' module. The 'currentweather' module's `showIndoorTemperature` option must be set to `true` for it to display the data sent from this module.<br />**Type:** `boolean`<br />**Default:** `true`
| `sendHumidity` | *Optional* - When `true`, an "INDOOR_HUMIDITY" notification is sent to the other modules when the data is received from the sensor. This can be used to display the indoor humidity within the built-in 'currentweather' module. The 'currentweather' module's `showIndoorHumidity` option must be set to `true` for it to display the data sent from this module.<br />**Type:** `boolean`<br />**Default:** `true`
| `showTemperature` | *Optional* - When `true`, the module will display the temperature on screen.<br />**Type:** `boolean`<br />**Default:** `false`
| `showHumidity` | *Optional* - When `true`, the module will display the humidity on screen.<br />**Type:** `boolean`<br />**Default:** `false`
| `temperatureText` | *Optional* - The text template to be used when displaying the temperature data. The stings `"{temperature}"` and `"{humidity}"` will be replaced with the temperature and humidity values respectively. <br />**Type:** `string`<br />**Default:** `"Temperature: {temperature}°C/°F/K"`
| `humidityText` | *Optional* - The text template to be used when displaying the humidity data. The stings `"{temperature}"` and `"{humidity}"` will be replaced with the temperature and humidity values respectively. <br />**Type:** `string`<br />**Default:** `"Humidity: {humidity}%"`
| `fontSize` | *Optional* - The main font size to use for the module text. <br />**Type:** `string`<br />**Default:** `'medium'`<br />**Options:** `'x-small'`, `'small'`, `'medium'`, `'large'`, `'x-large'`
| `decimalSymbol` | *Optional* - The character to use as the decimal symbol. <br />**Type:** `string`<br />**Default:** `"."`
| `roundTemperature` | *Optional* - When true, the temperature value will be rounded to the nearest integer. <br />**Type:** `boolean`<br />**Default:** `false`
| `roundHumidity` | *Optional* - When true, the humidity value will be rounded to the nearest integer. <br />**Type:** `boolean`<br />**Default:** `false`
Expand All @@ -75,7 +76,7 @@ var config = {

## Connecting the Sensor to the Raspberry Pi

Here are some diagrams that you may find useful when connecting your sensor. See the [adafruit.com guide](docs/adafruit-dht-sensor-guide.pdf?raw=true) for more wiring and programming information.
Here are some diagrams that you may find useful when connecting your sensor. See the [guide from adafruit.com](docs/adafruit-dht-sensor-guide.pdf?raw=true) for more wiring and programming information.

### DHT11 sensor
![Example of a DHT11 sensor with a Raspberry Pi](images/wiring_dht11.png?raw=true "How to connect a DHT11 sensor to a Raspberry Pi")
Expand Down Expand Up @@ -123,10 +124,4 @@ conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.**

0 comments on commit 23dd11a

Please sign in to comment.