// enum PORTID {
//   P0,
//   P1,
//   P2,
//   P3,
//   P4,
//   P5,
//   P6,
//   P7,
//   P8,
//   P9,
//   P10,
//   P11,
//   P12,
//   P13
// }

//% color="#fc4040" iconWidth=40 iconHeight=40
namespace Hx711 {
  //% block="tare and set Hx711 weight sensor initliallize scale [SCALE] pin Dout [DOUT] SCK [SCK]"  blockType="command"
  //% SCALE.shadow="number"   SCALE.defl="1992"
  //% DOUT.shadow="dropdown" DOUT.options="PINX"
  //% SCK.shadow="dropdown" SCK.options="PINX"
  export function beginHx711(parameter: any, block: any) {
    let scale = parameter.SCALE.code;
    let sser = "hx711";
    let dout = parameter.DOUT.code;
    let sck = parameter.SCK.code;
    Generator.addInclude("includeHx711", "#include <DFRobot_Hx711.h>");
    Generator.addObject("Hx711Object", "Hx711",`${sser}${dout}${sck};`);
    Generator.addCode(`${sser}${dout}${sck}.begin(${dout}, ${sck});`);
    Generator.addCode(`${sser}${dout}${sck}.setScale(${scale});`);
  }

  //% block="set Hx711 weight sensor initliallize scale [SCALE] pin Dout [DOUT] SCK [SCK]"  blockType="command"
  //% SCALE.shadow="number"   SCALE.defl="1992"
  //% DOUT.shadow="dropdown" DOUT.options="PINX"
  //% SCK.shadow="dropdown" SCK.options="PINX"
  export function setScale(parameter: any, block: any) {
    let scale = parameter.SCALE.code;
    let sser = "hx711";
    let dout = parameter.DOUT.code;
    let sck = parameter.SCK.code;
    Generator.addObject("Hx711Object", "Hx711",`${sser}${dout}${sck};`);
    Generator.addCode(`${sser}${dout}${sck}.setScale(${scale});`);
  }
  
  //% block="read Hx711 weitht sensor(g) pin Dout [DOUT] SCK [SCK]" blockType="reporter"
  //% DOUT.shadow="dropdown" DOUT.options="PINX"
  //% SCK.shadow="dropdown" SCK.options="PINX"
  export function getGram(parameter: any, block: any) {
    let sser = "hx711";
    let dout = parameter.DOUT.code;
    let sck = parameter.SCK.code;
    // Generator.addInclude("includeHx711", "#include <DFRobot_Hx711.h>");
    Generator.addObject("Hx711Object", "Hx711",`${sser}${dout}${sck};`);
    Generator.addCode(`${sser}${dout}${sck}.getGram()`);
  }

}
