Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:c990fafbe0fc, committed 2018-06-22
- Comitter:
- rakware
- Date:
- Fri Jun 22 10:57:11 2018 +0000
- Child:
- 1:20aa0d04a527
- Commit message:
- 1st
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Jun 22 10:57:11 2018 +0000
@@ -0,0 +1,247 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+//Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut led(LED1);
+
+DigitalOut step(A0);
+DigitalOut dir(A1);
+
+int count = 0;
+
+float speed = 200;
+
+char ml_in[256];
+uint8_t idx = 0;
+
+//void process_comm_from_buff(char *_buff)
+//{
+//
+// pc.printf("procesez din buffer\r\n");
+// for (uint8_t i=0; i<sizeof(&_buff); i++) {
+// pc.printf("%c", _buff[i]);
+// }
+//}
+//
+void read_serial_into_buff(char *_buff)
+{
+ while(pc.readable()) {
+ char c = pc.getc();
+
+ switch(c) {
+
+// case '+':
+// speed += 10;
+// pc.printf("%f", speed);
+// break;
+//
+// case '-':
+// speed -= 10;
+// pc.printf("%f", speed);
+// break;
+
+ case ':':
+ idx=0;
+ memset(_buff, 0, 8);
+ break;
+
+ case '#':
+
+ switch (_buff[0]) {
+
+ case 'G':
+ switch (_buff[1]) {
+ case 'P':
+ pc.printf("%04X#", uint16_t(0));
+ pc.printf("\r\n");
+ break;
+ case 'H':
+ pc.printf("00#\r\n");
+ break;
+ case 'T':
+ pc.printf("%04X#\r\n", int8_t(25));
+ default:
+
+ for (uint8_t i=0; i<8; i++) {
+ pc.printf("%c", _buff[i]);
+ }
+ pc.printf("\r\n");
+
+ break;
+ }
+ break;
+ default:
+ for (uint8_t i=0; i<8; i++) {
+ pc.printf("%c", _buff[i]);
+ }
+ pc.printf("\r\n");
+
+ break;
+ }
+
+// for (uint8_t i=0; i<8; i++) {
+// pc.printf("%c", _buff[i]);
+// }
+// pc.printf("\r\n");
+
+ break;
+
+ default:
+
+
+ _buff[idx++] = c;
+ idx %= 8;
+ break;
+ }
+ }
+}
+
+
+void read_ser()
+{
+
+ while(pc.readable()) {
+ char c = pc.getc();
+
+ switch (c) {
+ case '#':
+ //pc.printf("%s\r\n", ml_in);
+
+ switch (ml_in[0]) {
+ case 'C': //N/A Initiate a temperature conversion; the conversion process takes a maximum of 750 milliseconds. The value returned by the :GT# command will not be valid until the conversion process completes.
+ break;
+ case 'F':
+ switch (ml_in[1]) {
+ case 'G': //N/A Go to the new position as set by the ":SNYYYY#" command.
+ break;
+ case 'Q': //N/A Immediately stop any focus motor movement.
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case 'G':
+ switch (ml_in[1]) {
+ case 'B': // Get the backlight value
+ pc.printf("00#");
+ break;
+ case 'C': //XX# Returns the temperature coefficient where XX is a two-digit signed (2’s complement) hex number.
+ pc.printf("02#");
+ break;
+ case 'D': //XX# Returns the current stepping delay where XX is a two-digit unsigned hex number. Valid values 02, 04, 08, 10, 20 -> stepping delay 250, 125, 63, 32, 16 pps
+ pc.printf("02#");
+ break;
+ case 'H': //00# OR FF# Returns "FF#" if the focus motor is half-stepped otherwise return "00#"
+ pc.printf("00#");
+ break;
+ case 'I': //00# OR 01# Returns "00#" if the focus motor is not moving, otherwise return "01#"
+ pc.printf("00#");
+ break;
+ case 'N': //YYYY# Returns the new position previously set by a ":SNYYYY" command where YYYY is a four-digit unsigned hex number
+ pc.printf("0000#"); //TODO
+ break;
+ case 'P': //YYYY# Returns the current position where YYYY is a four-digit unsigned hex number.
+ pc.printf("%04X#", uint16_t(0)); //TODO
+ break;
+ case 'T': //YYYY# Returns the current temperature where YYYY is a four-digit signed (2’s complement) hex number.
+ pc.printf("%04X#", uint16_t(25));
+ break;
+ case 'V': //DD# Get the version of the firmware as a two-digit decimal number where the first digit is the major version number, and the second digit is the minor version number.
+ pc.printf("01#");
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case 'S':
+ switch(ml_in[1]) {
+ case 'C': //N/A Set the new temperature coefficient where XX is a two-digit, signed (2’s complement) hex number.
+ break;
+ case 'D': //N/A Set the new stepping delay where XX is a two-digit, unsigned hex number. Valid values to send are 02, 04, 08, 10 and 20, which correspond to a stepping delay of 250, 125, 63, 32 and 16 steps per second respectively.
+ //strncpy(str, cmd + 2, 2);
+ //g_motor1.set_speed(util::hexstr2long(str));
+ break;
+
+ case 'F': //N/A Set full-step mode.
+ //g_motor1.set_full_step();
+ break;
+
+ case 'H': //N/A Set half-step mode.
+ //g_motor1.set_half_step();
+ break;
+
+ case 'N': //N/A Set the new position where YYYY is a four-digit unsigned hex number.
+ //strncpy(str, cmd + 2, 4);
+ //g_motor1.set_target_position(util::hexstr2long(str));
+ break;
+
+ case 'P': //Set the current position where YYYY is a four-digit unsigned hex number.
+ //strncpy(str, cmd + 2, 4);
+ //g_motor1.set_current_position(util::hexstr2long(str));
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case '+': //N/A Activate temperature compensation focusing.
+ break; //TODO
+ case '-': //N/A Disable temperature compensation focusing.
+ break; //TODO
+
+ case 'P':
+ break;
+
+// case ':POXX#': //N/A Temperature calibration offset, XX is a two-digit signed hex number, in half degree increments. Example 1: :PO02# offset of +1°C Example 2: :POFB# offset of -2.5°
+// break; //TODO
+
+ default:
+ break;
+ }
+ break;
+
+ case ':':
+ idx=0;
+ memset(ml_in, 0, 8);
+ break;
+
+ default:
+ ml_in[idx++] = c;
+ idx %= 8;
+ break;
+ }
+
+
+
+ }
+}
+
+
+int main()
+{
+ step = 0;
+ dir = 0;
+
+ pc.attach(&read_ser, Serial::RxIrq);
+
+ while(1) {
+
+ //read_serial_into_buff(ml_in);
+
+
+
+ //step = !step;
+// count++;
+// wait( float(1/(speed*2)) );
+//
+// if(count == 400) {
+// dir = !dir;
+// }
+
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Jun 22 10:57:11 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee \ No newline at end of file