Skip to content

Allow use IO Expanders - 74HC595 FIXED #3 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: esp8266
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified README.adoc
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions dependencies.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
//#include <MFRC522.h> // RFID
// #include <RCSwitch.h> // RF 433Mhz
// #include <ESP8266AT.h> // ESP8266 - AT Firmwware
#include <ESP8266WiFi.h> // ESP8266 - Standalone

//#include <ESP8266WiFi.h> // ESP8266 - Standalone
//#include <PubSubClient.h> // Enable MQTT

//#if defined(EnableInterrupt_h)
//#define EI_ARDUINO_INTERRUPTED_PIN
Expand Down
4 changes: 2 additions & 2 deletions examples/BluetoothConnection/BluetoothConnection.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

void setup(){
ODev.enableDebug();
ODev.addDevice(13, Device::DIGITAL); // ID:1
ODev.addDevice("LED", 13, Device::DIGITAL); // ID:1
// ODev.begin(); // UNO
ODev.begin(Serial1, 9600); //-- for Leonardo, Teensy (Rx:0,Tx:1)
}

void loop(){
ODev.loop();
}
}
2 changes: 1 addition & 1 deletion examples/BluetoothConnectionSoft/BluetoothConnectionSoft.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SoftwareSerial mySerial(2, 5); // RX, TX

void setup(){
// ODev.enableDebug();
ODev.addDevice(13, Device::DIGITAL); // ID:1
ODev.addDevice("LED", 13, Device::DIGITAL); // ID:1

mySerial.begin(9600);
ODev.begin(mySerial);
Expand Down
27 changes: 27 additions & 0 deletions examples/Controller595/Controller595.ino/Controller595.ino.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* *****************************************************************************
* See tutorial: https://opendevice.atlassian.net/wiki/display/DOC/A.+First+Steps+with+ODev
* This example code is in the public domain.
* *****************************************************************************
*/
#include <OpenDevice.h>
#include <devices/Controller595.h>

Controller595 control(8,12,11,3);
LogicalDevice led(1);
LogicalDevice led1(9);
LogicalDevice led2(22);

void setup(){
control.begin();
ODev.enableDebug();
ODev.addDevice(led); // ID:1
ODev.addDevice(led1); // ID:2
ODev.addDevice(led2); // ID:3
ODev.begin(); // by default call Serial.begin() and while(!Serial) on Leonardo
}

void loop(){
ODev.loop();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* *****************************************************************************
* See tutorial: https://opendevice.atlassian.net/wiki/display/DOC/A.+First+Steps+with+ODev
* This example code is in the public domain.
* *****************************************************************************
*/
#include <OpenDevice.h>
#include <devices/Controller595.h>

Controller595 control(8,12,11,3);
LogicalDevice led(1);
LogicalDevice led1(9);
LogicalDevice led2(22);

void setup(){
control.begin();
ODev.enableDebug();
ODev.addDevice(led); // ID:1
ODev.addDevice(led1); // ID:2
ODev.addDevice(led2); // ID:3
ODev.begin(); // by default call Serial.begin() and while(!Serial) on Leonardo
}

void loop(){
ODev.loop();
}

Empty file modified examples/CustomSensor/CustomSensor.ino
100644 → 100755
Empty file.
Empty file.
35 changes: 7 additions & 28 deletions examples/ESP8266WiFi/ESP8266WiFi.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* The Open Device will create a TCP server on the default port and a softAP using ODev.name("...").
*
*
* Links:
* - Tutorial: https://opendevice.atlassian.net/wiki/display/DOC/WiFi+using+ESP8266
* - https://github.com/esp8266/arduino
Expand All @@ -13,48 +14,26 @@
*/


//#include <ESP8266AT.h> // to: AT Firmware
#include <ESP8266WiFi.h> // Enable ESP8266 Embedded
// #include <PubSubClient.h> // Enable + MQTT

#include <OpenDevice.h>
#include <utility/Timeout.h>

const char* ssid = "OpenWrt";
const char* password = "";
const char* ssid = "--";
const char* password = "--";

void setup() {
ODev.name("ODev-Thing1");
ODev.enableKeepAlive(false);
// Config.server = "192.168.3.105"; // Only for MQTT
ODev.enableDebug();

ODev.addDevice(2, Device::DIGITAL);
ODev.addDevice("LED", 2, Device::DIGITAL);

// WiFi.init(new ESP8266(Serial1, 115200)); // to: AT Firmware
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
ODev.begin(WiFi);
}

void loop() {

// Send using console
if(Serial.available()){
readAndSendAT();
}

ODev.loop();
}

// Optional - Only for debug purpose
void readAndSendAT(){
#ifdef Serial1
while(Serial.available() > 0){
Serial1.write(Serial.read());
}

// wait for response
String rec = WiFi.ESP->recvString("OK", "ERROR", 10000);
Serial.print(rec);
#endif
}


Empty file modified examples/ESP8266WiFi_AT/ESP8266WiFi_AT.ino
100644 → 100755
Empty file.
Empty file modified examples/EnergiaLaunchPadBasic/EnergiaLaunchPadBasic.ino
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/EthernetConnection/EthernetConnection.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void setup(){
// ODev.ip(192,168,3,106);

ODev.enableDebug();
ODev.addDevice(13, Device::DIGITAL);
ODev.addDevice("LED", 13, Device::DIGITAL);
ODev.addCommand("mycmd1", ledON);
ODev.addCommand("mycmd2", ledOFF);
ODev.begin();
Expand Down
2 changes: 1 addition & 1 deletion examples/EthernetCustomCommands/EthernetCustomCommands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void setup(){
#endif

ODev.enableDebug();
ODev.addDevice(13, Device::DIGITAL);
ODev.addDevice("LED", 13, Device::DIGITAL);
ODev.addCommand("mycmd1", ledON);
ODev.addCommand("mycmd2", ledOFF);
ODev.begin();
Expand Down
23 changes: 23 additions & 0 deletions examples/Expander595/Expander595.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* *****************************************************************************
* See tutorial: https://opendevice.atlassian.net/wiki/display/DOC/A.+First+Steps+with+ODev
* This example code is in the public domain.
* *****************************************************************************
*/
#include <OpenDevice.h>
#include <devices/Expander595.h>

void setup(){
ODev.enableDebug();
ODev.setIoExpander(new Expander595(8,12,11,3));
ODev.addLogical("led",1); // ID:1
ODev.addLogical("led1",2); // ID:2
ODev.addLogical("led2",22); // ID:3
ODev.addLogical("led2",24); // ID:3
ODev.begin(); // by default call Serial.begin() and while(!Serial) on Leonardo
}

void loop(){
ODev.loop();
}

22 changes: 22 additions & 0 deletions examples/Expander595/Expander595.ino~
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* *****************************************************************************
* See tutorial: https://opendevice.atlassian.net/wiki/display/DOC/Port+Expanders
* This example code is in the public domain.
* *****************************************************************************
*/
#include <OpenDevice.h>
#include <devices/Expander595.h>

void setup(){
ODev.enableDebug();
ODev.setIoExpander(new Expander595(8,12,11,2));//pin load, pin clock, pin data, lenght of chip
ODev.addLogical("led 0",1); // ID:1 chip:1 Q0
ODev.addLogical("led 1",2); // ID:2 chip:1 Q1
ODev.addLogical("led 2",15); // ID:3 chip:2 Q6
ODev.begin(); // by default call Serial.begin() and while(!Serial) on Leonardo
}

void loop(){
ODev.loop();
}

Empty file modified examples/RF433Sensor/RF433Sensor.ino
100644 → 100755
Empty file.
Empty file modified examples/RFIDSensor/RFIDSensor.ino
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/UsbConnection/UsbConnection.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

void setup(){
ODev.enableDebug();
ODev.addDevice(13, Device::DIGITAL); // ID:1
ODev.addDevice("LED", 13, Device::DIGITAL); // ID:1
ODev.begin(); // by default call Serial.begin() and while(!Serial) on Leonardo
}

Expand Down
Empty file modified examples/UserCommands/UserCommands.ino
100644 → 100755
Empty file.
20 changes: 20 additions & 0 deletions src/AbstractExpander.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Controller595.h - Library for expansão de portas.
Created by Douglas B., Julho 2, 2016.
Released into the public domain.
*/

#ifndef AbstractExpander_h
#define AbstractExpander_h

class AbstractExpander{
public:
virtual void begin();
virtual void digitalWrite(int indice,byte value);
protected:
int _chips;
byte *_portas;
virtual void syncData();
};

#endif
Empty file modified src/BaseWifiConnection.cpp
100644 → 100755
Empty file.
6 changes: 3 additions & 3 deletions src/BaseWifiConnection.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
using namespace od;


#if !defined(WL_DEFINITIONS_H_)
#ifndef WL_DEFINITIONS_H_

typedef enum {
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
WL_IDLE_STATUS = 0,
Expand All @@ -33,10 +34,9 @@ using namespace od;
WL_CONNECTION_LOST = 5,
WL_DISCONNECTED = 6
} wl_status_t;
#endif

#if !defined(WL_DEFINITIONS_H_)
enum WiFiMode { WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 };

#endif

/*
Expand Down
31 changes: 20 additions & 11 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Device::Device(){
_init(0, 0, DIGITAL, false);
_init(NULL, 0, 0, DIGITAL, false);
}

Device::Device(uint8_t ipin){
_init(0, ipin, DIGITAL, false);
_init(NULL, 0, ipin, DIGITAL, false);
}

Device::Device(uint8_t ipin, DeviceType type){
_init(0, ipin, type, false);
_init(NULL, 0, ipin, type, false);
}

Device::Device(uint8_t ipin, DeviceType type, bool sensor){
_init(0, ipin, type, sensor);
_init(NULL, 0, ipin, type, sensor);
}


Device::Device(uint8_t _id, uint8_t _pin, DeviceType _type){
_init(_id, _pin, _type, false);
_init(NULL, _id, _pin, _type, false);
}

Device::Device(uint8_t _id, uint8_t _pin, DeviceType _type, bool _sensor){
_init(_id, _pin, _type, _sensor);
_init(NULL, _id, _pin, _type, _sensor);
}

void Device::_init(uint8_t _id, uint8_t _pin, DeviceType _type, bool _sensor){

void Device::_init(char* name, uint8_t _id, uint8_t _pin, DeviceType _type, bool _sensor){

id = _id;
pin = _pin;
Expand All @@ -61,6 +61,7 @@ void Device::_init(uint8_t _id, uint8_t _pin, DeviceType _type, bool _sensor){
interruptEnabled = false;
interruptMode = CHANGE;
changeListener = 0;
deviceName = name;

//if(_sensor){
currentValue = LOW;
Expand All @@ -73,11 +74,11 @@ void Device::_init(uint8_t _id, uint8_t _pin, DeviceType _type, bool _sensor){


void Device::on(){
setValue(HIGH);
setValue(HIGH, true);
}

void Device::off(){
setValue(LOW);
setValue(LOW, true);
}

bool Device::setValue(unsigned long value, bool sync){
Expand Down Expand Up @@ -185,6 +186,14 @@ Device* Device::invertedState(){
return this;
}

void Device::name(char* name){
deviceName = name;
}

char* Device::name(){
return deviceName;
}

void Device::onChange(DeviceListener listener){
changeListener = listener;
}
Expand All @@ -203,7 +212,7 @@ bool Device::notifyListeners(){
// [ID, PIN, VALUE, TARGET, SENSOR?, TYPE]
int Device::toString(char buffer[]){
int itype = type;
return sprintf (buffer, "[%d,%d,%lu,%d,%d,%d]", id, pin, getValue(), targetID, (sensor ? 1 : 0), itype);
return sprintf (buffer, "[%s,%d,%d,%lu,%d,%d,%d]", (deviceName != NULL ? deviceName : ""), id, pin, getValue(), targetID, (sensor ? 1 : 0), itype);
}


Expand Down
Loading