B
    #D^  ã               @   sF   d dl Z d dlZd dlZd dlmZ dZd	dd„ZG dd„ deƒZ	dS )
é    N)Ú
get_prettyé	   é   c             C   s
   t d| ƒS )Nr   )Úrange)Ún© r   ú$/home/pi/src/pyrow/pyrow/simpyrow.pyÚfind   s    r	   c               @   sd   e Zd Zdd„ Zedd„ ƒZddd„Zddd	„Zdd
d„Zddd„Z	ddd„Z
dd„ Zddd„ZdS )ÚPyErgc             C   s0   || _ t ¡ | _tj dd¡| _tj ¡ | _	dS )z 
        Sets erg value
        é   g{®Gáz”?N)
ÚergÚtimeÚ_start_timeÚnpZrandomZnormalÚ_factorÚdatetimeÚnowZ_PyErg__lastsend)Úselfr   r   r   r   Ú__init__   s    
zPyErg.__init__c             C   s:   t |ƒtk	rt|ƒ‚||  kr(|ks6n t|d ƒ‚dS )zP
        Checks that value is an integer and within the specified range
        z outside of rangeT)ÚtypeÚintÚ	TypeErrorÚ
ValueError)r   ÚvalueZlabelZminimumZmaximumr   r   r   Z__checkvalue   s
    zPyErg.__checkvalueFc             C   sö   d}d}d}dd„ }d}dd„ }t t ¡ | j dƒ}	i }
t |	dƒ|
d	< tt | j||	ƒ ƒƒ|
d
< ||
d< ||
d< |
d ržd| d d |
d< |d d |
d< nd\|
d< |
d< t ||	 ƒ|
d< d|
d< |ràdgd |
d< d|
d< t|
d< t|
|ƒ}
|
S )a  
        Returns values from the monitor that relate to the current workout,
        optionally returns force plot data and stroke state. (* required)
        time: time in seconds
        distance: distance in meters
        spm: strokes per minute
        power: power in watts
        pace: seconds/500m
        calhr: calories burned per hour
        calories: calories burned
        heartrate: heartrate
        status
        if heartrate:
            forceplot: force plot data
            strokestate
        é   é–   r   c             S   sT   dt  t j|  ¡ dt  t j|  d ¡  dt  |  d ¡  dt  |  d ¡  S )Né   g      à?ià  éx   é   )r   ÚsinÚpiÚcosÚexp)Úxr   r   r   Ú<lambda>>   ó    z#PyErg.get_monitor.<locals>.<lambda>r   c             S   s`   dd|   dt  |  d ¡  dt  |  d ¡  dt  t j|  d ¡  dt  t j|  ¡  S )	Ngfffff&D@r   é<   r   é   éP   ià  g333333Ó?)r   r"   r   r    r!   )r#   r   r   r   r$   @   r%   r   r   ÚdistanceZspmZpowergffffff@gUUUUUUÕ?iô  ÚpacegO¯”eˆ@g     Àr@Zcalhr)r   r   Zcalorieséd   Z	heartrateé    Ú	forceplotr   ÚstrokestateÚstatus)Úroundr   r   r   r   ÚSTATUSr   )r   r-   ÚprettyZSPMZPOWERZCAL_TO_TIMEZVELZVELOCITYZDISTZelapsed_timeZmonitorr   r   r   Úget_monitor)   s0    
zPyErg.get_monitorc             C   s0   i }dgd |d< d|d< t |d< t||ƒ}|S )z:
        Returns force plot data and stroke state
        r   r,   r-   r   r.   r/   )r1   r   )r   r2   r-   r   r   r   Úget_forceplotY   s    
zPyErg.get_forceplotc             C   sB   i }d|d< d|d< d|d< d|d< d|d< t |d< t||ƒ}|S )	z.
        Returns overall workout data
        r   Zuseridr   r   ÚstateZinttypeZintcountr/   )r1   r   )r   r2   Zworkoutdatar   r   r   Úget_workoute   s    
zPyErg.get_workoutc             C   sb   i }d|d< d|d< d|d< d|d< d|d< d|d< d|d< d|d	< d|d
< t |d< t||ƒ}|S )zI
        Returns all erg data that is not related to the workout
        r   ZmfgidZcidZmodelZ	hwversionZ	swversionÚserialZmaxrxZmaxtxZmininterframer/   )r1   r   )r   r2   Zergdatar   r   r   Úget_ergt   s    
zPyErg.get_ergc             C   s   i }t |d< t||ƒ}|S )z/
        Returns the status of the erg
        r/   )r1   r   )r   r2   r/   r   r   r   Ú
get_statusŠ   s    
zPyErg.get_statusc             C   s   t j  ¡ }dS )zK
        Sets the erg clock to the computers current time and date
        N)r   r   )r   r   r   r   r   Ú	set_clock”   s    zPyErg.set_clockNc       
      C   sð  |dkr|   |ddd¡ nº|dkr¼t|ƒdkr:| dd¡ t|ƒdkrR| dd¡ |   |d ddd¡ |   |d d	dd
¡ |   |d ddd
¡ |d dkrÔ|d dkrÔ|d dk rÔtdƒ‚n|dkrÔ|   |ddd¡ |dkr’|dkrN|dkrNt|d ƒ}|d d |d d  |d  }t|d d d ƒ}	|   |dtd|	ƒ|d ¡ nD|dkrŠ|dkrŠt|d d ƒ}	|   |dtd|	ƒ|¡ ntdƒ‚|dkr¶ttd|d d  ƒƒ}n|dkrÔtt|d d ƒƒ}|dkrÞ|dkrìd}dS )aÝ  
        If machine is in the ready state, function will set the
        workout and display the start workout screen
        Choose one of:
        program: workout program 0 to 15
        workout_time: workout time as a list, [hours, minutes, seconds]
        distance: meters
        If workout_time or distance, optional: split
        One of the following for pace boat (optional):
        pace: seconds
        calpace: calories per hour
        powerpace: watts
        NZProgramr   é   r   r   z
Time Hoursr   zTime Minutesé;   zTime Secondsr'   zWorkout too shortZDistancer+   iPÃ  i  r&   r   g      à?z
Split TimeiÐ  zSplit distancez!Cannot set split for current goalgffffff@g     @@é   g     Àr@gO¯”eˆ@)Ú_PyErg__checkvalueÚlenÚinsertr   r   Úmaxr0   )
r   ZprogramZworkout_timer)   Úsplitr*   ZcalpaceZ	powerpaceZtime_rawZminsplitr   r   r   Úset_workoutš   s>    $

 



zPyErg.set_workout)FF)F)F)F)F)NNNNNNN)Ú__name__Ú
__module__Ú__qualname__r   Úclassmethodr>   r3   r4   r6   r8   r9   r:   rC   r   r   r   r   r
      s   	
0




  r
   )r   )
r   r   Znumpyr   Zpyrow.pyrowr   r1   r	   Úobjectr
   r   r   r   r   Ú<module>   s   
