Skip to content

Commit

Permalink
Added functional callbacks for makecode package
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Feb 9, 2018
1 parent b095467 commit f996ee5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
30 changes: 30 additions & 0 deletions udriver_pca9685.cpp
Expand Up @@ -141,6 +141,7 @@ void PCA9685::digital_write_all(int value)
this->register_write(REG_ADDR_ALL_OFF_H, 0x10);
}

this->pulse_mode = 0;
}

void PCA9685::pwm_write(Pin pin, int value)
Expand Down Expand Up @@ -190,6 +191,8 @@ void PCA9685::pwm_write_all(int value)
this->register_write(REG_ADDR_ALL_OFF_H, off_hsb);

}

this->pulse_mode = 0;
}

void PCA9685::pwm_pulse(Pin pin, int pulse_us)
Expand Down Expand Up @@ -292,3 +295,30 @@ void PCA9685ServoController::move_servo(Pin pin, double angle_deg)
this->pwm_pulse(pin, pulse_us);
}

//Functional Callbacks for makecode package
namespace UDriver_PCA9685
{
static PCA9685ServoController *pca_device = new PCA9685ServoController;
//%
void digital_write(int pin, int value){ pca_device->digital_write((Pin)pin, value); }
//%
void digital_write_all(int pin, int value){ pca_device->digital_write_all(value); }
//%
void pwm_write(int pin, int value){ pca_device->pwm_write((Pin)pin, value); }
//%
void pwm_write_all(int pin, int value){ pca_device->pwm_write_all(value); }
//%
void pwm_pulse(int pin, int pulse_us) { pca_device->pwm_pulse((Pin)pin, pulse_us); }
//%
void set_pwm_frequency(int frequency){ pca_device->set_pwm_frequency(frequency); }
//%
void sleep(){ pca_device->sleep(); }
//%
void wake(){ pca_device->wake(); }
//%
void software_reset(){ pca_device->software_reset(); }
//%
void move_servo(int pin, int angle_deg){ pca_device->move_servo((Pin)pin, angle_deg);}
//%
void configure_servo(int pin, int min, int max){ pca_device->configure_servo((Pin)pin, min, max); }
}
3 changes: 1 addition & 2 deletions udriver_pca9685.h
Expand Up @@ -110,7 +110,7 @@ namespace UDriver_PCA9685
{
public:
PCA9685ServoController(I2CAddress addr=I2C_ADDRESS_ALL_CALL);

/* Move the servo's shaft to a certain angle in degrees */
void move_servo(Pin pin, double angle_deg);

Expand All @@ -126,6 +126,5 @@ namespace UDriver_PCA9685
uint16_t pulse_min[16];
uint16_t pulse_max[16];
};

}
#endif /* ifndef UDRIVER_PCA9685 */
34 changes: 33 additions & 1 deletion udriver_pca9685.ts
Expand Up @@ -11,7 +11,7 @@
namespace UDriver_PCA9685
{
/**
* Defines the analog pins on the PCA9685
* Defines the analog GVS pins on the PCA9685
*/
export enum Pin
{
Expand All @@ -33,4 +33,36 @@ namespace UDriver_PCA9685
P15
}

//%shim=UDriver_PCA9685::digital_write
export function digital_write(pin:Number, value:Number){}

//%shim=UDriver_PCA9685::digital_write_all
export function digital_write_all(pin:Number, value:Number){}

//%shim=UDriver_PCA9685:pwm_write
export function pwm_write(pin:Number, value:Number){}

//%shim=UDriver_PCA9685:pwm_write_all
export function pwm_write_all(pin:Number, value:Number){}

//%shim=Udriver_PCA9685::pwm_pulse
export function pwm_pulse(pin:Number, pulse_us:Number) {}

//%shim=Udriver_PCA9685::set_pwm_frequency
export function set_pwm_frequency(frequency:Number){}

//%shim=Udriver_PCA9685::sleep
export function sleep(){}

//%shim=Udriver_PCA9685::wake
export function wake(){}

//%shim=Udriver_PCA9685::software_reset
export function software_reset(){}

//%shim=Udriver_PCA9685::move_servo
export function move_servo(pin:Number, angle_deg:Number){}
//
//%shim=Udriver_PCA9685::configure_servo
export function configure_servo(pin:Number, min:Number, max:Number){}
}

0 comments on commit f996ee5

Please sign in to comment.