ESP3D
3.0
Firmware for ESP boards connected to 3D Printer
ESP170.cpp
Go to the documentation of this file.
1
/*
2
ESP170.cpp - ESP3D command 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
#include "../../include/esp3d_config.h"
21
#if defined (CAMERA_DEVICE)
22
#include "../commands.h"
23
#include "../esp3doutput.h"
24
#include "../settings_esp3d.h"
25
#include "../../modules/authentication/authentication_service.h"
26
#include "../../modules/network/netservices.h"
27
#include "../../modules/camera/camera.h"
28
//Set camera server state which can be ON, OFF
29
//[ESP170]<state>pwd=<admin password>
30
bool
Commands::ESP170(
const
char
* cmd_params,
level_authenticate_type
auth_type,
ESP3DOutput
* output)
31
{
32
bool
response =
true
;
33
String parameter;
34
#ifdef AUTHENTICATION_FEATURE
35
if
(auth_type ==
LEVEL_GUEST
) {
36
output->
printERROR
(
"Wrong authentication!"
, 401);
37
return
false
;
38
}
39
#else
40
(void)auth_type;
41
#endif //AUTHENTICATION_FEATURE
42
parameter =
get_param
(cmd_params,
""
);
43
//get
44
if
(parameter.length() == 0) {
45
output->
printMSG
(!
esp3d_camera
.
started
()?
"Camera OFF"
:
"Camera ON"
);
46
}
else
{
//set
47
#ifdef AUTHENTICATION_FEATURE
48
if
(auth_type !=
LEVEL_ADMIN
) {
49
output->
printERROR
(
"Wrong authentication!"
, 401);
50
return
false
;
51
}
52
#endif //AUTHENTICATION_FEATURE
53
parameter.toUpperCase();
54
if
(!((parameter ==
"ON"
) || (parameter ==
"OFF"
))) {
55
output->
printERROR
(
"Only ON or OFF mode supported!"
);
56
return
false
;
57
}
else
{
58
if
(parameter ==
"ON"
) {
59
esp3d_camera
.
begin
();
60
}
else
{
61
esp3d_camera
.
stopHardware
();
62
}
63
output->
printMSG
(
"ok"
);
64
}
65
}
66
return
response;
67
}
68
69
#endif //HTTP_FEATURE && CAMERA_DEVICE
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition:
commands.cpp:162
Camera::started
bool started()
Definition:
camera.h:38
Camera::begin
bool begin(bool forceinit=false)
Camera::stopHardware
bool stopHardware()
LEVEL_GUEST
@ LEVEL_GUEST
Definition:
authentication_service.h:26
level_authenticate_type
level_authenticate_type
Definition:
authentication_service.h:25
ESP3DOutput::printMSG
size_t printMSG(const char *s, bool withNL=true)
Definition:
esp3doutput.cpp:190
ESP3DOutput::printERROR
size_t printERROR(const char *s, int code_error=200)
Definition:
esp3doutput.cpp:247
LEVEL_ADMIN
@ LEVEL_ADMIN
Definition:
authentication_service.h:28
esp3d_camera
Camera esp3d_camera
ESP3DOutput
Definition:
esp3doutput.h:48
esp3d
src
core
espcmd
ESP170.cpp
Generated by
1.8.17