test

Dependencies:   BLE_API nRF51822 mbed

Fork of KS7 by masaaki makabe

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers io.h Source File

io.h

00001 #ifndef io_H_
00002 #define io_H_
00003 
00004 #include "mbed.h"
00005 #include "common.h"
00006 
00007 //#define UART_DEBUG
00008 
00009 //#define PCB_VER1 // define for ver1 board (P0_26/27 -> P0_24/25) & ADC
00010 //#define PCB_VER2
00011 //#define PCB_VER3 // default
00012 //#define PCB_VER4 // with HX711
00013 
00014 //#define USE_JOYSTICK // define for using joystick as power switch in PCB_VER1
00015 
00016 // memo of load cell / gain
00017 // 0.9mV/kg(raw) -> 0.54V/kg(x600)
00018 // FS=+-1.65V -> 3.06kg(FS)
00019 
00020 // 0.9mV/kg(raw) -> 0.297V/kg(x330)
00021 // FS=+-1.65V -> 3.06kg(FS)
00022 
00023 //#define WEIGHT_COEFFICIENT              (8.64)
00024 //#define WEIGHT_COEFFICIENT              (3.15)
00025 // weight calibration on 2016/3/28 by akita11 in weight_calib150328.txt
00026 #define WEIGHT_COEFFICIENT              (682.32) // for PCB_VER4
00027 // 2000g = 6300
00028 
00029 //#define DISPLAY_ZERO_SUPPRESS // leading zero suppress on display
00030 
00031 class io {
00032 public:
00033 #ifdef PCB_VER4
00034     io(PinName CLK, PinName DAT);
00035 #else
00036     io();
00037 #endif
00038     ~io(); 
00039     int display_value; // 4-digit integer to display
00040     void display(float f); // set display brightness (0.0 - 1.0)
00041 
00042     virtual float get_weight(); // get (calibrated) weight [g]
00043 #ifdef PCB_VER4
00044     virtual uint32_t get_weight_raw(); // ADC raw value of weight gauage
00045 #else
00046     uint16_t get_weight_raw(); // ADC raw value of weight gauage
00047 #endif
00048     virtual uint8_t get_switch(); // get switch status (1=pressed, 0=released)
00049 
00050     virtual void calibrate_weight(); // calibrate weight gauage
00051     void analog_pow(uint8_t f); // turn on/off analog power
00052 
00053 #ifdef PCB_VER4
00054     uint32_t _get_adc_raw(uint8_t ch); // ADC raw value, 0x0000 - 0xffffff 
00055     uint32_t _adc0; // ADC value for calibrating zero point
00056 #else
00057     uint16_t _get_adc_raw(uint8_t ch); // ADC raw value, 0x0000 - 0xffff 
00058     uint16_t _adc0; // ADC value for calibrating zero point
00059 #endif
00060 
00061 #ifdef PCB_VER4
00062     void power_save_mode(uint8_t f); // f=1 for power-save mode during sleep
00063 #endif
00064 
00065  protected:
00066 #ifdef PCB_VER4
00067 #endif
00068     uint8_t _seg[4];
00069     float _get_adc(uint8_t ch); // ADC value, 0.0 - 1.0
00070 #ifdef PCB_VER1
00071     float _get_x(); // raw value of joystick X
00072     float _get_y(); // raw value of joystick Y
00073 #endif
00074     // belows are for internal use only
00075     int _display_value;
00076     uint8_t _col;
00077     uint8_t _row_out[8];
00078     void _set_col();
00079     void _set_row(uint8_t d);
00080     uint8_t _set_segment(uint8_t d);
00081     void _timer_ticker();
00082     DigitalOut *_sg0, *_sg1, *_sg2, *_sg3, *_sg4, *_sg5, *_sg6, *_sg7;
00083     DigitalOut *_sa0, *_sa1, *_sa2, *_pow;
00084 #ifdef PCB_VER1
00085     AnalogIn *_jx, *_jy, *_weight;
00086 #endif
00087 #ifdef PCB_VER2
00088     char _adc_dat[4];
00089 #endif
00090     PwmOut *_pwm;
00091 #ifdef PCB_VER3
00092     DigitalIn *_sw;
00093     DigitalOut *_adc_ck;
00094     DigitalIn *_adc_di;
00095     uint8_t _fDisplaying;
00096 #endif
00097 #ifdef PCB_VER4
00098 /*S------------------------------------------------------------------*/
00099 protected:
00100     DigitalIn *_sw;
00101     virtual void display_unit(void){}
00102 /*E------------------------------------------------------------------*/
00103 //    DigitalOut *_adc_ck; // for software SPI
00104 //    DigitalIn *_adc_di; // for software SPI
00105     DigitalOut *_reg_ps;
00106     DigitalOut *_adc_rate;
00107     uint32_t _PselSCK, _PselMISO; // for hardware SPI
00108     void _set_adc_ck(uint8_t f); // for hardware SPI
00109     void _enableSPI(uint8_t f); // for hardware SPI
00110     uint8_t _spi_transfer(void); // for hardware SPI
00111     uint8_t _fDisplaying;
00112     SPI _hx711; // for hardware SPI
00113 #endif
00114     
00115 };
00116 
00117 #endif