def real_time_data_prompt(serial_socket):

    real_time_answer = raw_input("Would you like to plot real-time data? (y/n) ")
    

    if real_time_answer == 'y':
        real_time_data = 'ON'
        

        # Handshake with arduino to ensure RT data engaged
        python_send = 244
        arduino_success = 11
        arduino_fail = 13
        message_success = "RT Data Enabled!"
        message_fail = "!!!RT Data failed to enable!!!"

        hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail, message_success, message_fail)


    else:
        real_time_data = 'OFF'

        # Handshake with arduino to ensure RT data engaged
        python_send = 245
        arduino_success = 12
        arduino_fail = 13
        message_success = "RT Data Disabled!"
        message_fail = "!!!RT Data failed to disable!!!"

        hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail, message_success, message_fail)

    # HANDSHAKE COMPLETE

    return real_time_data
def download_data(serial_socket):
    

    # Handshake with device for mode change
    python_send = 1
    arduino_success = 127
    arduino_fail = 128

    hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail)

    # HANDSHAKE COMPLETE


    choice = raw_input("Would you like to download now? (y/n) ")
    time.sleep(0.2)

    if choice == 'y':
        dl.downloader_main(serial_socket)
    else:
        print("Goodbye!")
        exit();
def collect_data(serial_socket):
    

    # Handshake with device for mode change
    python_send = 0
    arduino_success = 126
    arduino_fail = 128

    hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail)
    # HANDSHAKE complete


    real_time_data = real_time_data_prompt(serial_socket)

    print("Plotting data now...")

    # RT Data
    if real_time_data == 'ON':
        
        # Instantiate plot
        analog_plot = AnalogPlot(serial_socket)

        
        # set up animation
        # Attaching 3D axis to the figure
        fig = plt.figure()
        ax = p3.Axes3D(fig)
        
        ax.set_title('3D Test')
        ax.set_xlim3d([30.0, 60.0])
        ax.set_xlabel('X')
        ax.set_ylim3d([30.0, 60.0])
        ax.set_ylabel('Y')
        ax.set_zlim3d([0.0, 250.0])
        ax.set_zlabel('Z')

        frame_num = 2500

        data_lines = [np.empty((3, frame_num))]
        
        lines = [ax.plot([0], [0], [0])[0]]
        
        anim = animation.FuncAnimation(fig, analog_plot.update, frame_num, fargs=(data_lines, lines), interval=50, blit=False)

        
        # show plot
        plt.show()

        # clean up
        analog_plot.close()

        print('exiting.')

                

    # NO RT Data
    elif real_time_data == 'OFF':
        while True:
            while serial_socket.inWaiting() > 0:
                  
                print ord(serial_socket.read(1))
def collect_data(serial_socket):
    

    # Handshake with device for mode change
    python_send = 0
    arduino_success = 126
    arduino_fail = 128

    hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail)
    
  
    # HANDSHAKE complete



    real_time_answer = raw_input("Would you like to plot real-time data? (y/n) ")
    
    

    if real_time_answer == 'y':
        real_time_data = 'ON'
        


        # Handshake with arduino to ensure RT data engaged
        python_send = 244
        arduino_success = 11
        arduino_fail = 13
        message_success = "RT Data Enabled!"
        message_fail = "!!!RT Data failed to enable!!!"

        hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail, message_success, message_fail)

        # HANDSHAKE COMPLETE




    else:
        real_time_data = 'OFF'

        # Handshake with arduino to ensure RT data engaged
        python_send = 245
        arduino_success = 12
        arduino_fail = 13
        message_success = "RT Data Disabled!"
        message_fail = "!!!RT Data failed to disable!!!"

        hs.hand_shake(serial_socket, python_send, arduino_success, arduino_fail, message_success, message_fail)

        # HANDSHAKE COMPLETE



    # RT Data
    if real_time_data == 'ON':
        
        # Attaching 3D axis to the figure
        fig = plt.figure()
        ax = p3.Axes3D(fig)

        # Setting the axes properties
        ax.set_xlim3d([0.0, 30.0])
        ax.set_xlabel('X')

        ax.set_ylim3d([0.0, 30.0])
        ax.set_ylabel('Y')

        ax.set_zlim3d([0.0, 30.0])
        ax.set_zlabel('Z')

        ax.set_title('3D Test')


        # instantiating accel and time lists
        length = 20
        counter = 0
    

        line_data = np.empty((3, length))
        
        lines = [ax.plot(line_data[0, 0:1], line_data[1, 0:1], line_data[2, 0:1])][0]
        

       
        # Creating the Animation object
        line_ani = animation.FuncAnimation(fig, update_lines, length, fargs=(line_data, lines, serial_socket), blit=False)
        
        plt.show()


                


    # NO RT Data
    elif real_time_data == 'OFF':
        while True:
            while serial_socket.inWaiting() > 0:
                
                print ord(serial_socket.read(1))