int main() { // Close the simpleterm half duplex connection simpleterm_close(); // Start the sensor cog(s) cogstart(&pollPingSensors, NULL, pstack, sizeof pstack); // Blinken Lights! const int pauseTime = 50; const int startLED = 17; // 16 is used for the pollPingSensors cog to indicate activity. const int endLED = 23; high(startLED); pause(pauseTime); low(startLED); while(1) { pause(5); if(isActive == 1) { for (int led = startLED + 1; led <= endLED; led++) { high(led); pause(pauseTime); low(led); } for (int led = endLED - 1; led >= startLED; led--) { high(led); pause(pauseTime); low(led); } isActive = 0; } } }
void MessageStart() { lock = locknew(); lockclr(lock); simpleterm_close(); msg_serial = fdserial_open(31, 30, 0, 115200); cogstart(&HandleSerial, NULL, msg_stack, sizeof(msg_stack)); }
void wifi_simpletermSuspend(void) { if(wifi_comSelectPin != USB_PGM_TERM) { if(wifi_comSelectPin >= 0) high(wifi_comSelectPin); // Input prevents spurious nonprinting character in Wi-Fi-only mode on close. input(wifi_pin_di); simpleterm_close(); } }
void cmd_init(int wifi_rx, int wifi_tx, int debug_rx, int debug_tx) { // Close default same-cog terminal simpleterm_close(); // Set to open collector instead of driven wifi = fdserial_open(wifi_rx, wifi_tx, 0b0100, 115200); // Generate a BREAK to enter CMD command mode pause(10); low(wifi_tx); pause(1); input(wifi_tx); pause(1); if (debug_tx != -1 && wifi_tx != debug_tx) debug = fdserial_open(debug_rx, debug_tx, 0, 115200); else debug = wifi; }
void main() { badge_setup(); simpleterm_close(); ir_start(); ee_wipe(); // Connection to host routine (FORCE CONNECTION TO HOST) port = fdserial_open(31, 30, 0, 115200); char_size(SMALL); cursor(2, 4); display("Connecting..."); while(1) { dprint(port, "Propeller\n"); pause(1000); // We need this pause, since the host needs time to respond. 5 x 1 second = 10 second timeout if (fdserial_rxCount(port) == 0) { continue; } else if (fdserial_rxCount(port) < 5) { fdserial_rxFlush(port); continue; } else dscan(port, "%s", handshake); // Attempt handshake and listen to response if (strcmp(handshake, "H0st") == 0) { break; } } clear(); while(1) { rgb(L, OFF); rgb(R, OFF); char_size(BIG); cursor(0, 0); display("HOTSPOT!"); char_size(SMALL); cursor(4, 5); display("Start an"); cursor(1, 6); display("interaction to"); cursor(0, 7); display("upload your data"); memset(&their, 0, sizeof(info)); int t = CNT; int dt = CLKFREQ * 2; if (check_inbox() == 1) { clear(); message_get(&their); ir_send(&my); char_size(SMALL); cursor(2, 2); display("Receiving..."); while(1) { if (CNT - t > dt) { clear(); char_size(SMALL); cursor(5, 2); display("ERROR!"); cursor(0, 5); display("Please try again"); dprint(port, "txBegin\n"); dprint(port, "Timeout\n"); ee_wipe(); clear_inbox(); pause(2000); clear(); break; } if (check_inbox() == 1) { t = CNT; message_get(&their); if(!strcmp(their.name, "txDone")) { char_size(SMALL); cursor(0, 5); display("Upload complete"); dprint(port, "txBegin\n"); ee_uploadContacts(port); ee_wipe(); clear_inbox(); pause(1000); clear(); break; } ee_save(&their); dprint(port, "Name: %s\n", their.name); dprint(port, "Email: %s\n", their.email); } } } } }
int main(void) { //drive_pins(12, 13); sirc_setTimeout(60); simpleterm_close(); pause(100); term = fdserial_open(31, 30, 0, 115200); pause(100); drive_open(); while(1) { dprint(term, "%c", CLS); button = sirc_button(10); if(button == PWR) { set_mode(); } switch(mode) { case 0: switch(button) { case CH_UP: //drive_speed(100, 100); drive_speed(smul, smul); break; case CH_DN: //drive_speed(-100, -100); drive_speed(-smul, -smul); break; case VOL_DN: //drive_speed(-100, 100); drive_speed(-smul, smul); break; case VOL_UP: //drive_speed(100, -100); drive_speed(smul, -smul); break; default: //drive_speed(0, 0); drive_speed(0, 0); break; } break; case 1: for(int i = 0; i < 4; i++) { dist[i] = ping_cm(14+i); //dprint(term, "%d=%03d\n", i, dist[i]); pause(10); } speedL = 0; speedR = 0; if(dist[BACK] < 30) { speedL += 100; speedR += 100; } if(dist[FRONT] < 30) { speedL -= 100; speedR -= 100; } if(dist[LEFT] < 30) { if(speedL == 0) speedL -= 100; else if(speedL < 0) //speedR += 200; speedR += 50; else if(speedL > 0) //speedR -= 200; speedR -= 50; } if(dist[RIGHT] < 30) { if(speedR == 0) speedR -= 100; else if(speedR < 0) //speedL += 200; speedL += 50; else if(speedR > 0) //speedL -= 200; speedL -= 50; } drive_speed(speedL, speedR); pause(100); break; case 2: smul = 50; mode = 0; break; case 3: smul = 100; mode = 0; break; /* case 4: val = get_val(); dprint(term, "val = %d\n", val); pause(3000); break; */ } } }
int main() { //access the simpleIDE terminal simpleterm_close(); //set full-duplex serialization for the terminal term = fdserial_open(31, 30, 0, 9600); char c; //servo_angle(16, gripDegree); //Orient gripper to half open on start //pause(3000); while (1) { c = fdserial_rxChar(term); //Get the character entered from the terminal if (c != -1) { //Use the below to see if any key input is being read by the terminal // dprint(term, "You typed: %c\n", c); //Link key presses to directional commands, and print the command to strings if (c == 'f') //press "f" fof forward { Drive(ticks, ticks, maxSpeed); dprint(term, "ok\n"); } else if (c == 'b') //press "b" for backward { Drive(-ticks, -ticks, maxSpeed); dprint(term, "ok\n"); } else if (c == 'r') //press "r" for right turn { Drive(turnTick, -turnTick, maxTurnSpeed); dprint(term, "ok\n"); } else if (c == 'l') //press "l" for left turn { Drive(-turnTick, turnTick, maxTurnSpeed); dprint(term, "ok\n"); } //Increasing and Decreasing Drive Speed else if (c == 'u') { ticks = ticks + 2; if (ticks > maxSpeed) //clamp speed so it can't go over the maximum speed { ticks = maxSpeed; } dprint(term, "move_speed %d\n", ticks); } else if (c == 'd') { ticks = ticks - 2; if (ticks < minSpeed) //clamp speed so it can't go negative or 0 { ticks = minSpeed; } dprint(term, "move_speed %d\n", ticks); } //Increase Turn Speed; else if (c == 't') { turnTick = turnTick + 1; if (turnTick > maxTurnSpeed) { turnTick = maxTurnSpeed; } dprint(term, "turn_speed %d\n", turnTick); } //decrease turn speed else if (c == 'n') { turnTick = turnTick - 1; if (turnTick < minTurnSpeed) { turnTick = minTurnSpeed; } dprint(term, "turn_speed %d\n", turnTick); } else if (c == 'p') //ping distance { pingDistance = ping(8); dprint(term, "echo %d\n", pingDistance); dprint(term, "ok\n"); } else if (c == 'k') // poke { } else if (c == 'o') //open gripper { gripState = 0; gripDegree = -1800; } else if (c == 'g') //close gripper { gripState = 1; gripDegree = 1800; } } // End of Read Character Function if (gripState != -1) { Grip(gripDegree, 2000); } } // End of While Loop } //End of Main Loop
void main() { badge_setup(); simpleterm_close(); contacts_clearAll(); preserve_header(); CLKLIMIT = CLKFREQ * 2; // Connection to host routine (FORCE CONNECTION TO HOST) port = fdserial_open(31, 30, 0, 115200); text_size(SMALL); cursor(2, 4); oledprint("Connecting..."); spkr = talk_run(9, 10); // Start talk process while(1) { dprint(port, "Propeller\n"); pause(1000); // We need this pause, since the host needs time to respond. 5 x 1 second = 10 second timeout if (fdserial_rxCount(port) == 0) { continue; } else if (fdserial_rxCount(port) < 5) { fdserial_rxFlush(port); continue; } else dscan(port, "%s", handshake); // Attempt handshake and listen to response if (strcmp(handshake, "H0st") == 0) { break; } } clear(); talk_say(spkr, "heloa"); while(1) { rgb(L, OFF); rgb(R, OFF); text_size(LARGE); cursor(0, 0); oledprint("HOTSPOT!"); text_size(SMALL); cursor(4, 5); oledprint("Start an"); cursor(1, 6); oledprint("interaction to"); cursor(0, 7); oledprint("upload your data"); char their_id[7]; memset(&their_id, 0, 7); int t = CNT; char i_type[5]; irscan("%s%s", their_id, i_type); if (strlen(their_id) > 0) { clear(); eeprint("%s,%u,%s\n", their_id, 0, "INFO"); irprint("%s\n%s\n", "htspt1", "DUMP"); text_size(SMALL); cursor(2, 2); oledprint("Receiving..."); while(1) { char b[128]; memset(&b, 0, 128); irscan("%s", b); if (CNT - t > CLKLIMIT) { clear(); text_size(LARGE); cursor(0, 0); oledprint(" ERROR"); text_size(SMALL); cursor(0, 6); oledprint("Please try again"); dprint(port, "txBegin\n"); dprint(port, "Timeout\n"); contacts_clearAll(); preserve_header(); talk_say(spkr, "oops;/trae,-ugen"); pause(2000); clear(); break; } if (strlen(b) > 0) { t = CNT; if(!strcmp(b, "irDone")) { clear(); text_size(LARGE); cursor(0, 0); oledprint("SUCCESS"); text_size(SMALL); cursor(0, 6); oledprint("Upload complete"); talk_say(spkr, "oakay;</aem,dun"); dprint(port, "txBegin\n"); upload_contacts(port); contacts_clearAll(); preserve_header(); pause(1000); clear(); break; } save_contact(b); } } } } }
terminal *simpleterm_reopen(int rxpin, int txpin, int mode, int baud) { simpleterm_close(); dport_ptr = serial_open(rxpin, txpin, mode, baud); return dport_ptr; }