

amptest
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
#include <Arduino.h> #include "proto.h" #include "QList.h" #include "mode.h" #include "amptimer.h" void init_proto() { Serial.begin(115200); Serial.println("Piezo Control started."); Serial.println("Commands:"); Serial.println(" amp: [0 - 1]"); Serial.println(" freq: [0.1 - 200]"); Serial.println(" mode: [const][sine][tri]"); Serial.println(" sweep:[start;end;rate][no]"); Serial.println("------------------------"); } #define COMMAND_BUFFER_SIZE 256 #define CR 0x0D #define LF 0x0A void executeCommand(const char* cmd_str); char commandString[COMMAND_BUFFER_SIZE]; size_t cmdStrIndex = 0; #define CMD_ARG_OFFSET 7 unsigned long lastAutoStatus = 0; QList<String> arrCmd; void serialEvent() { while (Serial.available() > 0) { if (cmdStrIndex >= COMMAND_BUFFER_SIZE) { // Drop data. memset(commandString, 0, sizeof(commandString)); cmdStrIndex = 0; // return; } char inChar = (char)Serial.read(); commandString[cmdStrIndex] = inChar; // Serial1.print(inChar); if (inChar == CR || inChar == LF) commandString[cmdStrIndex] = char(0); cmdStrIndex++; if (inChar == LF) { // executeCommand(commandString); arrCmd.push_back(String(commandString)); cmdStrIndex = 0; // break; } } if (arrCmd.size() > 0) { executeCommand(arrCmd.at(0).c_str()); arrCmd.pop_front(); } } const char* _szCmdFreq = "freq:"; const char* _szCmdAmp = "amp:"; const char* _szCmdMode = "mode:"; const char* _szCmdSweep = "sweep:"; void executeCommand(const char* cmd_str) { // Serial.print("cmd: "); // Serial.println(cmd_str); if (strstr(cmd_str, _szCmdFreq) != NULL) { const char* str_arg = cmd_str + strlen(_szCmdFreq); if (strstr(str_arg, "?") == NULL) { double freq = atof(str_arg); setFreq(freq); } Serial.print(_szCmdFreq ); Serial.println(getFreq(), 3); } else if (strstr(cmd_str, _szCmdAmp) != NULL) { const char* str_arg = cmd_str + strlen(_szCmdAmp); if (strstr(str_arg, "?") == NULL) { double ampnew = atof(str_arg); setAmp(ampnew); } Serial.print(_szCmdAmp); Serial.println(getAmp(), 2); } else if (strstr(cmd_str, _szCmdMode) != NULL) { const char* str_arg = cmd_str + strlen(_szCmdMode); setMode(str_arg); Serial.print(_szCmdMode); Serial.println(getCurrentModeName()); } else if (strstr(cmd_str, _szCmdSweep) != NULL) { const char* str_arg = cmd_str + strlen(_szCmdSweep); setSweep(str_arg); //Serial.println(str_mode); Serial.print(_szCmdSweep); Serial.println(getSweepParams()); } } void processCommand() { serialEvent(); } |
Commits for amptest/trunk/proto.cpp
Revision | Author | Commited | Message |
---|---|---|---|
2 |
![]() |
Wed 20 Jul, 2022 00:52:33 +0000 |