Ignore:
Timestamp:
Apr 30, 2016, 11:29:25 PM (8 years ago)
Author:
ertl-honda
Message:

1.7.10のファイルに更新

Location:
rtos_arduino/trunk/arduino_lib/libraries/Ciao
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino

    r175 r224  
    33
    44#define CONNECTOR     "rest"
    5 #define SERVER_ADDR   "192.168.0.100" // change ip address with your server ip address
     5#define SERVER_ADDR   "192.168.1.1" // change ip address with your server ip address
    66
    7 int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
    8 int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
     7int buttonState; //this variable tracks the state of the button, low if not pressed, high if pressed
     8int ledState = HIGH; //this variable tracks the state of the LED, negative if off, positive if on
    99long lastDebounceTime = 0;  // the last time the output pin was toggled
    1010long debounceDelay = 50;    // the debounce time; increase if the output flickers
     11String command = "/arduino/mode/13/output";
     12int previous_value = LOW;
    1113
    1214void setup() {
    1315  Ciao.begin();
     16  Ciao.write(CONNECTOR, SERVER_ADDR, command);
    1417  pinMode(2, INPUT);
    1518 
     
    2023  //sample the state of the button - is it pressed or not?
    2124  buttonState = digitalRead(2);
    22  
     25  
    2326  //filter out any noise by setting a time buffer
    24   if ( (millis() - lastDebounceTime) > debounceDelay) {
    25  
    26     //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
    27     if ( (buttonState == HIGH) && (ledState < 0) ) {
    28  
    29       CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/1"); //turn LED on
    30       ledState = -ledState; //now the LED is on, we need to change the state
    31       lastDebounceTime = millis(); //set the current time
     27  if ( (buttonState == HIGH) && (previous_value == LOW) && (millis() - lastDebounceTime) > debounceDelay ) {
     28    if (ledState == HIGH){
     29      command = "/arduino/digital/13/0";
     30      ledState = LOW;
    3231    }
    33     else if ( (buttonState == HIGH) && (ledState > 0) ) {
    34  
    35       CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/0"); //turn LED off
    36       ledState = -ledState; //now the LED is off, we need to change the state
    37       lastDebounceTime = millis(); //set the current time
    38        
    39       if (!data.isEmpty()){
    40         Ciao.println( "State: " + String (data.get(1)) );
    41         Ciao.println( "Response: " + String (data.get(2)) );
    42       }
    43       else{
    44         Ciao.println ("Write Error");
    45       }
    46              
     32    else{
     33      command = "/arduino/digital/13/1";
     34      ledState = HIGH;
    4735    }
    48  
     36     
     37    lastDebounceTime = millis(); //set the current time
     38    CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, command); 
     39    if (!data.isEmpty()){
     40      Ciao.println( "State: " + String (data.get(1)) );
     41      Ciao.println( "Response: " + String (data.get(2)) );
     42    }
     43    else{
     44      Ciao.println ("Write Error");
     45    }
     46
    4947  }
    5048 
     49  previous_value = buttonState;
     50 
    5151}
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestServer/CiaoRestServer.ino

    r175 r224  
    11/*
    22
    3  This sketch uses the xmpp connector to receive command for the MCU from a xmpp client.
     3 This sketch uses the restserver connector receive rest calls. It allows access to
     4 the analog and digital pin of the board via rest calls.
     5
     6 supported boards: Yun,Tian.
    47
    58 Possible commands to send from the xmpp client:
    69
    7  * "digital/PIN"        -> to read a digital PIN
    8  * "digital/PIN/VALUE"  -> to write a digital PIN (VALUE: 1/0)
    9  * "analog/PIN/VALUE"   -> to write in a PWM PIN(VALUE range: 0 - 255);
    10  * "analog/PIN"         -> to read a analog PIN
    11  * "servo/PIN/VALUE"      -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
    12  * "mode/PIN/VALUE"     -> to set the PIN mode (VALUE: input / output)
    13  * "ledon"              -> turn on led 13
    14  * "ledoff"             -> turn off led 13
    15  * "ciao"               -> random answers in 5 different languages
    16  
    17  NOTE: be sure to activate and configure xmpp connector on Linino OS
    18        http://labs.arduino.org/Ciao
    19    
     10 * "/arduino/digital/PIN"       -> to read a digital PIN
     11 * "/arduino/digital/PIN/VALUE" -> to write a digital PIN (VALUE: 1/0)
     12 * "/arduino/analog/PIN/VALUE"  -> to write in a PWM PIN(VALUE range: 0 - 255);
     13 * "/arduino/analog/PIN"        -> to read a analog PIN
     14 * "/arduino/servo/PIN/VALUE"   -> to write angle in a SERVO PIN(VALUE range: 0 - 180);
     15 * "/arduino/mode/PIN/VALUE"    -> to set the PIN mode (VALUE: input / output)
     16
     17 Example:
     18 "/arduino/mode/13/output" -> pinMode(13, OUTPUT)
     19 "/arduino/digital/13/1"     -> digitalWrite(13, HIGH)
     20
     21
     22 NOTE: be sure to activate and configure restserver connector on Linino OS
     23  http://labs.arduino.org/Ciao
     24
    2025 created September 2015
    2126 by andrea[at]arduino[dot]org
    22  
     27
    2328 */
    24  
     29
    2530#include <Ciao.h>
    2631#include <Servo.h>
     
    3540void loop() {
    3641
    37   CiaoData data = Ciao.read("restserver");   
    38   if(!data.isEmpty()){ 
     42  CiaoData data = Ciao.read("restserver");
     43  if(!data.isEmpty()){
    3944    String id = data.get(0);
    4045    String sender = data.get(1);
    4146    String message = data.get(2);
    42    
     47
    4348    message.toUpperCase();
    44    
     49
    4550    String command[3];
    46          
     51
    4752    splitString(message,"/",command,3);
    4853    execute(command,id);
     
    7176void servoCommand(String cmd[], String id){
    7277   int pin, value;
    73  
     78
    7479  pin = (cmd[1]).toInt();
    75  
     80
    7681  if (cmd[2] != "-1") {
    7782    value = (cmd[2]).toInt();
     
    8590  }
    8691  else
    87     Ciao.writeResponse("restserver",id,"Invalid command"); 
     92    Ciao.writeResponse("restserver",id,"Invalid command");
    8893}
    8994
    9095void digitalCommand(String cmd[], String id) {
    9196  int pin, value;
    92  
     97
    9398  pin = (cmd[1]).toInt();
    94  
     99
    95100  if (cmd[2] != "-1") {
    96101    value = (cmd[2]).toInt();
     
    99104      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" ON");
    100105    else if(value == 0)
    101       Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");   
     106      Ciao.writeResponse("restserver",id,"Pin D"+String(pin)+" OFF");
    102107  }
    103108  else if (cmd[2] == "-1") {
     
    111116
    112117  pin = (cmd[1]).toInt();
    113  
     118
    114119  if (cmd[2] != "-1") {
    115120    value =(cmd[2]).toInt();
     
    127132
    128133  pin = (cmd[1]).toInt();
    129  
     134
    130135  if (cmd[2] == "INPUT") {
    131136    pinMode(pin, INPUT);
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/keywords.txt

    r175 r224  
    77#######################################
    88
    9 Ciao            KEYWORD3
    10 CiaoData        KEYWORD3
    11 Wifi            KEYWORD3
    12 WifiData        KEYWORD3
     9Ciao  KEYWORD3
     10CiaoData  KEYWORD3
     11Wifi  KEYWORD3
     12WifiData  KEYWORD3
    1313
    1414#######################################
     
    1616#######################################
    1717
    18 begin                   KEYWORD2
    19 writeResponse   KEYWORD2
    20 available               KEYWORD2
    21 read                    KEYWORD2
    22 write                   KEYWORD2
    23 bool                    KEYWORD2
     18writeResponse KEYWORD2
     19available KEYWORD2
     20read  KEYWORD2
     21write KEYWORD2
    2422
     23#######################################
     24# Constants (LITERAL1)
     25#######################################
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/library.properties

    r175 r224  
    11name=Ciao
    2 version=1.0
     2version=0.0.3
    33author=Arduino srl
    44maintainer=Arduino srl<info@arduino.org>
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/Ciao.h

    r175 r224  
    3030
    3131#include <Arduino.h>
     32#include <Stream.h>
    3233#include "lib/CiaoData.h"
    3334#if defined(__AVR_ATmega328P__)
    34 #include "lib/rest.h"
    3535#include "lib/SC16IS750.h"
    36 #include "lib/espduino.h"
    37 #else
    38 #include <Stream.h>
    3936#endif
    4037
     
    4441#define BAUDRATE 250000
    4542#elif defined(ARDUINO_ARCH_SAMD)
    46 #define BAUDRATE 115200
     43#define BAUDRATE 4000000
    4744#endif
    4845
     
    5552                CiaoData parse( String, String);
    5653                void println(String log){};
    57                 #if defined(__AVR_ATmega32U4__)
    5854                CiaoClass(Stream &_stream);
    59                 #elif defined(ARDUINO_ARCH_SAMD)
    60                 CiaoClass(Serial_ stream);
    61                 #endif
    6255
    6356        private:
    6457                void dropAll();
    6558                bool started;
    66                 #if defined(__AVR_ATmega32U4__)
    6759                Stream &stream;
    68                 #elif defined(ARDUINO_ARCH_SAMD)
    69                 Serial_ stream;
    70                 #endif
    7160};
    7261
     
    8069                }
    8170                #elif defined(ARDUINO_ARCH_SAMD)
    82                 SerialCiaoClass(Serial_ serial)
    83                         : CiaoClass(serial){
    84                         // Empty       
     71                SerialCiaoClass(Serial_ &_serial)
     72                        : CiaoClass(_serial), serial(_serial) {
     73                        // Empty
    8574                }
    8675                #endif
     
    9382                HardwareSerial &serial;
    9483                #elif defined(ARDUINO_ARCH_SAMD)
    95                 Serial_ serial;
     84                Serial_ &serial;
    9685                #endif
    9786};
     
    10392#else
    10493
    105 // class CiaoData {
    106 //      public:
    107                
    108 //              char* get(int index){
    109 //                      return msg_split[index];
    110 //              }
    111  
    112 //      public:
    113 //              char* msg_split[3];
    114                
    115 // };
     94class ArduinoWifiClass : public WifiData
     95{
    11696
    117 class CiaoClass {
     97        public:
     98                void begin();           
     99
     100                boolean connected();
     101                void connect(char* , char*);
     102
     103                void powerON();
     104                void powerOFF();
     105
     106
     107};
     108
     109class CiaoClass : public WifiData
     110{
    118111        public:
    119112                void begin();
     
    124117                CiaoData write( char*, char*, String );            // “rest”, ”hostname”, ”Stringone”,             
    125118                CiaoData write( char*, char*, String, char*);      // “rest”, ”hostname”, ”Stringone”, ”method”
    126                
    127                 void print(String str);
    128                 void println(String str);
    129119       
    130120};
     121
     122
    131123extern CiaoClass Ciao;
     124extern ArduinoWifiClass Wifi;
    132125
    133126#endif
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/Ciao.cpp

    r175 r224  
    2424*/
    2525
    26 #include "Ciao.h"
    2726
    2827#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_ARCH_SAMD)
    2928
    30 #if defined(__AVR_ATmega32U4__)
     29#include "Ciao.h"
     30
    3131CiaoClass::CiaoClass(Stream &_stream) :
    3232        stream(_stream), started(false) {
    3333  // Empty
    3434}
    35 #elif defined(ARDUINO_ARCH_SAMD)
    36 CiaoClass::CiaoClass(Serial_ stream){
    37   // Empty
    38 }
    39 #endif
    4035
    4136void CiaoClass::begin() {
     
    6055    }
    6156        do{
    62                 #if defined(__AVR_ATmega32U4__)
    6357                stream.print(F("run-ciao\n"));                          //start bridge python
    6458                stream.readStringUntil(END_TX_CHAR);
    65                 #endif
    6659                delay(3000);
    6760                stream.println("ciao;r;status");                                //check if bridge python is running
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.cpp

    r175 r224  
    2727#define WIRE Wire
    2828
    29 
    30 WifiData::WifiData(uint8_t prtcl, uint8_t addr_sspin)
    31 {
    32     protocol = prtcl;
    33     if ( protocol == SC16IS750_PROTOCOL_I2C ) {
    34         device_address_sspin = (addr_sspin>>1);
    35     } else {
    36         device_address_sspin = addr_sspin;
    37     }
     29WifiData::WifiData()
     30{
     31    device_address_sspin = (SC16IS750_ADDRESS_AA >> 1);
    3832    peek_flag = 0;
    3933}
     
    4135void WifiData::begin(uint32_t baud)
    4236{
    43     //Serial.println("1111111111111111");
     37
    4438    if ( protocol == SC16IS750_PROTOCOL_I2C) {
    45     //Serial.println("22222222222222");
    4639        WIRE.begin();
    4740    }
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/SC16IS750.h

    r175 r224  
    104104#define     SC16IS750_PROTOCOL_I2C  (0)
    105105#define     SC16IS750_PROTOCOL_I2C  (0)
    106 #define     END     "<!--~-->"
     106#define     DELIMITER     "<!--~-->"
     107#define     EOL           '\0'
    107108
    108109class WifiData : public Stream
    109110{
    110111    public:
    111         WifiData(uint8_t prtcl = SC16IS750_PROTOCOL_I2C, uint8_t addr = SC16IS750_ADDRESS_AD);
     112        WifiData();
    112113        void begin(uint32_t baud);                               
    113114        int read();
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.cpp

    r175 r224  
    188188}
    189189
    190 ESP::ESP(Stream *serial, int chip_pd):
    191 _serial(serial), _chip_pd(chip_pd)
     190ESP::ESP(Stream *serial):
     191_serial(serial)
    192192{
    193193  _debugEn = false;
     
    195195}
    196196
    197 ESP::ESP(Stream *serial, Stream* debug, int chip_pd):
    198 _serial(serial), _debug(debug), _chip_pd(chip_pd)
    199 {
    200     _debugEn = true;
    201     //_serial = _debug;
    202     init();
    203 }
     197
    204198void ESP::enable()
    205199{
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/src/lib/espduino.h

    r175 r224  
    9292{
    9393public:
    94   ESP(Stream *serial, Stream* debug, int chip_pd);
    95   ESP(Stream *serial, int chip_pd);
     94  //ESP(Stream *serial, Stream* debug, int chip_pd);
     95  ESP(Stream *serial); //ok
    9696  Stream *_debug;
    9797
Note: See TracChangeset for help on using the changeset viewer.