Skip to content
Snippets Groups Projects
Select Git revision
  • 6948091f9a9aef66d21f48051547dc7eb209052a
  • master default protected
  • 1.1.1
  • 1.1
  • 1.0
5 results

wheel.c

Blame
  • wheel.c 821 B
    // #include "display.h"
    #include "utilities.h"
    #include "wheel.h"
    
    
    
    int set_speed(int s){
        return -1;
    }
    
    int get_current_px(){
        return -1;
    }
    
    
    void *wheel_func(void *param){
        printf("\nwheel_func");
        wheel* id = (wheel *) (param);
    
        while(1){
          wheel_spin_1_tick(id);
          wait_until(wheel_delay_ms(*id));
        }
    }
    
    int wheel_spin_1_tick(wheel* this){
      if (this->speed) {
        pthread_mutex_lock(&this->lock);
        this->current_px = (this->current_px + 2) % 896 ;
        pthread_mutex_unlock(&this->lock);
      }
    }
    
    int wheel_delay_ms(wheel this){
      if (this.speed) {
        return this.speed * 2;
      } 
    }
    
    int stop_wheel(wheel* this){
      while (this->current_px % 128 != 96) { // 32 is the offset to center the item
        //wheel_spin_1_tick(this);
        wait_until(wheel_delay_ms(*this));
      }
      this->speed = 0;
    }