Library for Modtronix DINS-R8 boards. It is a 8 relay board controlled via I2C or RS-485, and can be mounted on a DIN rail.
dins-r8_i2c.h@2:b72096b1e461, 2015-08-04 (annotated)
- Committer:
- modtronix
- Date:
- Tue Aug 04 18:52:24 2015 +1000
- Revision:
- 2:b72096b1e461
- Child:
- 3:c9412ffaf58e
Added initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
modtronix | 2:b72096b1e461 | 1 | /** |
modtronix | 2:b72096b1e461 | 2 | * File: dins-r8.h |
modtronix | 2:b72096b1e461 | 3 | * |
modtronix | 2:b72096b1e461 | 4 | * Author: Modtronix Engineering - www.modtronix.com |
modtronix | 2:b72096b1e461 | 5 | * |
modtronix | 2:b72096b1e461 | 6 | * Description: |
modtronix | 2:b72096b1e461 | 7 | * |
modtronix | 2:b72096b1e461 | 8 | * Software License Agreement: |
modtronix | 2:b72096b1e461 | 9 | * This software has been written or modified by Modtronix Engineering. The code |
modtronix | 2:b72096b1e461 | 10 | * may be modified and can be used free of charge for commercial and non commercial |
modtronix | 2:b72096b1e461 | 11 | * applications. If this is modified software, any license conditions from original |
modtronix | 2:b72096b1e461 | 12 | * software also apply. Any redistribution must include reference to 'Modtronix |
modtronix | 2:b72096b1e461 | 13 | * Engineering' and web link(www.modtronix.com) in the file header. |
modtronix | 2:b72096b1e461 | 14 | * |
modtronix | 2:b72096b1e461 | 15 | * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, |
modtronix | 2:b72096b1e461 | 16 | * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
modtronix | 2:b72096b1e461 | 17 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE |
modtronix | 2:b72096b1e461 | 18 | * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
modtronix | 2:b72096b1e461 | 19 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
modtronix | 2:b72096b1e461 | 20 | */ |
modtronix | 2:b72096b1e461 | 21 | |
modtronix | 2:b72096b1e461 | 22 | #ifndef MODTRONIX_DINS_R8_I2C_H_ |
modtronix | 2:b72096b1e461 | 23 | #define MODTRONIX_DINS_R8_I2C_H_ |
modtronix | 2:b72096b1e461 | 24 | |
modtronix | 2:b72096b1e461 | 25 | #include "mbed.h" |
modtronix | 2:b72096b1e461 | 26 | |
modtronix | 2:b72096b1e461 | 27 | |
modtronix | 2:b72096b1e461 | 28 | //Error Numbers |
modtronix | 2:b72096b1e461 | 29 | #define DINS_R8_SUCCESS 0 //Success |
modtronix | 2:b72096b1e461 | 30 | #define DINS_R8_ERR_I2C 0xff //I2C Error |
modtronix | 2:b72096b1e461 | 31 | #define DINS_R8_ERR_INVALID_RELAY 0xfe //Invalid Relay number |
modtronix | 2:b72096b1e461 | 32 | |
modtronix | 2:b72096b1e461 | 33 | class DINS_R8_I2C { |
modtronix | 2:b72096b1e461 | 34 | public: |
modtronix | 2:b72096b1e461 | 35 | DINS_R8_I2C(I2C* i2cBus); |
modtronix | 2:b72096b1e461 | 36 | |
modtronix | 2:b72096b1e461 | 37 | /** Writes given relay with given value |
modtronix | 2:b72096b1e461 | 38 | * |
modtronix | 2:b72096b1e461 | 39 | * @param relayNumber Relay to update, number from 1 to 8 |
modtronix | 2:b72096b1e461 | 40 | * |
modtronix | 2:b72096b1e461 | 41 | * @param value New value, 0 if off, 1 is on |
modtronix | 2:b72096b1e461 | 42 | * |
modtronix | 2:b72096b1e461 | 43 | * @returns 0 if success, else error code |
modtronix | 2:b72096b1e461 | 44 | */ |
modtronix | 2:b72096b1e461 | 45 | uint8_t writeRelay(int8_t relayNumber, bool value); |
modtronix | 2:b72096b1e461 | 46 | |
modtronix | 2:b72096b1e461 | 47 | /** Set all relays with new values. Each bit is 1 relay |
modtronix | 2:b72096b1e461 | 48 | * |
modtronix | 2:b72096b1e461 | 49 | * @param relays New values for relays, each bit is 1 relay |
modtronix | 2:b72096b1e461 | 50 | * |
modtronix | 2:b72096b1e461 | 51 | * @returns 0 if success, else error code |
modtronix | 2:b72096b1e461 | 52 | */ |
modtronix | 2:b72096b1e461 | 53 | uint8_t writeAllRelays(int8_t relays); |
modtronix | 2:b72096b1e461 | 54 | |
modtronix | 2:b72096b1e461 | 55 | /** Get current I2C address. Default address is 0x60 |
modtronix | 2:b72096b1e461 | 56 | */ |
modtronix | 2:b72096b1e461 | 57 | uint8_t getAddress() const { |
modtronix | 2:b72096b1e461 | 58 | return i2cAdr; |
modtronix | 2:b72096b1e461 | 59 | } |
modtronix | 2:b72096b1e461 | 60 | |
modtronix | 2:b72096b1e461 | 61 | /** Set current I2C address. Default address is 0x60 |
modtronix | 2:b72096b1e461 | 62 | */ |
modtronix | 2:b72096b1e461 | 63 | void setAddress(uint8_t i2cAdr) { |
modtronix | 2:b72096b1e461 | 64 | this->i2cAdr = i2cAdr; |
modtronix | 2:b72096b1e461 | 65 | } |
modtronix | 2:b72096b1e461 | 66 | |
modtronix | 2:b72096b1e461 | 67 | /** Get value of all relays. Each bit is 1 relay |
modtronix | 2:b72096b1e461 | 68 | */ |
modtronix | 2:b72096b1e461 | 69 | uint8_t getRelays() const { |
modtronix | 2:b72096b1e461 | 70 | return relays; |
modtronix | 2:b72096b1e461 | 71 | } |
modtronix | 2:b72096b1e461 | 72 | |
modtronix | 2:b72096b1e461 | 73 | |
modtronix | 2:b72096b1e461 | 74 | protected: |
modtronix | 2:b72096b1e461 | 75 | uint8_t relays; //Value of all relays |
modtronix | 2:b72096b1e461 | 76 | I2C* pI2C; |
modtronix | 2:b72096b1e461 | 77 | uint8_t i2cAdr; |
modtronix | 2:b72096b1e461 | 78 | }; |
modtronix | 2:b72096b1e461 | 79 | |
modtronix | 2:b72096b1e461 | 80 | |
modtronix | 2:b72096b1e461 | 81 | |
modtronix | 2:b72096b1e461 | 82 | #endif /* MODTRONIX_DINS_R8_I2C_H_ */ |