Browse Source

résidence FDH

forced connection to sniperAP (WiFi.begin("sniperAP...)
forced station mode to prevent AP to start
debug random crash
Etienne Landon 8 years ago
parent
commit
3d67155a81
4 changed files with 69 additions and 37 deletions
  1. 32 14
      AD5242.h
  2. 23 10
      osc.h
  3. 9 10
      tens_esp.ino
  4. 5 3
      wifimgr.h

+ 32 - 14
AD5242.h

@@ -1,32 +1,50 @@
 #include <Wire.h>
 
-#define AD_adress1 0x2c
-#define AD_adress2 0x2f
-#define AD_pot1 0x00
-#define AD_pot2 0x80
+//#define AD_adress1 0x2c
+//#define AD_adress2 0x2f
+//#define AD_pot1 0x00
+//#define AD_pot2 0x80
+
+byte AD_adress1 = 0x2c;
+byte AD_adress2 = 0x2f;
+byte AD_pot1 = 0x00;
+byte AD_pot2 = 0x80;
 
 int potValue[4];
 int potValueUpdate[4];
-byte potAdress[][2] = { {AD_adress1, AD_pot1},
+byte potAdress[4][2] = { {AD_adress1, AD_pot1},
                        {AD_adress1, AD_pot2},
                        {AD_adress2, AD_pot1},
                        {AD_adress2, AD_pot2}, };
 
 void setup_AD5242() {
   Wire.begin(); // join i2c bus (address optional for master)
-  Serial.begin(115200);
+  Serial.println("starting digipots");
+  Serial.println(AD_adress1); 
+  Serial.println(AD_pot1);
+  Serial.println(potAdress[0][0]);
+  for (int i ; i<4 ; i++) {
+    for (int j ; j<2 ; j++){
+      Serial.print (potAdress[i][j], HEX);
+      Serial.print ("-");
+    }
+  }
 }
 
 void handle_AD5242() {
-  for (int i ; i++ ; i<4){
-    if (potValue[i] != potValueUpdate[i]) {
-      potValue[i] = potValueUpdate[i];
-      Wire.beginTransmission(potAdress[i][1]);
-      Wire.write(potAdress[i][2]);
-      Wire.write(potValue[i]); 
+  
+  for (int pot ; pot<4 ; pot++){
+//    Serial.println("pot");
+//    Serial.print(potAdress[pot][0] + " : ");
+//    Serial.println(potAdress[pot][1]);
+    if (potValue[pot] != potValueUpdate[pot]) {
+      potValue[pot] = potValueUpdate[pot];
+      Wire.beginTransmission(potAdress[pot][0]);
+      Wire.write(potAdress[pot][1]);
+      Wire.write(potValue[pot]); 
       Wire.endTransmission();
-      Serial.print(potAdress[i][1] + " : ");
-      Serial.println(potAdress[i][2]);
+      Serial.println("updated");
+      
     }
   }
   

+ 23 - 10
osc.h

@@ -29,10 +29,19 @@ void printTest(OSCMessage &msg) {
   
     Serial.print("OSC type : ");
     Serial.println (msg.getType(0));
-    sendOSC("/received", msg.getType(0));
+    sendOSC("/received", (int) msg.getType(0));
+    
   
 }
 
+void updatePotValue(OSCMessage &msg) {
+  // message /ESP_NAME/pot pot#[0..3] value[0..255]
+  potValueUpdate[msg.getInt(0)] = msg.getInt(1);
+  sendOSC("/updated", "pot" ); 
+  //Serial.print("update pot : " + msg.getInt(0) + "  ");
+  Serial.println (potValueUpdate[msg.getInt(0)]);
+}
+
 void setup_OSC(){
   
   ipMulti.fromString(UDP_IP);
@@ -46,14 +55,15 @@ void setup_OSC(){
   Serial.println(portMulti);
   
   UDP.beginMulticast(WiFi.localIP(),  ipMulti, portMulti);
-  OSCMessage OSCmsg("/connected");
-  for (int i=0 ; i<4 ; i++){
-    OSCmsg.add(WiFi.localIP()[i]);
-  }
-  UDP.beginPacketMulticast(ipMulti, portMulti,WiFi.localIP());
-  OSCmsg.send(UDP); // send the bytes to the SLIP stream
-  UDP.endPacket(); // mark the end of the OSC Packet
-  OSCmsg.empty(); // free space occupied by message
+//  OSCMessage OSCmsg("/connected");
+//  for (int i=0 ; i<4 ; i++){
+//    OSCmsg.add(WiFi.localIP()[i]);
+//  }
+//  UDP.beginPacketMulticast(ipMulti, portMulti,WiFi.localIP());
+//  OSCmsg.send(UDP); // send the bytes to the SLIP stream
+//  UDP.endPacket(); // mark the end of the OSC Packet
+//  OSCmsg.empty(); // free space occupied by message
+  sendOSC("/connected", 1);
 }
 
 void handle_OSC() {
@@ -67,10 +77,13 @@ void handle_OSC() {
     //Declare valid OSC messages here 
     if (!OSCin.hasError()) {
       OSCin.dispatch("/test", printTest);
-      if (OSCin.match(ESP_NAME)){Serial.println("matched");}
+      if (OSCin.match(ESP_NAME)){
+        Serial.println("matched");
+        OSCin.dispatch("/ESP_TENS_*/pot", updatePotValue);
       
       
     }
   }
 }
+}
 

+ 9 - 10
tens_esp.ino

@@ -11,36 +11,35 @@
 */
 
 #include <Ticker.h>
-
+#include "AD5242.h" //
 #include "leds.h"     //config and functions relative to leds
-#include "ota.h"      //config and functions relative to ota firmware updates
+//#include "ota.h"      //config and functions relative to ota firmware updates
 #include "wifimgr.h"   //config and functions relative to wifi and access point configuration and configuration permanent saving
 #include "osc.h"  //some helpers functions
-#include "AD5242.h" //
 
 
-void setup ( void ) {
-  
+
+void setup ( ) {
   delay(500) ;
   Serial.begin(115200);
   Serial.println("Starting ESP8266");
-  setup_AD5242() ;
+  
   setupLeds();
   setupWifi(); 
+  setup_AD5242() ;
   setup_OSC() ;
-  setupOTA();
+  //setupOTA();
   
  
   blueLedState(-1, 500);
   
-  
 }
 
 
-void loop ( void ) {
+void loop () {
   //Serial.println(WiFi.status());
   StartConfigAP();
-  checkOTA();
+  //checkOTA();
   handle_OSC();
   handle_AD5242();
   

+ 5 - 3
wifimgr.h

@@ -127,7 +127,7 @@ void StartConfigAP(){
     // detach all tickers (redLed, blueLed, OTA, wifimgr, UDP)
     redLedState (1, 500);
     blueLedState (1,500);
-    detachOTA();
+    //detachOTA();
     tkConfig.detach();
     delay (500); 
 
@@ -197,12 +197,14 @@ void StartConfigAP(){
 
 
 void setupWifi() {
-  pinMode(TRIGGER_PIN, INPUT);
+  pinMode(TRIGGER_PIN, INPUT_PULLUP);
   blueLedState (-1, 300);
   
   ReadConfig();
   Serial.print("Connecting");
-  WiFi.begin();
+  WiFi.mode(WIFI_STA);  // force remove AP
+  WiFi.begin("sniperAP","razorshark");
+  //WiFi.begin();
   int start_time = millis();
   while(WiFi.status()!=3){
     Serial.print(".");