ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
esp3doutput.h
Go to the documentation of this file.
1 /*
2  esp3Doutput.h - out functions class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #define ESP_NO_CLIENT 0
22 #define ESP_SERIAL_CLIENT 1
23 #define ESP_TELNET_CLIENT 2
24 #define ESP_HTTP_CLIENT 4
25 #define ESP_WEBSOCKET_TERMINAL_CLIENT 8
26 #define ESP_PRINTER_LCD_CLIENT 16
27 #define ESP_BT_CLIENT 32
28 #define ESP_SCREEN_CLIENT 64
29 #define ESP_WEBSOCKET_CLIENT 128
30 #define ESP_ALL_CLIENTS 255
31 
32 #ifndef _ESP3DOUTPUT_H
33 #define _ESP3DOUTPUT_H
34 
35 #include "Print.h"
36 #include "../include/esp3d_config.h"
37 #ifdef HTTP_FEATURE
38 #if defined (ARDUINO_ARCH_ESP32)
39 class WebServer;
40 #define WEBSERVER WebServer
41 #endif //ARDUINO_ARCH_ESP32
42 #if defined (ARDUINO_ARCH_ESP8266)
43 #include <ESP8266WebServer.h>
44 #define WEBSERVER ESP8266WebServer
45 #endif //ARDUINO_ARCH_ESP8266
46 #endif //HTTP_FEATURE
47 
48 class ESP3DOutput : public Print
49 {
50 public:
51  ESP3DOutput(uint8_t client = 0);
52 #ifdef HTTP_FEATURE
53  ESP3DOutput(WEBSERVER * webserver);
54 #endif //HTTP_FEATURE
55  ~ESP3DOutput();
56  size_t write(uint8_t c);
57  size_t write(const uint8_t *buffer, size_t size);
58 
59  inline size_t write(const char * s)
60  {
61  return write((uint8_t*) s, strlen(s));
62  }
63  inline size_t write(unsigned long n)
64  {
65  return write((uint8_t) n);
66  }
67  inline size_t write(long n)
68  {
69  return write((uint8_t) n);
70  }
71  inline size_t write(unsigned int n)
72  {
73  return write((uint8_t) n);
74  }
75  inline size_t write(int n)
76  {
77  return write((uint8_t) n);
78  }
79  uint8_t client()
80  {
81  return _client;
82  }
83  size_t dispatch (uint8_t * sbuf, size_t len);
84  size_t printMSG(const char * s, bool withNL = true);
85  size_t printERROR(const char * s, int code_error = 200);
86  size_t printLN(const char * s);
87  void flush();
88  int availableforwrite();
89  static bool isOutput(uint8_t flag, bool fromsettings = false);
90 private:
91  uint8_t _client;
92 #ifdef HTTP_FEATURE
93  int _code;
94  bool _headerSent;
95  bool _footerSent;
96  WEBSERVER * _webserver;
97 #endif //HTTP_FEATURE
98  static uint8_t _outputflags;
99 };
100 
102 {
103 public:
104  static void SetStatus(const char * status);
105  static void display_progress(uint8_t v);
106  static void display_IP(bool force = false);
107 };
108 
109 #endif //_ESP3DOUTPUT_H
110 
ESP3DGlobalOutput::display_IP
static void display_IP(bool force=false)
Definition: esp3doutput.cpp:445
ESP3DOutput::isOutput
static bool isOutput(uint8_t flag, bool fromsettings=false)
Definition: esp3doutput.cpp:78
ESP3DOutput::ESP3DOutput
ESP3DOutput(uint8_t client=0)
Definition: esp3doutput.cpp:48
ESP3DOutput::write
size_t write(unsigned int n)
Definition: esp3doutput.h:71
ESP3DOutput::availableforwrite
int availableforwrite()
Definition: esp3doutput.cpp:295
ESP3DOutput::printLN
size_t printLN(const char *s)
Definition: esp3doutput.cpp:165
ESP3DOutput::dispatch
size_t dispatch(uint8_t *sbuf, size_t len)
Definition: esp3doutput.cpp:87
ESP3DOutput::write
size_t write(const char *s)
Definition: esp3doutput.h:59
ESP3DGlobalOutput
Definition: esp3doutput.h:101
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition: esp3doutput.cpp:190
ESP3DOutput::write
size_t write(int n)
Definition: esp3doutput.h:75
ESP3DGlobalOutput::display_progress
static void display_progress(uint8_t v)
Definition: esp3doutput.cpp:436
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition: esp3doutput.cpp:247
ESP3DOutput::~ESP3DOutput
~ESP3DOutput()
Definition: esp3doutput.cpp:73
ESP3DOutput::write
size_t write(unsigned long n)
Definition: esp3doutput.h:63
ESP3DOutput::client
uint8_t client()
Definition: esp3doutput.h:79
ESP3DOutput::write
size_t write(uint8_t c)
Definition: esp3doutput.cpp:322
ESP3DOutput::flush
void flush()
Definition: esp3doutput.cpp:128
ESP3DOutput::write
size_t write(long n)
Definition: esp3doutput.h:67
ESP3DOutput
Definition: esp3doutput.h:48
ESP3DGlobalOutput::SetStatus
static void SetStatus(const char *status)
Definition: esp3doutput.cpp:428