ESP3D  3.0
Firmware for ESP boards connected to 3D Printer
ESP910.cpp
Go to the documentation of this file.
1 /*
2  ESP910.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 (BUZZER_DEVICE)
22 #include "../commands.h"
23 #include "../esp3doutput.h"
24 #include "../settings_esp3d.h"
25 #include "../../modules/authentication/authentication_service.h"
26 #include "../../modules/buzzer/buzzer.h"
27 //Get state / Set Enable / Disable buzzer
28 //[ESP910]<ENABLE/DISABLE>[pwd=<admin password>]
29 bool Commands::ESP910(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output)
30 {
31  bool response = true;
32  String parameter;
33 #ifdef AUTHENTICATION_FEATURE
34  if (auth_type == LEVEL_GUEST) {
35  output->printERROR("Wrong authentication!", 401);
36  return false;
37  }
38 #else
39  (void)auth_type;
40 #endif //AUTHENTICATION_FEATURE
41  parameter = get_param (cmd_params, "");
42  //get
43  if (parameter.length() == 0) {
44  if (esp3d_buzzer.started()) {
45  output->printMSG("ENABLED");
46  } else {
47  output->printMSG("DISABLED");
48  }
49  } else { //set
50  if (!Settings_ESP3D::write_byte (ESP_BUZZER, (parameter == "ENABLE")?1:0)) {
51  output->printERROR ("Set failed!");
52  response = false;
53  }
54  if (parameter == "ENABLE" ) {
55 
56  if (esp3d_buzzer.begin()) {
57  output->printMSG ("Buzzer enabled");
58  } else {
59  output->printERROR("Cannot enable buzzer!", 500);
60  response = false;
61  }
62  } else if (parameter == "DISABLE" ) {
63  output->printMSG ("Buzzer disabled");
64  esp3d_buzzer.end();
65  } else {
66  output->printERROR("Incorrect command!");
67  response = false;
68  }
69  }
70  return response;
71 }
72 #endif //BUZZER_DEVICE
Settings_ESP3D::write_byte
static bool write_byte(int pos, const uint8_t value)
Definition: settings_esp3d.cpp:749
Commands::get_param
const char * get_param(const char *cmd_params, const char *label)
Definition: commands.cpp:162
BuzzerDevice::started
bool started()
Definition: buzzer.h:37
LEVEL_GUEST
@ LEVEL_GUEST
Definition: authentication_service.h:26
BuzzerDevice::end
void end()
level_authenticate_type
level_authenticate_type
Definition: authentication_service.h:25
ESP_BUZZER
#define ESP_BUZZER
Definition: settings_esp3d.h:50
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
BuzzerDevice::begin
bool begin()
esp3d_buzzer
BuzzerDevice esp3d_buzzer
ESP3DOutput
Definition: esp3doutput.h:48